Mercurial > hg > isophonics-drupal-site
comparison core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
19 * @var array | 19 * @var array |
20 */ | 20 */ |
21 public static $modules = [ | 21 public static $modules = [ |
22 'field', | 22 'field', |
23 'node', | 23 'node', |
24 'telephone' | 24 'telephone', |
25 ]; | 25 ]; |
26 | 26 |
27 /** | 27 /** |
28 * A user with permission to create articles. | 28 * A user with permission to create articles. |
29 * | 29 * |
30 * @var \Drupal\user\UserInterface | 30 * @var \Drupal\user\UserInterface |
31 */ | 31 */ |
32 protected $webUser; | 32 protected $webUser; |
33 | 33 |
34 /** | |
35 * {@inheritdoc} | |
36 */ | |
34 protected function setUp() { | 37 protected function setUp() { |
35 parent::setUp(); | 38 parent::setUp(); |
36 | 39 |
37 $this->drupalCreateContentType(['type' => 'article']); | 40 $this->drupalCreateContentType(['type' => 'article']); |
38 $this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']); | 41 $this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']); |
39 $this->drupalLogin($this->webUser); | 42 $this->drupalLogin($this->webUser); |
40 } | |
41 | |
42 // Test fields. | |
43 | |
44 /** | |
45 * Helper function for testTelephoneField(). | |
46 */ | |
47 public function testTelephoneField() { | |
48 | 43 |
49 // Add the telephone field to the article content type. | 44 // Add the telephone field to the article content type. |
50 FieldStorageConfig::create([ | 45 FieldStorageConfig::create([ |
51 'field_name' => 'field_telephone', | 46 'field_name' => 'field_telephone', |
52 'entity_type' => 'node', | 47 'entity_type' => 'node', |
72 ->setComponent('field_telephone', [ | 67 ->setComponent('field_telephone', [ |
73 'type' => 'telephone_link', | 68 'type' => 'telephone_link', |
74 'weight' => 1, | 69 'weight' => 1, |
75 ]) | 70 ]) |
76 ->save(); | 71 ->save(); |
72 } | |
77 | 73 |
78 // Display creation form. | 74 /** |
75 * Test to confirm the widget is setup. | |
76 * | |
77 * @covers \Drupal\telephone\Plugin\Field\FieldWidget\TelephoneDefaultWidget::formElement | |
78 */ | |
79 public function testTelephoneWidget() { | |
79 $this->drupalGet('node/add/article'); | 80 $this->drupalGet('node/add/article'); |
80 $this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.'); | 81 $this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.'); |
81 $this->assertRaw('placeholder="123-456-7890"'); | 82 $this->assertRaw('placeholder="123-456-7890"'); |
83 } | |
82 | 84 |
85 /** | |
86 * Test the telephone formatter. | |
87 * | |
88 * @covers \Drupal\telephone\Plugin\Field\FieldFormatter\TelephoneLinkFormatter::viewElements | |
89 * | |
90 * @dataProvider providerPhoneNumbers | |
91 */ | |
92 public function testTelephoneFormatter($input, $expected) { | |
83 // Test basic entry of telephone field. | 93 // Test basic entry of telephone field. |
84 $edit = [ | 94 $edit = [ |
85 'title[0][value]' => $this->randomMachineName(), | 95 'title[0][value]' => $this->randomMachineName(), |
86 'field_telephone[0][value]' => "123456789", | 96 'field_telephone[0][value]' => $input, |
87 ]; | |
88 | |
89 $this->drupalPostForm(NULL, $edit, t('Save')); | |
90 $this->assertRaw('<a href="tel:123456789">', 'A telephone link is provided on the article node page.'); | |
91 | |
92 // Add number with a space in it. Need to ensure it is stripped on output. | |
93 $edit = [ | |
94 'title[0][value]' => $this->randomMachineName(), | |
95 'field_telephone[0][value]' => "1234 56789", | |
96 ]; | 97 ]; |
97 | 98 |
98 $this->drupalPostForm('node/add/article', $edit, t('Save')); | 99 $this->drupalPostForm('node/add/article', $edit, t('Save')); |
99 $this->assertRaw('<a href="tel:123456789">', 'Telephone link is output with whitespace removed.'); | 100 $this->assertRaw('<a href="tel:' . $expected . '">'); |
101 } | |
102 | |
103 /** | |
104 * Provides the phone numbers to check and expected results. | |
105 */ | |
106 public function providerPhoneNumbers() { | |
107 return [ | |
108 'standard phone number' => ['123456789', '123456789'], | |
109 'whitespace is removed' => ['1234 56789', '123456789'], | |
110 'parse_url(0) return FALSE workaround' => ['0', '0-'], | |
111 'php bug 70588 workaround - lower edge check' => ['1', '1-'], | |
112 'php bug 70588 workaround' => ['123', '1-23'], | |
113 'php bug 70588 workaround - with whitespace removal' => ['1 2 3 4 5', '1-2345'], | |
114 'php bug 70588 workaround - upper edge check' => ['65534', '6-5534'], | |
115 'php bug 70588 workaround - edge check' => ['65535', '6-5535'], | |
116 'php bug 70588 workaround - invalid port number - lower edge check' => ['65536', '6-5536'], | |
117 'php bug 70588 workaround - invalid port number - upper edge check' => ['99999', '9-9999'], | |
118 'lowest number not affected by php bug 70588' => ['100000', '100000'], | |
119 ]; | |
100 } | 120 } |
101 | 121 |
102 } | 122 } |