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 @@ -534,7 +534,7 @@ * (optional) A message to display with the assertion. Do not translate * messages with t(). * - * @throws ExpectationException + * @throws \Behat\Mink\Exception\ExpectationException * * @deprecated Scheduled for removal in Drupal 9.0.0. * Use $this->xpath() instead and check the values directly in the test. 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,6 +165,51 @@ $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2'); $this->assertFieldByXPath("//select[@id = 'edit-options']", '2'); + // 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->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->assertNoFieldByXPath('//notexisting'); $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); @@ -237,19 +282,6 @@ $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');