3 namespace Drupal\Tests\telephone\Functional;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\field\Entity\FieldStorageConfig;
10 * Tests the creation of telephone fields.
14 class TelephoneFieldTest extends BrowserTestBase {
21 public static $modules = [
28 * A user with permission to create articles.
30 * @var \Drupal\user\UserInterface
34 protected function setUp() {
37 $this->drupalCreateContentType(['type' => 'article']);
38 $this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']);
39 $this->drupalLogin($this->webUser);
45 * Helper function for testTelephoneField().
47 public function testTelephoneField() {
49 // Add the telephone field to the article content type.
50 FieldStorageConfig::create([
51 'field_name' => 'field_telephone',
52 'entity_type' => 'node',
53 'type' => 'telephone',
56 'field_name' => 'field_telephone',
57 'label' => 'Telephone Number',
58 'entity_type' => 'node',
59 'bundle' => 'article',
62 entity_get_form_display('node', 'article', 'default')
63 ->setComponent('field_telephone', [
64 'type' => 'telephone_default',
66 'placeholder' => '123-456-7890',
71 entity_get_display('node', 'article', 'default')
72 ->setComponent('field_telephone', [
73 'type' => 'telephone_link',
78 // Display creation form.
79 $this->drupalGet('node/add/article');
80 $this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.');
81 $this->assertRaw('placeholder="123-456-7890"');
83 // Test basic entry of telephone field.
85 'title[0][value]' => $this->randomMachineName(),
86 'field_telephone[0][value]' => "123456789",
89 $this->drupalPostForm(NULL, $edit, t('Save'));
90 $this->assertRaw('<a href="tel:123456789">', 'A telephone link is provided on the article node page.');
92 // Add number with a space in it. Need to ensure it is stripped on output.
94 'title[0][value]' => $this->randomMachineName(),
95 'field_telephone[0][value]' => "1234 56789",
98 $this->drupalPostForm('node/add/article', $edit, t('Save'));
99 $this->assertRaw('<a href="tel:123456789">', 'Telephone link is output with whitespace removed.');