mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
After [34561], `wp_list_comments()` no longer passed all of a post's comments to `Walker_Comments`. As a result, calls to `get_comment_link()` occurring inside the comment loop had insufficient context to determine the proper 'cpage' value to use when generating comment permalinks. This, in turn, caused comment permalinks to behave erratically. The current changeset addresses the problem as follows: * `get_comment_link()` now accepts a 'cpage' parameter. When present, 'cpage' will be used to build the comment permalink - no automatic calculation will take place. * When called within the main loop, `wp_list_comments()` calculates the proper 'cpage' value for comments in the loop, and passes it down to `get_comment_link()`. * `cpage` and `comment-page-x` query vars are generally required in comment permalinks (see #34068), but an exception is made when 'default_comment_page=oldest': the bare post permalink will always be the same as `cpage=1`, so `cpage` is excluded in this case. Props peterwilsoncc for assiduous spreadsheeting. Fixes #34073. git-svn-id: https://develop.svn.wordpress.org/trunk@34735 602fd350-edb4-49c9-b593-d223f7449a82
119 lines
3.2 KiB
PHP
119 lines
3.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group comment
|
|
*/
|
|
class Tests_Comment_GetCommentLink extends WP_UnitTestCase {
|
|
protected $p;
|
|
protected $comments = array();
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
|
|
$now = time();
|
|
$this->p = $this->factory->post->create();
|
|
$this->comments[] = $this->factory->comment->create( array(
|
|
'comment_post_ID' => $this->p,
|
|
'comment_content' => '1',
|
|
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
|
) );
|
|
$this->comments[] = $this->factory->comment->create( array(
|
|
'comment_post_ID' => $this->p,
|
|
'comment_content' => '2',
|
|
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
|
) );
|
|
$this->comments[] = $this->factory->comment->create( array(
|
|
'comment_post_ID' => $this->p,
|
|
'comment_content' => '3',
|
|
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
|
) );
|
|
$this->comments[] = $this->factory->comment->create( array(
|
|
'comment_post_ID' => $this->p,
|
|
'comment_content' => '4',
|
|
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
|
) );
|
|
$this->comments[] = $this->factory->comment->create( array(
|
|
'comment_post_ID' => $this->p,
|
|
'comment_content' => '4',
|
|
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
|
|
) );
|
|
$this->comments[] = $this->factory->comment->create( array(
|
|
'comment_post_ID' => $this->p,
|
|
'comment_content' => '4',
|
|
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
|
|
) );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34068
|
|
*/
|
|
public function test_default_comments_page_newest_default_page_should_have_cpage() {
|
|
update_option( 'default_comments_page', 'newest' );
|
|
update_option( 'comments_per_page', 2 );
|
|
|
|
$found = get_comment_link( $this->comments[1] );
|
|
|
|
$this->assertContains( 'cpage=3', $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34068
|
|
*/
|
|
public function test_default_comments_page_newest_middle_page_should_have_cpage() {
|
|
update_option( 'default_comments_page', 'newest' );
|
|
update_option( 'comments_per_page', 2 );
|
|
|
|
$found = get_comment_link( $this->comments[3] );
|
|
|
|
$this->assertContains( 'cpage=2', $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34068
|
|
*/
|
|
public function test_default_comments_page_newest_last_page_should_have_cpage() {
|
|
update_option( 'default_comments_page', 'newest' );
|
|
update_option( 'comments_per_page', 2 );
|
|
|
|
$found = get_comment_link( $this->comments[5] );
|
|
|
|
$this->assertContains( 'cpage=1', $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34068
|
|
*/
|
|
public function test_default_comments_page_oldest_default_page_should_not_have_cpage() {
|
|
update_option( 'default_comments_page', 'oldest' );
|
|
update_option( 'comments_per_page', 2 );
|
|
|
|
$found = get_comment_link( $this->comments[5] );
|
|
|
|
$this->assertNotContains( 'cpage', $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34068
|
|
*/
|
|
public function test_default_comments_page_oldest_middle_page_should_have_cpage() {
|
|
update_option( 'default_comments_page', 'oldest' );
|
|
update_option( 'comments_per_page', 2 );
|
|
|
|
$found = get_comment_link( $this->comments[3] );
|
|
|
|
$this->assertContains( 'cpage=2', $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34068
|
|
*/
|
|
public function test_default_comments_page_oldest_last_page_should_have_cpage() {
|
|
update_option( 'default_comments_page', 'oldest' );
|
|
update_option( 'comments_per_page', 2 );
|
|
|
|
$found = get_comment_link( $this->comments[1] );
|
|
|
|
$this->assertContains( 'cpage=3', $found );
|
|
}
|
|
}
|