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
This commit is contained in:
Sergey Biryukov 2023-03-01 14:43:27 +00:00
parent 8ec9e42cc9
commit b12e340f11
3 changed files with 93 additions and 1 deletions

View File

@ -0,0 +1,46 @@
<?php
/**
* Tests the `get_next_posts_link()` function.
*
* @since 6.2.0
*
* @group link
*
* @covers ::get_next_posts_link
*/
class Tests_Link_GetNextPostsLink extends WP_UnitTestCase {
/**
* Creates posts before any tests run.
*
* @param WP_UnitTest_Factory $factory
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
global $wp_query, $paged;
$factory->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() );
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Tests the `get_previous_posts_link()` function.
*
* @since 6.2.0
*
* @group link
*
* @covers ::get_previous_posts_link
*/
class Tests_Link_GetPreviousPostsLink extends WP_UnitTestCase {
/**
* Creates posts before any tests run.
*
* @param WP_UnitTest_Factory $factory
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
global $wp_query, $paged;
$factory->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() );
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* Tests get_the_posts_navigation function.
* Tests the `get_the_posts_navigation()` function.
*
* @since 6.2.0
*