From 402567d1281c991c9f019877c461daaa6e30c64a Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 31 Jul 2020 18:02:28 +0100
Subject: [PATCH] Issue #3142749 by munish.kumar, shaktik, pavnish, sja112,
 ravi.shankar, Lal_, mondrake, daffie, xjm: AssertLegacyTrait::assertPattern()
 calls in functional tests still have a message passed in

---
 .../book/tests/src/Functional/BookTestTrait.php      |  2 +-
 .../modules/color/tests/src/Functional/ColorTest.php |  3 ++-
 .../tests/src/Functional/CommentAnonymousTest.php    |  3 ++-
 .../tests/src/Functional/CommentInterfaceTest.php    |  2 +-
 .../tests/src/Functional/CommentNonNodeTest.php      |  3 ++-
 .../tests/src/Functional/CommentTitleTest.php        |  5 +++--
 core/modules/field/tests/src/Functional/FormTest.php |  3 ++-
 .../menu_ui/tests/src/Functional/MenuUiNodeTest.php  | 12 ++++++++----
 .../tests/src/Functional/Views/FrontPageTest.php     |  2 +-
 .../tests/src/Functional/StatisticsLoggingTest.php   |  4 ++--
 .../tests/src/Functional/Batch/ProcessingTest.php    |  2 +-
 .../system/tests/src/Functional/Form/StorageTest.php |  3 ++-
 .../system/tests/src/Kernel/Common/AddFeedTest.php   |  3 +--
 .../tests/src/Functional/TaxonomyTermPagerTest.php   |  8 ++++----
 .../tests/src/Functional/TermLanguageTest.php        |  2 +-
 .../tracker/tests/src/Functional/TrackerTest.php     |  4 +++-
 .../update/tests/src/Functional/UpdateUploadTest.php |  4 ++--
 .../user/tests/src/Functional/UserBlocksTest.php     |  9 ++++++---
 18 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/core/modules/book/tests/src/Functional/BookTestTrait.php b/core/modules/book/tests/src/Functional/BookTestTrait.php
