mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Comments: In wp_list_comments(), queries with custom pagination params should obey default comment_status logic.
When custom pagination parameters are passed to `wp_list_comments()`, a secondary query must be performed to fetch the proper comments. See [36157]. This query should show comments of the same `comment_status` as the default query initialized in `comments_template()`: show only comments that are approved, or those that are unapproved but belong to the current user. Props smerriman. Fixes #37048. git-svn-id: https://develop.svn.wordpress.org/trunk@37655 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -146,4 +146,88 @@ class Tests_Comment_WpListComments extends WP_UnitTestCase {
|
||||
preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
|
||||
$this->assertSame( array( $comments[3] ), array_map( 'intval', $matches[1] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37048
|
||||
*/
|
||||
public function test_custom_pagination_should_not_result_in_unapproved_comments_being_shown() {
|
||||
$p = self::factory()->post->create();
|
||||
|
||||
$comments = array();
|
||||
$now = time();
|
||||
for ( $i = 0; $i <= 5; $i++ ) {
|
||||
$comments[] = self::factory()->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
|
||||
'comment_author' => 'Commenter ' . $i,
|
||||
) );
|
||||
}
|
||||
|
||||
// Only 2 and 5 are approved.
|
||||
wp_set_comment_status( $comments[0], '0' );
|
||||
wp_set_comment_status( $comments[1], '0' );
|
||||
wp_set_comment_status( $comments[3], '0' );
|
||||
wp_set_comment_status( $comments[4], '0' );
|
||||
|
||||
update_option( 'page_comments', true );
|
||||
update_option( 'comments_per_page', 2 );
|
||||
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
// comments_template() populates $wp_query->comments
|
||||
get_echo( 'comments_template' );
|
||||
|
||||
$found = wp_list_comments( array(
|
||||
'echo' => false,
|
||||
'per_page' => 1,
|
||||
'page' => 2,
|
||||
) );
|
||||
|
||||
preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
|
||||
$this->assertSame( array( $comments[2] ), array_map( 'intval', $matches[1] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37048
|
||||
*/
|
||||
public function test_custom_pagination_should_allow_ones_own_unapproved_comments() {
|
||||
$p = self::factory()->post->create();
|
||||
$u = self::factory()->user->create();
|
||||
|
||||
$comments = array();
|
||||
$now = time();
|
||||
for ( $i = 0; $i <= 5; $i++ ) {
|
||||
$comments[] = self::factory()->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
|
||||
'comment_author' => 'Commenter ' . $i,
|
||||
'user_id' => $u,
|
||||
) );
|
||||
}
|
||||
|
||||
// Only 2 and 5 are approved.
|
||||
wp_set_comment_status( $comments[0], '0' );
|
||||
wp_set_comment_status( $comments[1], '0' );
|
||||
wp_set_comment_status( $comments[3], '0' );
|
||||
wp_set_comment_status( $comments[4], '0' );
|
||||
|
||||
update_option( 'page_comments', true );
|
||||
update_option( 'comments_per_page', 2 );
|
||||
|
||||
wp_set_current_user( $u );
|
||||
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
// comments_template() populates $wp_query->comments
|
||||
get_echo( 'comments_template' );
|
||||
|
||||
$found = wp_list_comments( array(
|
||||
'echo' => false,
|
||||
'per_page' => 1,
|
||||
'page' => 2,
|
||||
) );
|
||||
|
||||
preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
|
||||
$this->assertSame( array( $comments[4] ), array_map( 'intval', $matches[1] ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user