Problem/Motivation

From #3139412-9: Replace usages of deprecated AssertLegacyTrait::assertTitle()

Cleanup the arguments of calls to WebAssert::titleEquals and AssertLegacyTrait::assertTitle: change in 1st argument so that a string is passed directly (instead of casting to string a call to t() or a FormattableMarkup object), and no more arguments are passed in 2nd (being a $message) and 3rd (being a $group).

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Title: Cleanup the arguments of calls to WebAssert::titleEquals and AssertLegacyTrait::assertTitle: » Cleanup the arguments of calls to WebAssert::titleEquals and AssertLegacyTrait::assertTitle
mohrerao’s picture

Assigned: Unassigned » mohrerao

On it

mohrerao’s picture

Status: Active » Needs review
StatusFileSize
new34.96 KB

Adding a patch

longwave’s picture

I think it might be safe to replace $this->config('system.site')->get('name') with the hardcoded string "Drupal"?

Status: Needs review » Needs work

The last submitted patch, 4: 3143339-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mohrerao’s picture

Assigned: mohrerao » Unassigned
Status: Needs work » Needs review
StatusFileSize
new34.68 KB
new5.91 KB

@longwave, That makes sense. But if someone wants to test this on local with a different site name, then it would fail. I see tests using both hardcoded text 'Drupal' as well as $this->config('system.site')->get('name'). I have now replaced it to Drupal.

mondrake’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php
    @@ -67,9 +67,9 @@ public function testCommentPreview() {
    -    $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
    -    $this->assertText($edit['subject[0][value]'], 'Subject displayed.');
    -    $this->assertText($edit['comment_body[0][value]'], 'Comment displayed.');
    +    $this->assertTitle('Preview comment | Drupal');
    +    $this->assertText($edit['subject[0][value]']);
    +    $this->assertText($edit['comment_body[0][value]']);
    
    @@ -101,9 +101,9 @@ public function testCommentPreviewDuplicateSubmission() {
    -    $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
    -    $this->assertText($edit['subject[0][value]'], 'Subject displayed.');
    -    $this->assertText($edit['comment_body[0][value]'], 'Comment displayed.');
    +    $this->assertTitle('Preview comment | Drupal');
    +    $this->assertText($edit['subject[0][value]']);
    +    $this->assertText($edit['comment_body[0][value]']);
    
    @@ -150,11 +150,11 @@ public function testCommentEditPreviewSave() {
    -    $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
    -    $this->assertText($edit['subject[0][value]'], 'Subject displayed.');
    -    $this->assertText($edit['comment_body[0][value]'], 'Comment displayed.');
    -    $this->assertText($web_user->getAccountName(), 'Author displayed.');
    -    $this->assertText($expected_text_date, 'Date displayed.');
    +    $this->assertTitle('Preview comment | Drupal');
    +    $this->assertText($edit['subject[0][value]']);
    +    $this->assertText($edit['comment_body[0][value]']);
    +    $this->assertText($web_user->getAccountName());
    +    $this->assertText($expected_text_date);
    

    The changes to assertText calls are out of scope here.

  2. +++ b/core/modules/search/tests/src/Functional/SearchPageTextTest.php
    @@ -77,7 +77,8 @@ public function testSearchText() {
         $title_source = 'Search for @keywords | Drupal';
    -    $this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)]), 'Search page title is correct');
    +    $title_source = 'Search for '.Unicode::truncate($search_terms, 60, TRUE, TRUE).' | Drupal';
    +    $this->assertTitle('Search for ' . Unicode::truncate($search_terms, 60, TRUE, TRUE) . ' | Drupal');
    

    This is ending up assigning $title_source twice, and not using it also.

if someone wants to test this on local with a different site name, then it would fail

No, it won't, because for every functional test a default Drupal installation is prepared and the test run on that, to avoid that the local site info leak in the test.

mohrerao’s picture

Status: Needs work » Needs review
StatusFileSize
new33.52 KB
new3.11 KB

Thanks for the comments @mondrake.

  1. Removed #8.1 out of scope changes.
  2. Fixed #8.2 double assigning of $title_source. Havent removed $title_source as this is being used in other asserts as well

Thanks for the info. Did not know that Drupal uses a fresh installation for test runs. That answers lot of time taken for running tests!!

