Chris@0: drupalCreateContentType(['type' => 'article']); Chris@0: $this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']); Chris@0: $this->drupalLogin($this->webUser); Chris@0: Chris@0: // Add the telephone field to the article content type. Chris@0: FieldStorageConfig::create([ Chris@0: 'field_name' => 'field_telephone', Chris@0: 'entity_type' => 'node', Chris@0: 'type' => 'telephone', Chris@0: ])->save(); Chris@0: FieldConfig::create([ Chris@0: 'field_name' => 'field_telephone', Chris@0: 'label' => 'Telephone Number', Chris@0: 'entity_type' => 'node', Chris@0: 'bundle' => 'article', Chris@0: ])->save(); Chris@0: Chris@0: entity_get_form_display('node', 'article', 'default') Chris@0: ->setComponent('field_telephone', [ Chris@0: 'type' => 'telephone_default', Chris@0: 'settings' => [ Chris@0: 'placeholder' => '123-456-7890', Chris@0: ], Chris@0: ]) Chris@0: ->save(); Chris@0: Chris@0: entity_get_display('node', 'article', 'default') Chris@0: ->setComponent('field_telephone', [ Chris@0: 'type' => 'telephone_link', Chris@0: 'weight' => 1, Chris@0: ]) Chris@0: ->save(); Chris@17: } Chris@0: Chris@17: /** Chris@17: * Test to confirm the widget is setup. Chris@17: * Chris@17: * @covers \Drupal\telephone\Plugin\Field\FieldWidget\TelephoneDefaultWidget::formElement Chris@17: */ Chris@17: public function testTelephoneWidget() { Chris@0: $this->drupalGet('node/add/article'); Chris@0: $this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.'); Chris@0: $this->assertRaw('placeholder="123-456-7890"'); Chris@17: } Chris@0: Chris@17: /** Chris@17: * Test the telephone formatter. Chris@17: * Chris@17: * @covers \Drupal\telephone\Plugin\Field\FieldFormatter\TelephoneLinkFormatter::viewElements Chris@17: * Chris@17: * @dataProvider providerPhoneNumbers Chris@17: */ Chris@17: public function testTelephoneFormatter($input, $expected) { Chris@0: // Test basic entry of telephone field. Chris@0: $edit = [ Chris@0: 'title[0][value]' => $this->randomMachineName(), Chris@17: 'field_telephone[0][value]' => $input, Chris@0: ]; Chris@0: Chris@0: $this->drupalPostForm('node/add/article', $edit, t('Save')); Chris@17: $this->assertRaw(''); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Provides the phone numbers to check and expected results. Chris@17: */ Chris@17: public function providerPhoneNumbers() { Chris@17: return [ Chris@17: 'standard phone number' => ['123456789', '123456789'], Chris@17: 'whitespace is removed' => ['1234 56789', '123456789'], Chris@17: 'parse_url(0) return FALSE workaround' => ['0', '0-'], Chris@17: 'php bug 70588 workaround - lower edge check' => ['1', '1-'], Chris@17: 'php bug 70588 workaround' => ['123', '1-23'], Chris@17: 'php bug 70588 workaround - with whitespace removal' => ['1 2 3 4 5', '1-2345'], Chris@17: 'php bug 70588 workaround - upper edge check' => ['65534', '6-5534'], Chris@17: 'php bug 70588 workaround - edge check' => ['65535', '6-5535'], Chris@17: 'php bug 70588 workaround - invalid port number - lower edge check' => ['65536', '6-5536'], Chris@17: 'php bug 70588 workaround - invalid port number - upper edge check' => ['99999', '9-9999'], Chris@17: 'lowest number not affected by php bug 70588' => ['100000', '100000'], Chris@17: ]; Chris@0: } Chris@0: Chris@0: }