reverted: --- b/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php +++ a/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php @@ -35,18 +35,6 @@ '#default_value' => 'Test name', ]; - $form['checkbox_enabled'] = [ - '#type' => 'checkbox', - '#title' => 'Checkbox enabled', - '#default_value' => TRUE, - ]; - - $form['checkbox_disabled'] = [ - '#type' => 'checkbox', - '#title' => 'Checkbox disabled', - '#default_value' => FALSE, - ]; - $form['description'] = [ '#type' => 'textfield', '#title' => 'Description', @@ -69,18 +57,6 @@ '#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 -u b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php --- b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -611,7 +611,15 @@ $found = FALSE; if ($fields) { foreach ($fields as $field) { - if ($field->getAttribute('value') == $value) { + if ($field->getAttribute('type') == 'checkbox') { + if (is_bool($value)) { + $found = $field->isChecked() == $value; + } + else { + $found = TRUE; + } + } + elseif ($field->getAttribute('value') == $value) { // Input element with correct value. $found = TRUE; } diff -u b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php --- b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -165,63 +165,6 @@ $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2'); $this->assertFieldByXPath("//select[@id = 'edit-options']", '2'); - $this->assertNoField('invalid_name_and_id'); - $this->assertField('name'); - $this->assertField('edit-name'); - - // Test that the assertion fails correctly when searching by name. - try { - $this->assertNoField('name'); - $this->fail('The "name" field was not found based on name.'); - } - catch (ExpectationException $e) { - $this->pass('The "name" field was found by name.'); - } - - // Test that the assertion fails correctly when searching by id. - try { - $this->assertNoField('edit-name'); - $this->fail('The "name" field was not found based on id.'); - } - catch (ExpectationException $e) { - $this->pass('The "name" field was found by id.'); - } - - // Assert that assertion correctly fails when searching for the name field - // without a value. - try { - $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), ''); - $this->fail('The "name" field, with no value was found.'); - } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { - $this->pass('The "name" field, with no value was found.'); - } - - $this->assertFieldByName('checkbox_enabled', TRUE); - $this->assertFieldByName('checkbox_disabled'); - - $this->assertNoFieldByName('checkbox_enabled', FALSE); - - try { - $this->assertFieldByName('checkbox_enabled', FALSE); - $this->fail('The checked "checkbox_enabled" field was not found.'); - - } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { - $this->pass('The checked "checkbox_enabled" field was found.'); - } - - try { - $this->assertNoFieldByName('checkbox_enabled', TRUE); - $this->fail('The checked "checkbox_enabled" field was not found.'); - } - catch (ExpectationException $e) { - $this->pass('The checked "checkbox_enabled" field was found.'); - } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { - $this->pass('The checked "checkbox_enabled" field was found.'); - } - $this->assertNoFieldByXPath('//notexisting'); $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); @@ -238,7 +181,7 @@ $this->assertNoFieldByXPath("//input[@id = 'edit-name']"); $this->fail('The "edit-name" field was not found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationException $e) { $this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.'); } @@ -262,12 +205,12 @@ $this->pass('The "edit-name" field with no value was not found.'); } - // Test that the assertion fails correctly if another value is passed in. + // Test that the assertion fails correctly if NULL is passed in. try { - $this->assertFieldById('edit-name', 'not the value'); + $this->assertFieldById('name', NULL); $this->fail('The "name" field was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationException $e) { $this->pass('The "name" field was not found.'); } @@ -287,26 +230,13 @@ $this->assertField('invalid_name_and_id'); $this->fail('The "invalid_name_and_id" field was found.'); } - catch (ExpectationException $e) { + catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.'); } $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'); @@ -323,7 +253,7 @@ $this->assertFieldById('Save', NULL); $this->fail('The field with id of "Save" was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationException $e) { $this->pass($e->getMessage()); } @@ -389,7 +319,7 @@ $this->assertFieldByName('non-existing-name'); $this->fail('The "non-existing-name" field was found.'); } - catch (ExpectationException $e) { + catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->pass('The "non-existing-name" field was not found'); } @@ -398,7 +328,7 @@ $this->assertFieldByName('name', 'not the value'); $this->fail('The "name" field with incorrect value was found.'); } - catch (ExpectationException $e) { + catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.'); } } @@ -462,7 +392,7 @@ $this->assertFieldById('Save', NULL); $this->fail('The field with id of "Save" was found.'); } - catch (ExpectationException $e) { + catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->pass($e->getMessage()); } @@ -485,6 +415,11 @@ $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_enabled', ''); + $this->assertFieldByName('checkbox_disabled', ''); + // Test that checkboxes are found by name when using NULL to ignore the // 'checked' state. $this->assertFieldByName('checkbox_enabled', NULL);