Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.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 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\FunctionalJavascriptTests\Core; | 3 namespace Drupal\FunctionalJavascriptTests\Core; |
4 | 4 |
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase; | 5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase; |
6 | 6 |
7 /** | 7 /** |
8 * Tests for the machine name field. | 8 * Tests for the machine name field. |
9 * | 9 * |
10 * @group field | 10 * @group field |
11 */ | 11 */ |
12 class MachineNameTest extends JavascriptTestBase { | 12 class MachineNameTest extends WebDriverTestBase { |
13 | 13 |
14 /** | 14 /** |
15 * Required modules. | 15 * Required modules. |
16 * | 16 * |
17 * Node is required because the machine name callback checks for | 17 * Node is required because the machine name callback checks for |
57 ], | 57 ], |
58 ]; | 58 ]; |
59 | 59 |
60 // Get page and session. | 60 // Get page and session. |
61 $page = $this->getSession()->getPage(); | 61 $page = $this->getSession()->getPage(); |
62 $assert_session = $this->assertSession(); | |
63 | 62 |
64 // Get elements from the page. | 63 // Get elements from the page. |
65 $title_1 = $page->findField('machine_name_1_label'); | 64 $title_1 = $page->findField('machine_name_1_label'); |
66 $machine_name_1_field = $page->findField('machine_name_1'); | 65 $machine_name_1_field = $page->findField('machine_name_1'); |
67 $machine_name_2_field = $page->findField('machine_name_2'); | 66 $machine_name_2_field = $page->findField('machine_name_2'); |
109 // Validate the visibility of the second machine name field. | 108 // Validate the visibility of the second machine name field. |
110 $this->assertEquals(TRUE, $machine_name_2_wrapper->hasClass('visually-hidden'), 'The ID field must not be visible'); | 109 $this->assertEquals(TRUE, $machine_name_2_wrapper->hasClass('visually-hidden'), 'The ID field must not be visible'); |
111 | 110 |
112 // Validate if the element contains the correct value. | 111 // Validate if the element contains the correct value. |
113 $this->assertEquals($test_values[1]['expected'], $machine_name_1_field->getValue(), 'The ID field value must be equal to the php generated machine name'); | 112 $this->assertEquals($test_values[1]['expected'], $machine_name_1_field->getValue(), 'The ID field value must be equal to the php generated machine name'); |
113 | |
114 $assert = $this->assertSession(); | |
115 $this->drupalGet('/form-test/form-test-machine-name-validation'); | |
116 | |
117 // Test errors after with no AJAX. | |
118 $assert->buttonExists('Save')->press(); | |
119 $assert->pageTextContains('Machine-readable name field is required.'); | |
120 // Ensure only the first machine name field has an error. | |
121 $this->assertTrue($assert->fieldExists('id')->hasClass('error')); | |
122 $this->assertFalse($assert->fieldExists('id2')->hasClass('error')); | |
123 | |
124 // Test a successful submit after using AJAX. | |
125 $assert->fieldExists('Name')->setValue('test 1'); | |
126 $assert->fieldExists('id')->setValue('test_1'); | |
127 $assert->selectExists('snack')->selectOption('apple'); | |
128 $assert->assertWaitOnAjaxRequest(); | |
129 $assert->buttonExists('Save')->press(); | |
130 $assert->pageTextContains('The form_test_machine_name_validation_form form has been submitted successfully.'); | |
131 | |
132 // Test errors after using AJAX. | |
133 $assert->fieldExists('Name')->setValue('duplicate'); | |
134 $this->assertJsCondition('document.forms[0].id.value === "duplicate"'); | |
135 $assert->fieldExists('id2')->setValue('duplicate2'); | |
136 $assert->selectExists('snack')->selectOption('potato'); | |
137 $assert->assertWaitOnAjaxRequest(); | |
138 $assert->buttonExists('Save')->press(); | |
139 $assert->pageTextContains('The machine-readable name is already in use. It must be unique.'); | |
140 // Ensure both machine name fields both have errors. | |
141 $this->assertTrue($assert->fieldExists('id')->hasClass('error')); | |
142 $this->assertTrue($assert->fieldExists('id2')->hasClass('error')); | |
114 } | 143 } |
115 | 144 |
116 } | 145 } |