From c70fe62ed182000e0d627c3b37b6941400f5f537 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 19 Jul 2021 14:00:11 +0000 Subject: [PATCH] Tests: Replace `assertContains()` with `assertStringContainsString()` when used with strings. Using the `assertContains()` and `assertNotContains()` methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9. While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+. These methods introduced in PHPUnit 7.5 should be used as an alternative: * `assertStringContainsString()` * `assertStringContainsStringIgnoringCase` * `assertStringNotContainsString()` * `assertStringNotContainsStringIgnoringCase` As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the `WP_UnitTestCase` class for PHPUnit < 7.5. Follow-up to [51331], [51451], [51461]. Props jrf, dd32, SergeyBiryukov. See #53363, #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51462 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/admin/includesListTable.php | 46 ++++----- tests/phpunit/tests/admin/includesPost.php | 26 ++--- .../phpunit/tests/admin/includesTemplate.php | 8 +- .../tests/admin/wpPrivacyRequestsTable.php | 2 +- tests/phpunit/tests/adminbar.php | 4 +- tests/phpunit/tests/ajax/Compression.php | 6 +- tests/phpunit/tests/ajax/CustomizeManager.php | 10 +- tests/phpunit/tests/ajax/DimComment.php | 2 +- tests/phpunit/tests/ajax/ReplytoComment.php | 2 +- tests/phpunit/tests/blocks/block-editor.php | 10 +- tests/phpunit/tests/blocks/render.php | 2 +- .../tests/category/wpDropdownCategories.php | 18 ++-- .../tests/category/wpListCategories.php | 84 ++++++++-------- tests/phpunit/tests/comment-submission.php | 10 +- tests/phpunit/tests/comment.php | 4 +- tests/phpunit/tests/comment/commentForm.php | 6 +- .../tests/comment/commentsTemplate.php | 10 +- .../phpunit/tests/comment/getCommentLink.php | 14 +-- .../tests/comment/getCommentReplyLink.php | 2 +- tests/phpunit/tests/comment/query.php | 44 ++++----- tests/phpunit/tests/customize/control.php | 12 +-- .../tests/customize/custom-css-setting.php | 6 +- tests/phpunit/tests/customize/manager.php | 54 +++++----- tests/phpunit/tests/customize/nav-menus.php | 36 +++---- tests/phpunit/tests/customize/panel.php | 20 ++-- tests/phpunit/tests/customize/partial.php | 2 +- tests/phpunit/tests/customize/section.php | 12 +-- tests/phpunit/tests/customize/widgets.php | 32 +++--- tests/phpunit/tests/date/query.php | 2 +- tests/phpunit/tests/db.php | 18 ++-- tests/phpunit/tests/dependencies/scripts.php | 4 +- tests/phpunit/tests/dependencies/styles.php | 2 +- tests/phpunit/tests/feed/rss2.php | 2 +- tests/phpunit/tests/formatting/Emoji.php | 16 +-- .../tests/formatting/MakeClickable.php | 2 +- tests/phpunit/tests/general/paginateLinks.php | 8 +- .../phpunit/tests/general/wpResourceHints.php | 2 +- tests/phpunit/tests/l10n.php | 66 ++++++------- .../tests/link/getNextCommentsLink.php | 4 +- .../tests/link/getPreviousCommentsLink.php | 2 +- .../tests/link/getThePrivacyPolicyLink.php | 4 +- tests/phpunit/tests/mail.php | 2 +- tests/phpunit/tests/media.php | 98 +++++++++---------- tests/phpunit/tests/meta/query.php | 6 +- tests/phpunit/tests/multisite/site.php | 4 +- tests/phpunit/tests/oembed/WpEmbed.php | 2 +- tests/phpunit/tests/oembed/template.php | 2 +- tests/phpunit/tests/post.php | 6 +- tests/phpunit/tests/post/attachments.php | 4 +- tests/phpunit/tests/post/getPages.php | 2 +- .../tests/post/getPostsByAuthorSql.php | 36 +++---- tests/phpunit/tests/post/getTheContent.php | 4 +- tests/phpunit/tests/post/output.php | 22 ++--- tests/phpunit/tests/post/query.php | 58 +++++------ tests/phpunit/tests/post/template.php | 8 +- ...acyGeneratePersonalDataExportGroupHtml.php | 42 ++++---- ...vacySendErasureFulfillmentNotification.php | 38 +++---- .../wpPrivacySendPersonalDataExportEmail.php | 26 ++--- ...acySendRequestConfirmationNotification.php | 10 +- tests/phpunit/tests/query.php | 8 +- tests/phpunit/tests/query/dateQuery.php | 8 +- tests/phpunit/tests/query/invalidQueries.php | 10 +- tests/phpunit/tests/query/noFoundRows.php | 16 +-- tests/phpunit/tests/query/postStatus.php | 10 +- tests/phpunit/tests/query/results.php | 6 +- tests/phpunit/tests/query/search.php | 2 +- .../rest-api/rest-attachments-controller.php | 6 +- .../rest-block-renderer-controller.php | 2 +- .../rest-api/rest-categories-controller.php | 16 +-- .../rest-api/rest-comments-controller.php | 10 +- .../tests/rest-api/rest-pages-controller.php | 4 +- .../tests/rest-api/rest-posts-controller.php | 14 +-- .../rest-api/rest-revisions-controller.php | 6 +- .../tests/rest-api/rest-tags-controller.php | 20 ++-- .../tests/rest-api/rest-users-controller.php | 12 +-- tests/phpunit/tests/rewrite.php | 2 +- tests/phpunit/tests/robots.php | 16 +-- tests/phpunit/tests/sitemaps/sitemaps.php | 8 +- tests/phpunit/tests/term/getTermBy.php | 4 +- tests/phpunit/tests/term/getTermLink.php | 18 ++-- tests/phpunit/tests/term/query.php | 4 +- .../phpunit/tests/term/wpGenerateTagCloud.php | 18 ++-- tests/phpunit/tests/theme/customHeader.php | 6 +- tests/phpunit/tests/user.php | 8 +- tests/phpunit/tests/user/author.php | 12 +-- tests/phpunit/tests/user/query.php | 36 +++---- tests/phpunit/tests/user/wpDropdownUsers.php | 24 ++--- .../phpunit/tests/user/wpSendUserRequest.php | 40 ++++---- tests/phpunit/tests/widgets.php | 46 ++++----- .../tests/widgets/custom-html-widget.php | 22 ++--- .../tests/widgets/media-audio-widget.php | 12 +-- .../tests/widgets/media-gallery-widget.php | 12 +-- .../tests/widgets/media-image-widget.php | 60 ++++++------ .../tests/widgets/media-video-widget.php | 24 ++--- tests/phpunit/tests/widgets/media-widget.php | 16 +-- tests/phpunit/tests/widgets/text-widget.php | 96 +++++++++--------- tests/phpunit/tests/widgets/wpWidgetRss.php | 2 +- 97 files changed, 811 insertions(+), 811 deletions(-) diff --git a/tests/phpunit/tests/admin/includesListTable.php b/tests/phpunit/tests/admin/includesListTable.php index eaa496021c..a9f5df0205 100644 --- a/tests/phpunit/tests/admin/includesListTable.php +++ b/tests/phpunit/tests/admin/includesListTable.php @@ -221,7 +221,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $this->assertCount( count( $expected_ids ), array_keys( $matches[0] ) ); foreach ( $expected_ids as $id ) { - $this->assertContains( sprintf( 'id="post-%d"', $id ), $output ); + $this->assertStringContainsString( sprintf( 'id="post-%d"', $id ), $output ); } } @@ -236,7 +236,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $this->table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertNotContains( 'id="post-query-submit"', $output ); + $this->assertStringNotContainsString( 'id="post-query-submit"', $output ); } /** @@ -250,7 +250,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $this->table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertNotContains( 'id="filter-by-date"', $output ); + $this->assertStringNotContainsString( 'id="filter-by-date"', $output ); } /** @@ -264,7 +264,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $this->table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertNotContains( 'id="cat"', $output ); + $this->assertStringNotContainsString( 'id="cat"', $output ); } /** @@ -278,7 +278,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $this->table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertNotContains( 'id="delete_all"', $output ); + $this->assertStringNotContainsString( 'id="delete_all"', $output ); } /** @@ -291,7 +291,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertNotContains( 'id="post-query-submit"', $output ); + $this->assertStringNotContainsString( 'id="post-query-submit"', $output ); } /** @@ -313,7 +313,7 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertContains( 'id="post-query-submit"', $output ); + $this->assertStringContainsString( 'id="post-query-submit"', $output ); } /** @@ -335,8 +335,8 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase { $table->extra_tablenav( 'top' ); $output = ob_get_clean(); - $this->assertContains( 'id="filter-by-comment-type"', $output ); - $this->assertContains( "