From b12e340f11152343b0eb0614cdff2e1a5a42efcf Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 1 Mar 2023 14:43:27 +0000 Subject: [PATCH] Tests: Add unit tests for `get_next_posts_link()` and `get_previous_posts_link()`. The tests ensure that the `next_posts_link_attributes` and `previous_posts_link_attributes` filters are applied correctly. Follow-up to [1383], [5045], [8502], [9632], [55429]. Props geisthanen, mukesh27, costdev, audrasjb, SergeyBiryukov. Fixes #55751. git-svn-id: https://develop.svn.wordpress.org/trunk@55442 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/link/getNextPostsLink.php | 46 +++++++++++++++++++ .../tests/link/getPreviousPostsLink.php | 46 +++++++++++++++++++ .../tests/link/getThePostsNavigation.php | 2 +- 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/tests/link/getNextPostsLink.php create mode 100644 tests/phpunit/tests/link/getPreviousPostsLink.php diff --git a/tests/phpunit/tests/link/getNextPostsLink.php b/tests/phpunit/tests/link/getNextPostsLink.php new file mode 100644 index 0000000000..8df7d10ff0 --- /dev/null +++ b/tests/phpunit/tests/link/getNextPostsLink.php @@ -0,0 +1,46 @@ +post->create_many( 3 ); + $paged = 2; + $wp_query = new WP_Query( + array( + 'post_type' => 'post', + 'posts_per_page' => 1, + 'paged' => $paged, + ) + ); + } + + /** + * Tests that the 'next_posts_link_attributes' filter is applied correctly. + * + * @ticket 55751 + */ + public function test_get_next_posts_link_should_apply_next_posts_link_attributes_filter() { + $filter = new MockAction(); + add_filter( 'next_posts_link_attributes', array( &$filter, 'filter' ) ); + + get_next_posts_link(); + + $this->assertSame( 1, $filter->get_call_count() ); + } +} diff --git a/tests/phpunit/tests/link/getPreviousPostsLink.php b/tests/phpunit/tests/link/getPreviousPostsLink.php new file mode 100644 index 0000000000..ea7220b2dc --- /dev/null +++ b/tests/phpunit/tests/link/getPreviousPostsLink.php @@ -0,0 +1,46 @@ +post->create_many( 3 ); + $paged = 2; + $wp_query = new WP_Query( + array( + 'post_type' => 'post', + 'posts_per_page' => 1, + 'paged' => $paged, + ) + ); + } + + /** + * Tests that the 'previous_posts_link_attributes' filter is applied correctly. + * + * @ticket 55751 + */ + public function test_get_previous_posts_link_should_apply_previous_posts_link_attributes_filter() { + $filter = new MockAction(); + add_filter( 'previous_posts_link_attributes', array( &$filter, 'filter' ) ); + + get_previous_posts_link(); + + $this->assertSame( 1, $filter->get_call_count() ); + } +} diff --git a/tests/phpunit/tests/link/getThePostsNavigation.php b/tests/phpunit/tests/link/getThePostsNavigation.php index c09350d054..83c262d911 100644 --- a/tests/phpunit/tests/link/getThePostsNavigation.php +++ b/tests/phpunit/tests/link/getThePostsNavigation.php @@ -1,7 +1,7 @@