Skip to content
Snippets Groups Projects
Commit 4b8275db authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2857725 by Jo Fitzgerald, boaloysius, klausi: Improve...

Issue #2857725 by Jo Fitzgerald, boaloysius, klausi: Improve assertNoFieldByName() compatibility for empty strings
parent bd69cfc9
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -228,24 +228,27 @@ protected function assertFieldByName($name, $value = NULL) {
}
/**
* Asserts that a field exists 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) Value of the field to assert. You may pass in NULL (default)
* to skip checking the actual value, while still checking that the field
* exists.
* (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 = NULL) {
$this->assertSession()->fieldNotExists($name);
if ($value !== NULL) {
protected function assertNoFieldByName($name, $value = '') {
if ($this->getSession()->getPage()->findField($name) && isset($value)) {
$this->assertSession()->fieldValueNotEquals($name, (string) $value);
}
else {
$this->assertSession()->fieldNotExists($name);
}
}
/**
......
......@@ -187,6 +187,29 @@ public function testLegacyFieldAsserts() {
catch (ExpectationException $e) {
$this->pass('The "name" field was found.');
}
$this->assertNoFieldByName('name');
$this->assertNoFieldByName('name', 'not the value');
$this->assertNoFieldByName('notexisting');
$this->assertNoFieldByName('notexisting', NULL);
// Test that the assertion fails correctly if no value is passed in.
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.');
}
// Test that the assertion fails correctly if a NULL value is passed in.
try {
$this->assertNoFieldByName('name', NULL);
$this->fail('The "name" field was not found.');
}
catch (ExpectationException $e) {
$this->pass('The "name" field was found.');
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment