Problem/Motivation

In #2763013: Convert web tests to browser tests for link module we discovered that assertNoFieldByName() with en empty string as value does not work the same way as on WebTestBase. We need to improve that for easier conversion of tests.

Proposed resolution

Explicitly test assertNoFieldByName() with empty string values and imrpove our implementation on AssertLegacyTrait.

Remaining tasks

Patch.

Comments

klausi created an issue. See original summary.

jofitz’s picture

Status: Active » Needs review
StatusFileSize
new774 bytes

Set the default value of the optional parameter $value to be '' (rather than NULL) as it was on WebTestBase.

While investigating this issue I also found that most of the documentation for assertNoFieldByName() is incorrect - it appears to have been copied from assertFieldByName() and not completely updated - should this also be addressed in this issue or shall I create a separate issue?

klausi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Let's also make the docs for assertNoFieldByName() accurate in this issue.

+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -241,7 +241,7 @@ protected function assertFieldByName($name, $value = NULL) {
-  protected function assertNoFieldByName($name, $value = NULL) {
+  protected function assertNoFieldByName($name, $value = '') {
     $this->assertSession()->fieldNotExists($name);
     if ($value !== NULL) {
       $this->assertSession()->fieldValueNotEquals($name, (string) $value);

shouldn't you also change the if() condition to check for the new default value?

Can you expand the test in BrowserTestBaseTest::testLegacyXPathAsserts() to cover this?

boaloysius’s picture

StatusFileSize
new1.37 KB
new1.17 KB

Update NULL inside the if condition and modified the documentation.

boaloysius’s picture

Status: Needs work » Needs review
klausi’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
    @@ -228,22 +228,22 @@ protected function assertFieldByName($name, $value = NULL) {
    -   * Asserts that a field exists with the given name and value.
    +   * Asserts that a field don't exist with the given name and value.
    

    should be "doesn't"

  2. +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
    @@ -228,22 +228,22 @@ protected function assertFieldByName($name, $value = NULL) {
    -   *   (optional) Value of the field to assert. You may pass in NULL (default)
    +   *   (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
    -   *   exists.
    +   *   don't exist.
    

    Should be "(optional) Value of the field, to assert that the field's value on the page does not match it."

    from the original method in Simpletest.

And we still need to expand the test cases as I said above.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.82 KB
new3.53 KB
new3.1 KB
  • Corrected assertNoFieldByName().
  • Corrected the documentation for assertNoFieldByName() (copied from simpletest AsserContentTrait version).
  • Expanded the test in BrowserTestBaseTest::testLegacyXPathAsserts() to cover assertNoFieldByName().

I suspect there are also flaws in assertNoFieldById() - should that be covered within this ticket too?

The last submitted patch, 4: 2857725-4.patch, failed testing.

The last submitted patch, 7: 2857725-7-test_only.patch, failed testing.

klausi’s picture

Status: Needs review » Needs work

Very good, just a tiny thing:

+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -2,6 +2,7 @@
@@ -163,6 +164,19 @@ public function testLegacyXPathAsserts() {

@@ -163,6 +164,19 @@ public function testLegacyXPathAsserts() {
 
     $this->assertNoFieldByXPath('//notexisting');
     $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');
+
+    $this->assertNoFieldByName('name');

ah, sorry, this test method is about legacy xpath asserts ...

We can just rename the test method to testLegacyFieldAsserts() since all methods tested have "field" in their name :)

I think we can cover flaws in assertNoFieldById() in another issue.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new3.97 KB
new742 bytes

Renamed the method (and tweaked the documentation).

Now to remember what those flaws I was talking about are...

jofitz’s picture

StatusFileSize
new4.33 KB
new1.02 KB

Add another assertion failure test and a couple of comments.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a reroll.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new2.98 KB

Re-rolled.

goz’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 4b8275d to 8.4.x and c91342a to 8.3.x. Thanks!

+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -228,24 +228,27 @@ protected function assertFieldByName($name, $value = NULL) {
+  protected function assertNoFieldByName($name, $value = '') {

This brings us back into line with \Drupal\simpletest\AssertContentTrait::assertNoFieldByName() which is great for conversions.

  • alexpott committed 4b8275d on 8.4.x
    Issue #2857725 by Jo Fitzgerald, boaloysius, klausi: Improve...

  • alexpott committed c91342a on 8.3.x
    Issue #2857725 by Jo Fitzgerald, boaloysius, klausi: Improve...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

boaloysius’s picture