The assertNoText() method of class Drupal\Tests\BrowserTestBase has been deprecated. According to \Drupal\FunctionalTests\AssertLegacyTrait.php it should be replaced with $this->assertSession()->responseNotContains()

85 matches across 8 files

Comments

shubham.prakash created an issue. See original summary.

shubham.prakash’s picture

Assigned: shubham.prakash » Unassigned
Status: Active » Needs review
StatusFileSize
new32.09 KB
jonathan1055’s picture

Title: Replace deprecated function assertNoText() » Replace deprecated function assertNoText() with pageTextNotContains()
Parent issue: » #3042677: Drupal 9 Deprecated Code Report for Scheduler

I was about to start this myself, so thank you for the patch.

In AssertLegacyTrait.php it says:

   * Deprecated Scheduled for removal in Drupal 10.0.0.
   *   Use instead:
   *     - $this->assertSession()->responseNotContains() for non-HTML responses,
   *       like XML or Json.
   *     - $this->assertSession()->pageTextNotContains() for HTML responses.
   *       Unlike the deprecated assertNoText(), the passed text should be HTML
   *       decoded, exactly as a human sees it in the browser.

Given that we have #3050086: Replace deprecated function assertText() with pageTextContains() I'd like to replace assertNoText() with pageTextNotContains() to keep it consistent. Also this is html so we should be using pageTextNotContains() for html responses.

Secondly, the additional parameter in all the assert calls should be removed in the replacement. Sometimes this gives good information about what we are testing, so in these cases the text could become a comment immediately preceding the assert. Other times the existing general comment is adequate so the second parameter can just be deleted.

shubham.prakash’s picture

StatusFileSize
new29.41 KB

Here is the patch as asked for.

shubham.prakash’s picture

StatusFileSize
new30.82 KB

Sorry for the last patch. This patch would fix the issue.

shubham.prakash’s picture

StatusFileSize
new29.1 KB

Last patch failed due to changes in latest commit. Here is the patch again.

shubham.prakash’s picture

StatusFileSize
new30.86 KB

Missed to replace at 2 places .

jonathan1055’s picture

Status: Needs review » Fixed

Thanks for the updated patch. I also changed $this->assertSession() to $assert where it was available, and added it for the tests that had lots of uses. I fixed the two coding standards errors too.

Committed and fixed.

Status: Fixed » Closed (fixed)

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