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 5f25dd7..6ce4115 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 @@ -57,6 +57,18 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t('Save'), ]; + $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', + ]; + return $form; } diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 9931804..5e66f86 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -201,13 +201,13 @@ public function testLegacyFieldAsserts() { $this->assertFieldById('edit-name'); $this->fail('The "edit-name" field with no value was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationException $e) { $this->pass('The "edit-name" field with no value was not found.'); } - // Test that the assertion fails correctly if NULL is passed in. + // Test that the assertion fails correctly if another value is passed in. try { - $this->assertFieldById('name', NULL); + $this->assertFieldById('edit-name', 'not the value'); $this->fail('The "name" field was found.'); } catch (ExpectationException $e) { @@ -237,6 +237,19 @@ public function testLegacyFieldAsserts() { $this->pass('The "name" field was found.'); } + // 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('The "duplicate_button" field with the value Duplicate button 2 was found.'); + } + $this->assertOptionByText('options', 'one'); try { $this->assertOptionByText('options', 'four');