mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
In get_next_comments_link(), ensure proper pagination when no 'cpage' query var is found.
The 'cpage' query var is only set when using `comments_template()` to display comments. If displaying them in a context where 'cpage' is not yet set, the default value should be 1, not 0. Props MomDad, couturefreak. Fixes #20319. git-svn-id: https://develop.svn.wordpress.org/trunk@31617 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
18af27f550
commit
07abae914e
@ -2466,6 +2466,10 @@ function get_next_comments_link( $label = '', $max_page = 0 ) {
|
||||
|
||||
$page = get_query_var('cpage');
|
||||
|
||||
if ( ! $page ) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$nextpage = intval($page) + 1;
|
||||
|
||||
if ( empty($max_page) )
|
||||
|
||||
51
tests/phpunit/tests/link/getNextCommentsLink.php
Normal file
51
tests/phpunit/tests/link/getNextCommentsLink.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group link
|
||||
* @group comment
|
||||
* @covers ::get_next_comments_link
|
||||
*/
|
||||
class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase {
|
||||
public function setUp() {
|
||||
global $wp_rewrite;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
public function test_page_should_respect_value_of_cpage_query_var() {
|
||||
update_option( 'page_comments', '1' );
|
||||
$p = $this->factory->post->create();
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
$cpage = get_query_var( 'cpage' );
|
||||
set_query_var( 'cpage', 3 );
|
||||
|
||||
$link = get_next_comments_link( 'Next', 5 );
|
||||
|
||||
$this->assertContains( 'cpage=4', $link );
|
||||
|
||||
set_query_var( 'cpage', $cpage );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 20319
|
||||
*/
|
||||
public function test_page_should_default_to_1_when_no_cpage_query_var_is_found() {
|
||||
update_option( 'page_comments', '1' );
|
||||
$p = $this->factory->post->create();
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
$cpage = get_query_var( 'cpage' );
|
||||
set_query_var( 'cpage', '' );
|
||||
|
||||
$link = get_next_comments_link( 'Next', 5 );
|
||||
|
||||
$this->assertContains( 'cpage=2', $link );
|
||||
|
||||
set_query_var( 'cpage', $cpage );
|
||||
}
|
||||
|
||||
}
|
||||
49
tests/phpunit/tests/link/getPreviousCommentsLink.php
Normal file
49
tests/phpunit/tests/link/getPreviousCommentsLink.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group link
|
||||
* @group comment
|
||||
* @covers ::get_previous_comments_link
|
||||
*/
|
||||
class Tests_Link_GetPreviousCommentsLink extends WP_UnitTestCase {
|
||||
public function setUp() {
|
||||
global $wp_rewrite;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
public function test_page_should_respect_value_of_cpage_query_var() {
|
||||
update_option( 'page_comments', '1' );
|
||||
$p = $this->factory->post->create();
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
$cpage = get_query_var( 'cpage' );
|
||||
set_query_var( 'cpage', 3 );
|
||||
|
||||
$link = get_previous_comments_link( 'Next' );
|
||||
|
||||
$this->assertContains( 'cpage=2', $link );
|
||||
|
||||
set_query_var( 'cpage', $cpage );
|
||||
}
|
||||
|
||||
public function test_page_should_default_to_1_when_no_cpage_query_var_is_found() {
|
||||
update_option( 'page_comments', '1' );
|
||||
$p = $this->factory->post->create();
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
$cpage = get_query_var( 'cpage' );
|
||||
set_query_var( 'cpage', '' );
|
||||
|
||||
$link = get_previous_comments_link( 'Next', 5 );
|
||||
|
||||
// Technically, it returns null here.
|
||||
$this->assertEquals( '', $link );
|
||||
|
||||
set_query_var( 'cpage', $cpage );
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user