diff --git a/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php b/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php index 24a9bdb..98ddc7c 100644 --- a/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php +++ b/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php @@ -64,6 +64,18 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => 2, ]; + $form['duplicate_button'] = [ + '#type' => 'submit', + '#name' => 'duplicate_button', + '#value' => 'Duplicate button 1', + ]; + + $form['duplicate_button_2'] = [ + '#type' => 'submit', + '#name' => 'duplicate_button', + '#value' => 'Duplicate button 2', + ]; + $form['save'] = [ '#type' => 'submit', '#value' => $this->t('Save'), diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 3689ddd..3ac6ba2 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -334,9 +334,9 @@ public function testLegacyFieldAssertsWithTextfields() { } /** - * Tests legacy field asserts on other types of field. + * Tests legacy field asserts for options field type. */ - public function testLegacyFieldAssertsWithNonTextfields() { + public function testLegacyFieldAssertsWithOptions() { $this->drupalGet('test-field-xpath'); // Option field type. @@ -383,8 +383,14 @@ public function testLegacyFieldAssertsWithNonTextfields() { catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->pass($e->getMessage()); } + } + + /** + * Tests legacy field asserts for button field type. + */ + public function testLegacyFieldAssertsWithButton() { + $this->drupalGet('test-field-xpath'); - // Button field type. $this->assertFieldById('edit-save', NULL); // Test that the assertion fails correctly if the field value is passed in // rather than the id. @@ -407,7 +413,26 @@ public function testLegacyFieldAssertsWithNonTextfields() { $this->pass($e->getMessage()); } - // Checkbox field type. + // Test that multiple fields with the same name are validated correctly. + $this->assertFieldByName('duplicate_button', 'Duplicate button 1'); + $this->assertFieldByName('duplicate_button', 'Duplicate button 2'); + $this->assertNoFieldByName('duplicate_button', 'Rabbit'); + + try { + $this->assertNoFieldByName('duplicate_button', 'Duplicate button 2'); + $this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.'); + } + catch (ExpectationException $e) { + $this->pass('assertNoFieldByName correctly failed. The "duplicate_button" field with the value Duplicate button 2 was found.'); + } + } + + /** + * Tests legacy field asserts for checkbox field type. + */ + public function testLegacyFieldAssertsWithCheckbox() { + $this->drupalGet('test-field-xpath'); + // Test that checkboxes are found/not found correctly by name, when using // TRUE or FALSE to match their 'checked' state. $this->assertFieldByName('checkbox_enabled', TRUE); @@ -415,6 +440,19 @@ public function testLegacyFieldAssertsWithNonTextfields() { $this->assertNoFieldByName('checkbox_enabled', FALSE); $this->assertNoFieldByName('checkbox_disabled', TRUE); + // Test with an empty string value for a checkbox, the value should be + // ignored. + $this->assertFieldByName('checkbox_disabled', ''); + $this->assertFieldByName('checkbox_enabled', ''); + + } + + /** + * Tests legacy field asserts for checkbox field type. + */ + public function testLegacyFieldAssertsWithCheckboxTempPartTwo() { + $this->drupalGet('test-field-xpath'); + // Test that checkboxes are found by name when using NULL to ignore the // 'checked' state. $this->assertFieldByName('checkbox_enabled', NULL); @@ -426,6 +464,10 @@ public function testLegacyFieldAssertsWithNonTextfields() { $this->assertFieldById('edit-checkbox-disabled', FALSE); $this->assertNoFieldById('edit-checkbox-enabled', FALSE); $this->assertNoFieldById('edit-checkbox-disabled', TRUE); + + // Test that we have full legacy support by passing an empty string. + $this->assertFieldById('edit-checkbox-disabled', ''); + $this->assertFieldById('edit-checkbox-enabled', ''); // Test that checkboxes are found by by ID, when using NULL to ignore the // 'checked' state.