diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 608c06c..ad94a4e 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -197,7 +197,7 @@ public function testLegacyXpathAsserts() { /** * Tests legacy field asserts using textfields. */ - public function testLegacyFieldAssertsWithTextfields() { + public function testLegacyFieldAssertsForTextfields() { $this->drupalGet('test-field-xpath'); // *** 1. assertNoField(). @@ -331,24 +331,12 @@ public function testLegacyFieldAssertsWithTextfields() { catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not 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.'); - } } /** - * Tests legacy field asserts on other types of field. + * Tests legacy field asserts for options field type. */ - public function testLegacyFieldAssertsWithNonTextfields() { + public function testLegacyFieldAssertsForOptions() { $this->drupalGet('test-field-xpath'); // Option field type. @@ -395,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 testLegacyFieldAssertsForButton() { + $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. @@ -419,7 +413,27 @@ 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 testLegacyFieldAssertsForCheckbox() { + $this->drupalGet('test-field-xpath'); + + // Part 1 - Test by name. // 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); @@ -427,39 +441,48 @@ 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_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); $this->assertFieldByName('checkbox_disabled', NULL); + // Test that checkboxes are found by name when passing no second parameter. + $this->assertFieldByName('checkbox_enabled'); + $this->assertFieldByName('checkbox_disabled'); + + // Test that we have legacy support. + $this->assertFieldByName('checkbox_enabled', '1'); + $this->assertFieldByName('checkbox_disabled', ''); + + // Test that the assertion fails correctly when using NULL to ignore state. + try { + $this->assertNoFieldByName('checkbox_enabled', NULL); + $this->fail('The "checkbox_enabled" field was not found by name, using NULL value.'); + } + catch (ExpectationException $e) { + $this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.'); + } + + // Part 2 - Test by ID. // Test that checkboxes are found/not found correctly by ID, when using // TRUE or FALSE to match their 'checked' state. $this->assertFieldById('edit-checkbox-enabled', TRUE); $this->assertFieldById('edit-checkbox-disabled', FALSE); - // Test that we have full legacy support by passing an empty string. - $this->assertFieldById('edit-checkbox-enabled', ''); - $this->assertFieldById('edit-checkbox-disabled', ''); $this->assertNoFieldById('edit-checkbox-enabled', FALSE); $this->assertNoFieldById('edit-checkbox-disabled', TRUE); - // Test that checkboxes are found by by ID, when using NULL to ignore the + // Test that checkboxes are found by ID, when using NULL to ignore the // 'checked' state. $this->assertFieldById('edit-checkbox-enabled', NULL); $this->assertFieldById('edit-checkbox-disabled', NULL); - // Test that the assertion fails correctly when using NULL to ignore state. - try { - $this->assertNoFieldByName('checkbox_enabled', NULL); - $this->fail('The "checkbox_enabled" field was not found by name, using NULL value.'); - } - catch (ExpectationException $e) { - $this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.'); - } + // Test that checkboxes are found by ID when passing no second parameter. + $this->assertFieldById('edit-checkbox-enabled'); + $this->assertFieldById('edit-checkbox-disabled'); + + // Test that we have legacy support. + $this->assertFieldById('edit-checkbox-enabled', '1'); + $this->assertFieldById('edit-checkbox-disabled', ''); // Test that the assertion fails correctly when using NULL to ignore state. try { @@ -470,7 +493,7 @@ public function testLegacyFieldAssertsWithNonTextfields() { $this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.'); } - // Test the specific 'checked' assertions. + // Part 3 - Test the specific 'checked' assertions. $this->assertFieldChecked('edit-checkbox-enabled'); $this->assertNoFieldChecked('edit-checkbox-disabled');