mondrake’s picture

Thanks @mohrerao, this looks good, just there's a stray use statement left causing CS check failure.

Nit:

+++ b/core/modules/node/tests/src/Functional/NodeTitleTest.php
@@ -83,7 +83,7 @@ public function testNodeTitle() {
-    $this->assertTitle(0 . ' | Drupal', 'Page title is equal to 0.', 'Node');
+    $this->assertTitle(0 . ' | Drupal');

This could be just $this->assertTitle('0 | Drupal');, probably.

mondrake’s picture

Status: Needs review » Needs work
mohrerao’s picture

Status: Needs work » Needs review
StatusFileSize
new33.52 KB
new656 bytes

Thanks for that. Updated.

mondrake’s picture

Thanks. This is outstanding:


FILE: ...ules/block_content/tests/src/Functional/BlockContentTypeTest.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 5 | WARNING | [x] Unused use statement
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

mohrerao’s picture

StatusFileSize
new33.74 KB
new543 bytes

Aah missed it. Updating patch.

The last submitted patch, 12: 3143339-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! This patch is cleaning up Simpletest cruft from calls to AssertLegacyTrait::assertTitle and WebAssert::titleEquals - ensuring the first argument is always a string and no further arguments are passed in.

Prep for #3139412: Replace usages of deprecated AssertLegacyTrait::assertTitle().

xjm’s picture

Title: Cleanup the arguments of calls to WebAssert::titleEquals and AssertLegacyTrait::assertTitle » Clean up the arguments of calls to WebAssert::titleEquals() and AssertLegacyTrait::assertTitle()

  • xjm committed e4e64fa on 9.1.x
    Issue #3143339 by mohrerao, mondrake, longwave: Clean up the arguments...

  • xjm committed 7465e9b on 9.0.x
    Issue #3143339 by mohrerao, mondrake, longwave: Clean up the arguments...

  • xjm committed bd56fb1 on 8.9.x
    Issue #3143339 by mohrerao, mondrake, longwave: Clean up the arguments...
xjm’s picture

Version: 9.1.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

So much cleaner, and also actually better test coverage in a couple places. Thanks for the fast turnaround!

+++ b/core/modules/search/tests/src/Functional/SearchPageTextTest.php
@@ -91,7 +91,7 @@ public function testSearchText() {
     $search_terms = 'Every word is like an unnecessary stain on silence and nothingness.';
...
+    $this->assertTitle('Search for Every word is like an unnecessary stain on silence and… | Drupal');

The test author was feeling a bit existentialist, apparently.

(* In case someone needs to say something about how Samuel Beckett was not actually an existentialist, OK, fine.)

I've committed this to 9.1.x and cherry-picked it to 9.0.x and 8.9.x. It does not cherry-pick cleanly to 8.8.x, so if it's straightforward, we should create an 8.8.x version. (8.8.x will go into security-only mode starting with the code freeze on June 2, FYI, but we may be able to get this and the issue it's blocking backported by then.) Thanks!

bunty badgujar’s picture

Assigned: Unassigned » bunty badgujar
bunty badgujar’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new33.17 KB

backport to 8.8.x version.

mohrerao’s picture

Assigned: bunty badgujar » Unassigned
Status: Needs review » Reviewed & tested by the community

3143339-23.patch looks fine. Moving to RTBC again for commiting against 8.8.x

bunty badgujar’s picture

Title: Clean up the arguments of calls to WebAssert::titleEquals() and AssertLegacyTrait::assertTitle() » [backport] Clean up the arguments of calls to WebAssert::titleEquals() and AssertLegacyTrait::assertTitle()

  • xjm committed 0dad1ec on 8.8.x
    Issue #3143339 by mohrerao, Bunty Badgujar, mondrake, xjm, longwave: [...
xjm’s picture

Title: [backport] Clean up the arguments of calls to WebAssert::titleEquals() and AssertLegacyTrait::assertTitle() » Clean up the arguments of calls to WebAssert::titleEquals() and AssertLegacyTrait::assertTitle()
Status: Reviewed & tested by the community » Fixed

Committed the backport to 8.8.x. Thanks!

Status: Fixed » Closed (fixed)

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