Problem/Motivation

AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3191935

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Title: [PP-1] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated » [PP-2] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated
Issue summary: View changes
mondrake’s picture

Title: [PP-2] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated » [PP-1] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated
Issue summary: View changes

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Title: [PP-1] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated » Replace usages of AssertLegacyTrait::assertNoText, that is deprecated
Assigned: Unassigned » mondrake
Issue summary: View changes
Status: Postponed » Active

Working on this.

mondrake’s picture

Status: Active » Needs work

First batch of conversions

mondrake’s picture

mondrake’s picture

Assigned: mondrake » Unassigned
mondrake’s picture

mondrake’s picture

Title: Replace usages of AssertLegacyTrait::assertNoText, that is deprecated » [PP-1] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated
Status: Needs work » Postponed
alexpott’s picture

This problem is being caused by case sensitivity and not [3175718]. \Drupal\FunctionalTests\AssertLegacyTrait::assertNoText() is case sensitive - it uses \PHPUnit\Framework\Assert::assertStringNotContainsString(). The replacement code eventually uses \Behat\Mink\WebAssert::elementTextNotContains which does $regex = '/'.preg_quote($text, '/').'/ui'; and then $this->assertElementText(!preg_match($regex, $actual), $message, $element);

It's true that [3175718] does help because it removes words you would not expect to be there and I also think that doing a case insensitive check is a good idea because asserting for missing text is fraught enough without having to worry about that.

mondrake’s picture

alexpott’s picture

+++ b/core/tests/Drupal/Tests/WebAssert.php
@@ -894,7 +894,7 @@ public function pageTextNotContains($text) {
-    return parent::pageTextNotContains($text);
+    return $this->elementTextNotContains('xpath', '//body', $text);

You need to revert this change.

mondrake’s picture

Ah, yes, thx

mondrake’s picture

Title: [PP-1] Replace usages of AssertLegacyTrait::assertNoText, that is deprecated » Replace usages of AssertLegacyTrait::assertNoText, that is deprecated
Status: Postponed » Needs review

Rerolled

mondrake’s picture

Status: Needs review » Needs work
mondrake’s picture

Assigned: Unassigned » mondrake

The remaining ones after #3175718: Random fails due to drupal-settings-json being counted as page text are hard, because we have false positives coming from case insensivity. We need to change to more accurate checks on page elements, taking care to convert also corresponding pageTextContains() calls when the tests are checking first non presence and then presence (or vice versa). On this.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review

Ready for review. Please note as per #18, some conversions required more elaborate refactoring due to false positives.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

This all looks OK to me. I read through the entire patch, the conversions are mostly 1:1 and the ones that are not appear to make sense in that they are now looking for more specific elements to avoid false positives.

xjm’s picture

Title: Replace usages of AssertLegacyTrait::assertNoText, that is deprecated » Replace usages of AssertLegacyTrait::assertNoText, which is deprecated
xjm’s picture

Status: Reviewed & tested by the community » Needs work

Reviewed locally with git diff --color-words. Overall, the changes make sense. For the few cases that were not exactly a 1:1 replacement, my main concern is that using negative assertions tied to specific xpaths of page markup is pretty fragile -- we could easily get false passes if the page markup or theming is changed. It would be better to find a different way to fix those assertions, and I'd suggest splitting those tests into their own blocking issue that this could be postponed on. In particular:

  1. FieldUIDeleteTest and UserAdminTest pair negative and positive xpath assertions related to page markup, either as a before/after or including some things but not other things with a given markup pattern, so those might be okay.
  2. However, UpdateContribTest only has a negative assertion based on specific page markup. This is a concern because the test could have a false pass if the markup or theme changes. Can we do this a different way?
  3. Similarly, ExposedFormTest only has a negative assertion, so I don't think an xpath assertion is the right choice here for the same reasons as above.

As for the other things that are not the 1:1 replacement:

  • CommentRestExportTest asserts that the response does not contain the text, which makes sense given that it's a REST test.
  • The updated inline docs in LocaleTranslationUiTest make sense.

Finally, there are a few tests that still have assertNoText() following this patch, so they probably need to be addressed as well:

core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php
core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php
core/modules/field/tests/src/Kernel/DisplayApiTest.php
core/modules/system/tests/src/Kernel/Render/ClassyTest.php
core/modules/views/tests/src/Kernel/Handler/AreaResultTest.php
core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php
core/modules/views/tests/src/Kernel/Handler/FieldFieldAccessTestBase.php

I think this is really close -- just would like a smaller first step to potentially solve the negative xpath assertions a different way, and address the remaining usages.

Thanks!

mondrake’s picture

#22

.. there are a few tests that still have assertNoText() following this patch ...

Note they're all Kernel tests that cannot be converted to WebAssert, this issue applies only to Functional and FunctionalJavascript ones.

xjm’s picture

Re: #23 -- Aha, thanks for clarifying. Are there separate plans to deal with the kernel tests?

mondrake’s picture

tedbow made their first commit to this issue’s fork.

tedbow’s picture

Status: Needs work » Needs review

I addressed #22 2,3

xjm’s picture

Status: Needs review » Needs work

NW for recent feedback.

mondrake’s picture

Assigned: Unassigned » mondrake

On this

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review

Addressed @phenaproxima's input.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

All feedback was addressed, changes look correct to me.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a re-roll.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll

Rerolled.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 068f00c and pushed to 9.3.x. Thanks!

  • catch committed 068f00c on 9.3.x
    Issue #3191935 by mondrake, tedbow, xjm, alexpott, longwave: Replace...
catch’s picture

Title: Replace usages of AssertLegacyTrait::assertNoText, which is deprecated » [backport] Replace usages of AssertLegacyTrait::assertNoText, which is deprecated
Version: 9.3.x-dev » 9.2.x-dev
Status: Fixed » Needs work

We should backport this to 9.2.x to keep other patches in sync.

paulocs’s picture

On it.

paulocs’s picture

Status: Needs work » Needs review

Please review.

longwave’s picture

Status: Needs review » Needs work

Needs another reroll.

ankithashetty made their first commit to this issue’s fork.

ankithashetty’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Reviewed & tested by the community

The MR looks perfect to me - thanks!

  • catch committed d7442be on 9.2.x
    Issue #3191935 by mondrake, tedbow, paulocs, ankithashetty, longwave,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x, thanks!

mondrake’s picture

Title: [backport] Replace usages of AssertLegacyTrait::assertNoText, which is deprecated » Replace usages of AssertLegacyTrait::assertNoText, which is deprecated

Status: Fixed » Closed (fixed)

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