index 38a93f44b24f..f2d78b511200 100644
--- a/core/modules/book/tests/src/Functional/BookTestTrait.php
+++ b/core/modules/book/tests/src/Functional/BookTestTrait.php
@@ -95,7 +95,7 @@ public function checkBookNode(EntityInterface $node, $nodes, $previous, $up, $ne
 
     // Check outline structure.
     if ($nodes !== NULL) {
-      $this->assertPattern($this->generateOutlinePattern($nodes), new FormattableMarkup('Node @number outline confirmed.', ['@number' => $number]));
+      $this->assertPattern($this->generateOutlinePattern($nodes));
     }
 
     // Check previous, up, and next links.
diff --git a/core/modules/color/tests/src/Functional/ColorTest.php b/core/modules/color/tests/src/Functional/ColorTest.php
index 015d7202944f..66199d533de3 100644
--- a/core/modules/color/tests/src/Functional/ColorTest.php
+++ b/core/modules/color/tests/src/Functional/ColorTest.php
@@ -120,8 +120,9 @@ public function _testColor($theme, $test_values) {
 
     $this->drupalGet('<front>');
     $stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets');
+    // Make sure the color stylesheet is included in the content.
     foreach ($stylesheets as $stylesheet) {
-      $this->assertPattern('|' . file_url_transform_relative(file_create_url($stylesheet)) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
+      $this->assertPattern('|' . file_url_transform_relative(file_create_url($stylesheet)) . '|');
       $stylesheet_content = implode("\n", file($stylesheet));
       $this->assertStringContainsString('color: #123456', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
     }
diff --git a/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php b/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php
index a502a0b5f669..6366ce6d1519 100644
--- a/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php
@@ -188,7 +188,8 @@ public function testAnonymous() {
       'skip comment approval' => FALSE,
     ]);
     $this->drupalGet('node/' . $this->node->id());
-    $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
+    // Verify that the comment field title is displayed.
+    $this->assertPattern('@<h2[^>]*>Comments</h2>@');
     $this->assertSession()->linkExists('Log in', 1, 'Link to login was found.');
     $this->assertSession()->linkExists('register', 1, 'Link to register was found.');
 
diff --git a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
index e557c7ce194a..5018d5664ebc 100644
--- a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
@@ -55,7 +55,7 @@ public function testCommentInterface() {
 
     // Test the comment field title is displayed when there's comments.
     $this->drupalGet($this->node->toUrl());
-    $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is displayed.');
+    $this->assertPattern('@<h2[^>]*>Comments</h2>@');
 
     // Set comments to have subject and preview to required.
     $this->drupalLogout();
diff --git a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
index 8023bd204fbe..5a19a817b22f 100644
--- a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
@@ -370,7 +370,8 @@ public function testCommentFunctionality() {
       'skip comment approval' => FALSE,
     ]);
     $this->drupalGet('entity_test/' . $this->entity->id());
-    $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
+    // Verify that the comment field title is displayed.
+    $this->assertPattern('@<h2[^>]*>Comments</h2>@');
     $this->assertSession()->linkExists('Log in', 0, 'Link to login was found.');
     $this->assertSession()->linkExists('register', 0, 'Link to register was found.');
     $this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
diff --git a/core/modules/comment/tests/src/Functional/CommentTitleTest.php b/core/modules/comment/tests/src/Functional/CommentTitleTest.php
index 0565d88a275c..7897acbaa2c6 100644
--- a/core/modules/comment/tests/src/Functional/CommentTitleTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentTitleTest.php
@@ -45,7 +45,8 @@ public function testCommentEmptyTitles() {
     $regex = '/<article(.*?)id="comment-' . $comment->id() . '"(.*?)';
     $regex .= $comment->comment_body->value . '(.*?)';
     $regex .= '/s';
-    $this->assertPattern($regex, 'Comment is created successfully');
+    // Verify that the comment is created successfully.
+    $this->assertPattern($regex);
     // Tests that markup is not generated for the comment without header.
     $this->assertSession()->responseNotMatches('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');
   }
@@ -76,7 +77,7 @@ public function testCommentPopulatedTitles() {
     // Confirm that the comment was created.
     $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
     // Tests that markup is created for comment with heading.
-    $this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|', 'Comment title is rendered in h3 when title populated.');
+    $this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|');
     // Tests that the comment's title link is the permalink of the comment.
     $comment_permalink = $this->cssSelect('.permalink');
     $comment_permalink = $comment_permalink[0]->getAttribute('href');
diff --git a/core/modules/field/tests/src/Functional/FormTest.php b/core/modules/field/tests/src/Functional/FormTest.php
index 6bf6a3464da7..381ec8df9e4e 100644
--- a/core/modules/field/tests/src/Functional/FormTest.php
+++ b/core/modules/field/tests/src/Functional/FormTest.php
@@ -315,7 +315,8 @@ public function testFieldFormUnlimited() {
     }
     ksort($pattern);
     $pattern = implode('.*', array_values($pattern));
-    $this->assertPattern("|$pattern|s", 'Widgets are displayed in the correct order');
+    // Verify that the widgets are displayed in the correct order.
+    $this->assertPattern("|$pattern|s");
     $this->assertFieldByName("{$field_name}[$delta][value]", '', "New widget is displayed");
     $this->assertFieldByName("{$field_name}[$delta][_weight]", $delta, "New widget has the right weight");
     // Verify that no extraneous widget is displayed.
diff --git a/core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php
index 36175f8c8533..175360180a31 100644
--- a/core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php
+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php
@@ -78,12 +78,12 @@ public function testMenuNodeFormWidget() {
     // Verify that the menu link title has the correct maxlength.
     $title_max_length = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content')['title']->getSetting('max_length');
     $this->drupalGet('node/add/page');
-    $this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node add form.');
+    $this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/');
 
     // Verify that the menu link description has the correct maxlength.
     $description_max_length = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content')['description']->getSetting('max_length');
     $this->drupalGet('node/add/page');
-    $this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/', 'Menu link description field has correct maxlength in node add form.');
+    $this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/');
 
     // Disable the default main menu, so that no menus are enabled.
     $edit = [
@@ -193,8 +193,12 @@ public function testMenuNodeFormWidget() {
 
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertFieldById('edit-menu-weight', 17, 'Menu weight correct in edit form');
-    $this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node edit form.');
-    $this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/', 'Menu link description field has correct maxlength in node add form.');
+    // Verify that the menu link title field has correct maxlength in node edit
+    // form.
+    $this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/');
+    // Verify that the menu link description field has correct maxlength in
+    // node add form.
+    $this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/');
 
     // Disable the menu link, then edit the node--the link should stay disabled.
     $link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
diff --git a/core/modules/node/tests/src/Functional/Views/FrontPageTest.php b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php
index 35e04d0905bd..8d5b0f048758 100644
--- a/core/modules/node/tests/src/Functional/Views/FrontPageTest.php
+++ b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php
@@ -187,7 +187,7 @@ public function testAdminFrontPage() {
     $this->drupalGet('node');
     $this->assertSession()->statusCodeEquals(200);
     // Check that the frontpage view was rendered.
-    $this->assertPattern('/class=".+view-frontpage/', 'Frontpage view was rendered');
+    $this->assertPattern('/class=".+view-frontpage/');
   }
 
   /**
diff --git a/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php b/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php
index c089649c62e6..23b810d080e7 100644
--- a/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php
+++ b/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php
@@ -117,13 +117,13 @@ public function testLogging() {
     // Verify that logging scripts are found on a valid node page.
     $this->drupalGet($path);
     $settings = $this->getDrupalSettings();
-    $this->assertPattern($expected_library, 'Found statistics library JS on node page.');
+    $this->assertPattern($expected_library);
     $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on node page.');
 
     // Verify the same when loading the site in a non-default language.
     $this->drupalGet($this->language['langcode'] . '/' . $path);
     $settings = $this->getDrupalSettings();
-    $this->assertPattern($expected_library, 'Found statistics library JS on a valid node page in a non-default language.');
+    $this->assertPattern($expected_library);
     $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on valid node page in a non-default language.');
 
     // Manually call statistics.php to simulate ajax data collection behavior.
diff --git a/core/modules/system/tests/src/Functional/Batch/ProcessingTest.php b/core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
index 69e23ed0c6ee..4e98379aedc7 100644
--- a/core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
+++ b/core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
@@ -221,7 +221,7 @@ public function testBatchLargePercentage() {
    */
   public function assertBatchMessages($texts, $message) {
     $pattern = '|' . implode('.*', $texts) . '|s';
-    return $this->assertPattern($pattern, $message);
+    return $this->assertPattern($pattern);
   }
 
   /**
diff --git a/core/modules/system/tests/src/Functional/Form/StorageTest.php b/core/modules/system/tests/src/Functional/Form/StorageTest.php
index 09780a0688b3..602d52ed04cd 100644
--- a/core/modules/system/tests/src/Functional/Form/StorageTest.php
+++ b/core/modules/system/tests/src/Functional/Form/StorageTest.php
@@ -101,7 +101,8 @@ public function testFormCached() {
    */
   public function testValidation() {
     $this->drupalPostForm('form_test/form-storage', ['title' => '', 'value' => 'value_is_set'], 'Continue submit');
-    $this->assertPattern('/value_is_set/', 'The input values have been kept.');
+    // Ensure that the input values have been kept.
+    $this->assertPattern('/value_is_set/');
   }
 
   /**
diff --git a/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php
index 9926b1899219..efa055746f74 100644
--- a/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php
+++ b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\system\Kernel\Common;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Url;
 use Drupal\KernelTests\KernelTestBase;
 
@@ -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']));
     }
   }
 
diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php
index 1641e0c8a98a..27db54e98537 100644
--- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php
@@ -63,13 +63,13 @@ public function testTaxonomyTermOverviewPager() {
       $this->createTerm($this->vocabulary);
     }
 
-    // Get Page 1.
+    // Ensure that pager is visible on page 1.
     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
-    $this->assertPattern('|<nav class="pager" [^>]*>|', 'Pager is visible on page 1');
+    $this->assertPattern('|<nav class="pager" [^>]*>|');
 
-    // Get Page 2.
+    // Ensure that pager is visible on page 2.
     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
-    $this->assertPattern('|<nav class="pager" [^>]*>|', 'Pager is visible on page 2');
+    $this->assertPattern('|<nav class="pager" [^>]*>|');
   }
 
 }
diff --git a/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php b/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php
index 78482be633ea..6e6daac92d49 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php
@@ -142,7 +142,7 @@ public function testTermTranslatedOnOverviewPage() {
 
     // Overview page in the other language shows the translated term
     $this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
-    $this->assertPattern('|<a[^>]*>' . $translated_title . '</a>|', 'The term language is correct');
+    $this->assertPattern('|<a[^>]*>' . $translated_title . '</a>|');
   }
 
 }
diff --git a/core/modules/tracker/tests/src/Functional/TrackerTest.php b/core/modules/tracker/tests/src/Functional/TrackerTest.php
index abef37179969..e111400ecb10 100644
--- a/core/modules/tracker/tests/src/Functional/TrackerTest.php
+++ b/core/modules/tracker/tests/src/Functional/TrackerTest.php
@@ -353,7 +353,9 @@ public function testTrackerOrderingNewComments() {
     // It's almost certainly too brittle.
     $pattern = '/' . preg_quote($node_one->getTitle()) . '.+' . preg_quote($node_two->getTitle()) . '/s';
     $this->verbose($pattern);
-    $this->assertPattern($pattern, 'Most recently commented on node appears at the top of tracker');
+    // Verify that the most recent comment on node appears at the top of
+    // tracker.
+    $this->assertPattern($pattern);
   }
 
   /**
diff --git a/core/modules/update/tests/src/Functional/UpdateUploadTest.php b/core/modules/update/tests/src/Functional/UpdateUploadTest.php
index 34995cfd4ff3..74762ad2598a 100644
--- a/core/modules/update/tests/src/Functional/UpdateUploadTest.php
+++ b/core/modules/update/tests/src/Functional/UpdateUploadTest.php
@@ -147,9 +147,9 @@ public function testUploadModule() {
   public function testFileNameExtensionMerging() {
     $this->drupalGet('admin/modules/install');
     // Make sure the bogus extension supported by update_test.module is there.
-    $this->assertPattern('/file extensions are supported:.*update-test-extension/', "Found 'update-test-extension' extension.");
+    $this->assertPattern('/file extensions are supported:.*update-test-extension/');
     // Make sure it didn't clobber the first option from core.
-    $this->assertPattern('/file extensions are supported:.*tar/', "Found 'tar' extension.");
+    $this->assertPattern('/file extensions are supported:.*tar/');
   }
 
   /**
diff --git a/core/modules/user/tests/src/Functional/UserBlocksTest.php b/core/modules/user/tests/src/Functional/UserBlocksTest.php
index 36b70cd7af5e..fc0079235c48 100644
--- a/core/modules/user/tests/src/Functional/UserBlocksTest.php
+++ b/core/modules/user/tests/src/Functional/UserBlocksTest.php
@@ -88,7 +88,8 @@ public function testUserLoginBlock() {
     $this->assertEqual('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER));
     $this->drupalPostForm(NULL, $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
-    $this->assertPattern('!<title.*?Compose tips.*?</title>!', 'Still on the same page after login for allowed page');
+    // Verify that we are still on the same page after login for allowed page.
+    $this->assertPattern('!<title.*?Compose tips.*?</title>!');
 
     // Log out again and repeat with a non-403 page including query arguments.
     $this->drupalLogout();
@@ -96,7 +97,8 @@ public function testUserLoginBlock() {
     $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER));
     $this->drupalPostForm(NULL, $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
-    $this->assertPattern('!<title.*?Compose tips.*?</title>!', 'Still on the same page after login for allowed page');
+    // Verify that we are still on the same page after login for allowed page.
+    $this->assertPattern('!<title.*?Compose tips.*?</title>!');
     $this->assertStringContainsString('/filter/tips?foo=bar', $this->getUrl(), 'Correct query arguments are displayed after login');
 
     // Repeat with different query arguments.
@@ -105,7 +107,8 @@ public function testUserLoginBlock() {
     $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER));
     $this->drupalPostForm(NULL, $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
-    $this->assertPattern('!<title.*?Compose tips.*?</title>!', 'Still on the same page after login for allowed page');
+    // Verify that we are still on the same page after login for allowed page.
+    $this->assertPattern('!<title.*?Compose tips.*?</title>!');
     $this->assertStringContainsString('/filter/tips?foo=baz', $this->getUrl(), 'Correct query arguments are displayed after login');
 
     // Check that the user login block is not vulnerable to information
-- 
GitLab