From 050b91b764f50878c80bd3d8a61caf5f80526e6c Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Fri, 28 Aug 2020 12:06:48 +1000 Subject: [PATCH] Issue #3160405 by mondrake, ravi.shankar, jungle, longwave: Deprecate overloading arguments to WebAssert methods to prevent conversions of legacy Simpletest test to carry over cruft --- .../BigPipeRegressionTest.php | 8 +- .../src/Functional/CommentAnonymousTest.php | 6 +- .../src/Functional/CommentInterfaceTest.php | 2 +- .../src/Functional/CommentNonNodeTest.php | 6 +- .../tests/src/Functional/CommentTitleTest.php | 2 +- .../src/Functional/FileFieldDisplayTest.php | 2 +- .../src/Functional/ImageFieldDisplayTest.php | 2 +- .../Functional/NodeAccessBaseTableTest.php | 7 +- .../tests/src/Functional/PathAliasTest.php | 2 +- .../src/Functional/StatisticsLoggingTest.php | 6 +- .../Form/ElementsTableSelectTest.php | 23 +- .../tests/src/Functional/Form/StorageTest.php | 8 +- .../src/Functional/Routing/RouterTest.php | 10 +- .../FunctionalJavascript/Form/RebuildTest.php | 2 +- .../FunctionalJavascript/FrameworkTest.php | 2 +- .../src/Functional/TaxonomyTermPagerTest.php | 3 +- .../tests/src/Functional/UpdateTestBase.php | 3 +- .../Core/Assert/WebAssertArgumentsTest.php | 574 ++++++++++++++++++ core/tests/Drupal/Tests/WebAssert.php | 402 ++++++++++++ 19 files changed, 1028 insertions(+), 42 deletions(-) create mode 100644 core/tests/Drupal/Tests/Core/Assert/WebAssertArgumentsTest.php diff --git a/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php b/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php index 8534051a8eb..a4641d71f15 100644 --- a/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php +++ b/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php @@ -141,11 +141,15 @@ JS; // Besides verifying there is no JavaScript syntax error, also verify the // HTML structure. + // The BigPipe stop signal is present just before the closing and + // tags. $this->assertSession() - ->responseContains(BigPipe::STOP_SIGNAL . "\n\n\n", 'The BigPipe stop signal is present just before the closing and tags.'); + ->responseContains(BigPipe::STOP_SIGNAL . "\n\n\n"); $js_code_until_closing_body_tag = substr(BigPipeRegressionTestController::MARKER_2678662, 0, strpos(BigPipeRegressionTestController::MARKER_2678662, '')); + // The BigPipe start signal does NOT start at the closing tag string + // in an inline script. $this->assertSession() - ->responseNotContains($js_code_until_closing_body_tag . "\n" . BigPipe::START_SIGNAL, 'The BigPipe start signal does NOT start at the closing tag string in an inline script.'); + ->responseNotContains($js_code_until_closing_body_tag . "\n" . BigPipe::START_SIGNAL); } /** diff --git a/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php b/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php index 15132da9c07..8b1a7e46d3e 100644 --- a/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php +++ b/core/modules/comment/tests/src/Functional/CommentAnonymousTest.php @@ -175,7 +175,8 @@ class CommentAnonymousTest extends CommentTestBase { // NOTE: if authenticated user has permission to post comments, then a // "Login or register to post comments" type link may be shown. $this->drupalGet('node/' . $this->node->id()); - $this->assertSession()->responseNotMatches('@]*>Comments@', 'Comments were not displayed.'); + // Verify that comments were not displayed. + $this->assertSession()->responseNotMatches('@]*>Comments@'); $this->assertSession()->linkNotExists('Add new comment', 'Link to add comment was found.'); // Attempt to view node-comment form while disallowed. @@ -199,7 +200,8 @@ class CommentAnonymousTest extends CommentTestBase { 'skip comment approval' => TRUE, ]); $this->drupalGet('node/' . $this->node->id()); - $this->assertSession()->responseNotMatches('@]*>Comments@', 'Comments were not displayed.'); + // Verify that comments were not displayed. + $this->assertSession()->responseNotMatches('@]*>Comments@'); $this->assertFieldByName('subject[0][value]', '', 'Subject field found.'); $this->assertFieldByName('comment_body[0][value]', '', 'Comment field found.'); diff --git a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php index 4998f43d468..a9001e8d405 100644 --- a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php +++ b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php @@ -32,7 +32,7 @@ class CommentInterfaceTest extends CommentTestBase { // Make sure that comment field title is not displayed when there's no // comments posted. $this->drupalGet($this->node->toUrl()); - $this->assertSession()->responseNotMatches('@]*>Comments@', 'Comments title is not displayed.'); + $this->assertSession()->responseNotMatches('@]*>Comments@'); // Set comments to have subject and preview disabled. $this->setCommentPreview(DRUPAL_DISABLED); diff --git a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php index 84c3a6a889b..f0fbe3bd8a8 100644 --- a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php +++ b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php @@ -354,7 +354,8 @@ class CommentNonNodeTest extends BrowserTestBase { // Attempt to view comments while disallowed. $this->drupalGet('entity-test/' . $this->entity->id()); - $this->assertSession()->responseNotMatches('@]*>Comments@', 'Comments were not displayed.'); + // Verify that comments were not displayed. + $this->assertSession()->responseNotMatches('@]*>Comments@'); $this->assertSession()->linkNotExists('Add new comment', 'Link to add comment was found.'); // Attempt to view test entity comment form while disallowed. @@ -387,7 +388,8 @@ class CommentNonNodeTest extends BrowserTestBase { 'view test entity' => TRUE, ]); $this->drupalGet('entity_test/' . $this->entity->id()); - $this->assertSession()->responseNotMatches('@]*>Comments@', 'Comments were not displayed.'); + // Verify that comments were not displayed. + $this->assertSession()->responseNotMatches('@]*>Comments@'); $this->assertFieldByName('subject[0][value]', '', 'Subject field found.'); $this->assertFieldByName('comment_body[0][value]', '', 'Comment field found.'); diff --git a/core/modules/comment/tests/src/Functional/CommentTitleTest.php b/core/modules/comment/tests/src/Functional/CommentTitleTest.php index 3ac9d27c7b1..d276e515070 100644 --- a/core/modules/comment/tests/src/Functional/CommentTitleTest.php +++ b/core/modules/comment/tests/src/Functional/CommentTitleTest.php @@ -48,7 +48,7 @@ class CommentTitleTest extends CommentTestBase { // Verify that the comment is created successfully. $this->assertSession()->responseMatches($regex); // Tests that markup is not generated for the comment without header. - $this->assertSession()->responseNotMatches('|]*>|', 'Comment title H3 element not found when title is an empty string.'); + $this->assertSession()->responseNotMatches('|]*>|'); } /** diff --git a/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php index 72d150e70f6..7b3a92e8c54 100644 --- a/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php @@ -112,7 +112,7 @@ class FileFieldDisplayTest extends FileFieldTestBase { $this->clickLink(t('Back to content editing')); $this->assertRaw($field_name . '[0][display]', 'First file appears as expected.'); $this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.'); - $this->assertSession()->responseContains($field_name . '[1][description]', 'Description of second file appears as expected.'); + $this->assertSession()->responseContains($field_name . '[1][description]'); // Check that the file fields don't contain duplicate HTML IDs. $this->assertSession()->pageContainsNoDuplicateId(); diff --git a/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php b/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php index 3e313ce5b67..b1bcfdf0fc9 100644 --- a/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php +++ b/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php @@ -367,7 +367,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase { $this->drupalGet('node/' . $node->id()); // Verify that no image is displayed on the page by checking for the class // that would be used on the image field. - $this->assertSession()->responseNotMatches('
', 'No image displayed when no image is attached and no default image specified.'); + $this->assertSession()->responseNotMatches('
'); $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags'); $this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.'); diff --git a/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php b/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php index 54010538521..ca9c1c814b8 100644 --- a/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessBaseTableTest.php @@ -157,12 +157,7 @@ class NodeAccessBaseTableTest extends NodeTestBase { else { $should_be_visible = TRUE; } - $this->assertSession()->statusCodeEquals($should_be_visible ? 200 : 403, strtr('A %private node by user %uid is %visible for user %current_uid.', [ - '%private' => $is_private ? 'private' : 'public', - '%uid' => $uid, - '%visible' => $should_be_visible ? 'visible' : 'not visible', - '%current_uid' => $this->webUser->id(), - ])); + $this->assertSession()->statusCodeEquals($should_be_visible ? 200 : 403); } } diff --git a/core/modules/path/tests/src/Functional/PathAliasTest.php b/core/modules/path/tests/src/Functional/PathAliasTest.php index 3d998ad3a93..5f233f1d0a2 100644 --- a/core/modules/path/tests/src/Functional/PathAliasTest.php +++ b/core/modules/path/tests/src/Functional/PathAliasTest.php @@ -414,7 +414,7 @@ class PathAliasTest extends PathTestBase { // This error should still be present next to the field. $this->assertSession()->pageTextContains("The alias {$edit['path[0][alias]']} is already in use in this language."); // The validation error set for the page should include this text. - $this->assertSession()->pageTextContains(t('1 error has been found: URL alias'), 'Form error found with expected text.'); + $this->assertSession()->pageTextContains('1 error has been found: URL alias'); // The text 'URL alias' should be a link. $this->assertSession()->linkExists('URL alias'); // The link should be to the ID of the URL alias field. diff --git a/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php b/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php index f6083c89156..f0f660e9e2a 100644 --- a/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php +++ b/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php @@ -105,13 +105,15 @@ class StatisticsLoggingTest extends BrowserTestBase { // Verify that logging scripts are not found on a non-node page. $this->drupalGet('node'); $settings = $this->getDrupalSettings(); - $this->assertSession()->responseNotMatches($expected_library, 'Statistics library JS not found on node page.'); + // Statistics library JS should not be present. + $this->assertSession()->responseNotMatches($expected_library); $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.'); // Verify that logging scripts are not found on a non-existent node page. $this->drupalGet('node/9999'); $settings = $this->getDrupalSettings(); - $this->assertSession()->responseNotMatches($expected_library, 'Statistics library JS not found on non-existent node page.'); + // Statistics library JS should not be present. + $this->assertSession()->responseNotMatches($expected_library); $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.'); // Verify that logging scripts are found on a valid node page. diff --git a/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php b/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php index 91f7b2863cc..ce0f3d84ea0 100644 --- a/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php +++ b/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php @@ -31,7 +31,7 @@ class ElementsTableSelectTest extends BrowserTestBase { $this->drupalGet('form_test/tableselect/multiple-true'); - $this->assertSession()->responseNotContains('Empty text.', 'Empty text should not be displayed.'); + $this->assertSession()->responseNotContains('Empty text.'); // Test for the presence of the Select all rows tableheader. $this->assertNotEmpty($this->xpath('//th[@class="select-all"]'), 'Presence of the "Select all" checkbox.'); @@ -65,8 +65,9 @@ class ElementsTableSelectTest extends BrowserTestBase { public function testTableSelectColSpan() { $this->drupalGet('form_test/tableselect/colspan'); - $this->assertSession()->pageTextContains('Three', 'Presence of the third column'); - $this->assertSession()->pageTextNotContains('Four', 'Absence of a fourth column'); + // Verify presence of column three and absence of column four. + $this->assertSession()->pageTextContains('Three'); + $this->assertSession()->pageTextNotContains('Four'); // There should be three labeled column headers and 1 for the input. $table_head = $this->xpath('//thead/tr/th'); @@ -88,7 +89,7 @@ class ElementsTableSelectTest extends BrowserTestBase { */ public function testEmptyText() { $this->drupalGet('form_test/tableselect/empty-text'); - $this->assertSession()->pageTextContains('Empty text.', 'Empty text should be displayed.'); + $this->assertSession()->pageTextContains('Empty text.'); } /** @@ -102,18 +103,18 @@ class ElementsTableSelectTest extends BrowserTestBase { $this->drupalPostForm('form_test/tableselect/multiple-true', $edit, 'Submit'); $assert_session = $this->assertSession(); - $assert_session->pageTextContains('Submitted: row1 = row1', 'Checked checkbox row1'); - $assert_session->pageTextContains('Submitted: row2 = 0', 'Unchecked checkbox row2.'); - $assert_session->pageTextContains('Submitted: row3 = 0', 'Unchecked checkbox row3.'); + $assert_session->pageTextContains('Submitted: row1 = row1'); + $assert_session->pageTextContains('Submitted: row2 = 0'); + $assert_session->pageTextContains('Submitted: row3 = 0'); // Test a submission with multiple checkboxes checked. $edit['tableselect[row1]'] = TRUE; $edit['tableselect[row3]'] = TRUE; $this->drupalPostForm('form_test/tableselect/multiple-true', $edit, 'Submit'); - $assert_session->pageTextContains('Submitted: row1 = row1', 'Checked checkbox row1.'); - $assert_session->pageTextContains('Submitted: row2 = 0', 'Unchecked checkbox row2.'); - $assert_session->pageTextContains('Submitted: row3 = row3', 'Checked checkbox row3.'); + $assert_session->pageTextContains('Submitted: row1 = row1'); + $assert_session->pageTextContains('Submitted: row2 = 0'); + $assert_session->pageTextContains('Submitted: row3 = row3'); } @@ -123,7 +124,7 @@ class ElementsTableSelectTest extends BrowserTestBase { public function testMultipleFalseSubmit() { $edit['tableselect'] = 'row1'; $this->drupalPostForm('form_test/tableselect/multiple-false', $edit, 'Submit'); - $this->assertSession()->pageTextContains('Submitted: row1', 'Selected radio button'); + $this->assertSession()->pageTextContains('Submitted: row1'); } /** diff --git a/core/modules/system/tests/src/Functional/Form/StorageTest.php b/core/modules/system/tests/src/Functional/Form/StorageTest.php index cb6c469f343..1005fd46f9d 100644 --- a/core/modules/system/tests/src/Functional/Form/StorageTest.php +++ b/core/modules/system/tests/src/Functional/Form/StorageTest.php @@ -66,7 +66,8 @@ class StorageTest extends BrowserTestBase { $this->drupalPostForm(NULL, $edit, 'Save'); $assert_session->pageTextContains('Form constructions: 4'); - $assert_session->pageTextContains('Title: new', 'The form storage has stored the values.'); + // Verify that the form storage has stored the values. + $assert_session->pageTextContains('Title: new'); } /** @@ -93,7 +94,8 @@ class StorageTest extends BrowserTestBase { $this->drupalPostForm(NULL, $edit, 'Save'); $this->assertSession()->pageTextContains('Form constructions: 4'); - $this->assertSession()->pageTextContains('Title: new', 'The form storage has stored the values.'); + // Verify that the form storage has stored the values. + $this->assertSession()->pageTextContains('Title: new'); } /** @@ -137,7 +139,7 @@ class StorageTest extends BrowserTestBase { // validation error. Post again and verify that the rebuilt form contains // the values of the updated form storage. $this->drupalPostForm(NULL, ['title' => 'foo', 'value' => 'bar'], 'Save'); - $this->assertSession()->pageTextContains("The thing has been changed.", 'The altered form storage value was updated in cache and taken over.'); + $this->assertSession()->pageTextContains("The thing has been changed."); } /** diff --git a/core/modules/system/tests/src/Functional/Routing/RouterTest.php b/core/modules/system/tests/src/Functional/Routing/RouterTest.php index 16a83898871..b8ac3cadc02 100644 --- a/core/modules/system/tests/src/Functional/Routing/RouterTest.php +++ b/core/modules/system/tests/src/Functional/Routing/RouterTest.php @@ -59,7 +59,7 @@ class RouterTest extends BrowserTestBase { $this->assertRaw('', 'Page markup was found.'); // In some instances, the subrequest handling may get confused and render // a page inception style. This test verifies that is not happening. - $this->assertSession()->responseNotMatches('#.*#s', 'There was no double-page effect from a misrendered subrequest.'); + $this->assertSession()->responseNotMatches('#.*#s'); // Confirm that route-level access check's cacheability is applied to the // X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags headers. @@ -156,7 +156,7 @@ class RouterTest extends BrowserTestBase { // In some instances, the subrequest handling may get confused and render // a page inception style. This test verifies that is not happening. - $this->assertSession()->responseNotMatches('#.*#s', 'There was no double-page effect from a misrendered subrequest.'); + $this->assertSession()->responseNotMatches('#.*#s'); } /** @@ -173,7 +173,7 @@ class RouterTest extends BrowserTestBase { // In some instances, the subrequest handling may get confused and render // a page inception style. This test verifies that is not happening. - $this->assertSession()->responseNotMatches('#.*#s', 'There was no double-page effect from a misrendered subrequest.'); + $this->assertSession()->responseNotMatches('#.*#s'); } /** @@ -190,7 +190,7 @@ class RouterTest extends BrowserTestBase { // In some instances, the subrequest handling may get confused and render // a page inception style. This test verifies that is not happening. - $this->assertSession()->responseNotMatches('#.*#s', 'There was no double-page effect from a misrendered subrequest.'); + $this->assertSession()->responseNotMatches('#.*#s'); } /** @@ -219,7 +219,7 @@ class RouterTest extends BrowserTestBase { // In some instances, the subrequest handling may get confused and render // a page inception style. This test verifies that is not happening. - $this->assertSession()->responseNotMatches('#.*#s', 'There was no double-page effect from a misrendered subrequest.'); + $this->assertSession()->responseNotMatches('#.*#s'); } /** diff --git a/core/modules/system/tests/src/FunctionalJavascript/Form/RebuildTest.php b/core/modules/system/tests/src/FunctionalJavascript/Form/RebuildTest.php index fef51c7c00d..d1365b898e4 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/Form/RebuildTest.php +++ b/core/modules/system/tests/src/FunctionalJavascript/Form/RebuildTest.php @@ -109,7 +109,7 @@ class RebuildTest extends WebDriverTestBase { 'title[0][value]' => $this->randomString(), ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertSession()->pageTextContains('Test file field is required.', 'Non-AJAX submission correctly triggered a validation error.'); + $this->assertSession()->pageTextContains('Test file field is required.'); // Ensure that the form contains two items in the multi-valued field, so we // know we're testing a form that was correctly retrieved from cache. diff --git a/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php index 8e1d576ca1c..3b12707f1b1 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php +++ b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php @@ -122,7 +122,7 @@ class FrameworkTest extends WebDriverTestBase { // information about the file; we only really care about whether it appears // in a LINK or STYLE tag, for which Drupal always adds a query string for // cache control. - $assert->responseNotContains('js.module.css?', 'Ajax lazy loading does not add overridden CSS files.'); + $assert->responseNotContains('js.module.css?'); } } diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php index 5d380d1f12e..5233169832b 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermPagerTest.php @@ -56,7 +56,8 @@ class TaxonomyTermPagerTest extends TaxonomyTestBase { // Get Page 1. $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); - $this->assertSession()->responseNotMatches('|