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 @@ -228,24 +228,27 @@ } /** - * Asserts that a field don't exist with the given name and value. + * Asserts that a field does not exist with the given name and value. * * @param string $name * Name of field to assert. * @param string $value - * (optional) Assert field not equal to the Value. You may pass in NULL (default) - * to skip checking the actual value, while still checking that the field - * don't exist. + * (optional) Value for the field, to assert that the field's value on the + * page does not match it. You may pass in NULL to skip checking the + * value, while still checking that the field does not exist. However, the + * default value ('') asserts that the field value is not an empty string. * * @deprecated Scheduled for removal in Drupal 9.0.0. * Use $this->assertSession()->fieldNotExists() or * $this->assertSession()->fieldValueNotEquals() instead. */ protected function assertNoFieldByName($name, $value = '') { - $this->assertSession()->fieldNotExists($name); - if ($value !== '') { + if ($this->getSession()->getPage()->findField($name) && isset($value)) { $this->assertSession()->fieldValueNotEquals($name, (string) $value); } + else { + $this->assertSession()->fieldNotExists($name); + } } /** only in patch2: unchanged: --- 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 @@ -35,6 +35,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => 'Test name', ]; + $form['description'] = [ + '#type' => 'textfield', + '#title' => 'Description', + '#default_value' => '', + ]; + $form['options'] = [ '#type' => 'select', '#title' => 'Options', only in patch2: unchanged: --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -2,6 +2,7 @@ namespace Drupal\FunctionalTests; +use Behat\Mink\Exception\ExpectationException; use Drupal\Component\Utility\Html; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; @@ -163,6 +164,19 @@ public function testLegacyXPathAsserts() { $this->assertNoFieldByXPath('//notexisting'); $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); + + $this->assertNoFieldByName('name'); + $this->assertNoFieldByName('name', 'not the value'); + $this->assertNoFieldByName('notexisting'); + $this->assertNoFieldByName('notexisting', NULL); + + try { + $this->assertNoFieldByName('description'); + $this->fail('The "description" field, with no value was not found.'); + } + catch (ExpectationException $e) { + $this->pass('The "description" field, with no value was found.'); + } } /**