Problem/Motivation

The current calls to AssertLegacyTrait::assertPattern() in functional tests still have a message passed in, even if the method does not take that in. We need to remove the messages from the calls and inline them as comments where appropriate.

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

Issue tags: +Deprecated assertions
sja112’s picture

Assigned: Unassigned » sja112
sja112’s picture

Assigned: sja112 » Unassigned
Status: Active » Needs review
StatusFileSize
new19.69 KB
ketikagrover’s picture

Assigned: Unassigned » ketikagrover
daffie’s picture

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

Patch no longer applies.

munish.kumar’s picture

Status: Needs work » Needs review
StatusFileSize
new19.63 KB

Patch rerolled for 9.1.

sivaji_ganesh_jojodae’s picture

Issue tags: -Needs reroll
daffie’s picture

Status: Needs review » Needs work

The latest patch returns with 4 coding standards messages. See: https://www.drupal.org/pift-ci-job/1710147.

pavnish’s picture

Assigned: ketikagrover » pavnish
shaktik’s picture

Status: Needs work » Needs review
StatusFileSize
new19.78 KB
new0 bytes
shaktik’s picture

StatusFileSize
new2.12 KB

Hi @daffie,

solved returns with 4 coding standards messages, kindly check.

daffie’s picture

Status: Needs review » Needs work

A quick review of the interdiff file:

+++ b/core/modules/user/tests/src/Functional/UserBlocksTest.php
@@ -89,7 +92,7 @@ public function testUserLoginBlock() {
-    $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!');
+    $this->assertPattern('!<title.*Compose tips.*?</title>!');

This change is missing a comma character.

pavnish’s picture

Assigned: pavnish » Unassigned
Status: Needs work » Needs review
StatusFileSize
new19.67 KB
new704 bytes

@daffie #13 has been changed.
Please review this patch.

daffie’s picture

Status: Needs review » Needs work

The latest patch returns a coding standard violation. See: https://www.drupal.org/pift-ci-job/1711330

munish.kumar’s picture

Status: Needs work » Needs review
StatusFileSize
new50.1 KB
new30.39 KB

Hi @pavnish, You latest patch contains a coding standard issue, Fixed this issue and uploaded interdiff for the same.

munish.kumar’s picture

StatusFileSize
new19.95 KB
new442 bytes

Ignore the previous patch, Here is the updated patch which addresses #15 issues.

The last submitted patch, 16: 3142749-16.patch, failed testing. View results

Rkumar’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks clean and didn't find any other occurrence of assertPattern() with a message.
So moving it to RTBC.

mondrake’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
Lal_’s picture

Status: Needs work » Needs review
StatusFileSize
new19.95 KB
daffie’s picture

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

Reroll is done correctly.
Back to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

I read over all the removed messages in the patch, and I think that the inline comments are being added in all the cases where existing comments don't already provide sufficient information. Nice work!

  1. I did a broad search for places that might have the second parameter with a non-regexy grep:

    [ayrton:maintainer | Wed 14:54:49] $ grep -r "assertPattern" * | grep "," | grep -v "vendor" | grep -v "node_modules"
    core/tests/Drupal/KernelTests/AssertContentTrait.php:  protected function assertPattern($pattern, $message = '', $group = 'Other') {
    core/modules/system/tests/src/Functional/Menu/LocalActionTest.php:      $this->assertPattern('@<a [^>]*class="[^"]*button-action[^"]*"[^>]*>' . preg_quote($title, '@') . '</@');
    core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php:    return $this->assertPattern('@<a [^>]*>' . preg_quote($title, '@') . '</a>@');
    core/modules/system/tests/src/Kernel/Common/AddFeedTest.php:      $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']));
    core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php:    $this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)>\s*<picture/');
    core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php:      $this->assertPattern('/media="\(min-width: 560px\)".+?sizes="\(min-width: 700px\) 700px, 100vw"/');
    core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php:    $this->assertPattern('/srcset="' . preg_quote(file_url_transform_relative($thumbnail_style->buildUrl($image_uri)), '/') . ' 1x".+?media="\(min-width: 0px\)"/');
    core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php:        $this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)>\s*<picture/');
    core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php:        $this->assertPattern('/<a(.*?)href="' . preg_quote($node->toUrl()->toString(), '/') . '"(.*?)>\s*<picture/');

    Those are all false positives, except the method on AssertContentTrait itself. So, this isn't like the other issue where the message wasn't supported at all, is it?

    Is the message not being printed? Should we be deprecating passing a message to the method?

  2. +++ b/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php
    @@ -140,9 +140,9 @@ public function testTermTranslatedOnOverviewPage() {
    -    // Overview page in the other language shows the translated term
    +    // Overview page in the other language shows the translated term.
    

    Technically out of scope, but OK. :)

  3. +++ b/core/modules/user/tests/src/Functional/UserBlocksTest.php
    @@ -32,6 +32,9 @@ class UserBlocksTest extends BrowserTestBase {
    +  /**
    +   * {@inheritdoc}
    +   */
    

    Hmm, also out of scope, and less close to the issue scope.

I'm mostly interested in more information for point 1, but let's fix 2 and 3 while we're at it. Thanks!

shaktik’s picture

Status: Needs work » Needs review
StatusFileSize
new19.66 KB
new1.2 KB

reverted point 2 and 3.

mondrake’s picture

@xjm re #23.1 I think your regex starting point is wrong - like this you capture the calls that have a function in the concatenation of the pattern string, and that function has multiple arguments.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

mondrake’s picture

I read again #23.1, my comment in #25 is not relevant to the question.

AssertContentTrait is not touched by this chain of issues, it's not in any deprecation stage. True, the assert methods there all have $message and $group, with the former in use and the latter totally irrelevant. Also they could be PHPUnitised a bit more. But that IMHO should be a totally separate endeavour. It's not even a followup.

catch’s picture

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

Opened #3162193: Modernize AssertContentTrait.

Patch needs a re-roll.

ravi.shankar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new19.61 KB

Added a reroll of patch #24.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1017 bytes

Thanks.

alexpott’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 402567d128 to 9.1.x and 0c53f5b191 to 9.0.x and 2c1c4e601e to 8.9.x. Thanks!

Backported to 8.9.x to keep tests in-sync.

+++ b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php
@@ -2,7 +2,6 @@
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Url;
 use Drupal\KernelTests\KernelTestBase;
 
@@ -69,7 +68,7 @@ public function testBasicFeedAddNoTitle() {

@@ -69,7 +68,7 @@ public function testBasicFeedAddNoTitle() {
     $this->setRawContent($response->getContent());
     // Assert that the content contains the RSS links we specified.
     foreach ($urls as $description => $feed_info) {
-      $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), new FormattableMarkup('Found correct feed header for %description', ['%description' => $description]));
+      $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']));
     }
   }
 

This change is tricky. This is a kernel test. It's using \Drupal\KernelTests\AssertContentTrait::assertPattern() which still supports $message. That said the default message added by AssertContentTrait::assertPattern() is okay so let's proceed.

  • alexpott committed 402567d on 9.1.x
    Issue #3142749 by munish.kumar, shaktik, pavnish, sja112, ravi.shankar,...

  • alexpott committed 0c53f5b on 9.0.x
    Issue #3142749 by munish.kumar, shaktik, pavnish, sja112, ravi.shankar,...

  • alexpott committed 2c1c4e6 on 8.9.x
    Issue #3142749 by munish.kumar, shaktik, pavnish, sja112, ravi.shankar,...

Status: Fixed » Closed (fixed)

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