Comments: Query used to fill comment descendants should reset 'offset' and 'number' params.

Descendant queries should not inherit the 'offset' and 'number'
parameters of the parent query, or descendants will be missed.

Previously: [38497].

See #37696.

git-svn-id: https://develop.svn.wordpress.org/trunk@39274 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-11-17 03:02:40 +00:00
parent 1e05bf877e
commit 206a330d72
2 changed files with 36 additions and 0 deletions

View File

@ -996,6 +996,8 @@ class WP_Comment_Query {
$parent_query_args['parent__in'] = $uncached_parent_ids;
$parent_query_args['no_found_rows'] = true;
$parent_query_args['hierarchical'] = false;
$parent_query_args['offset'] = 0;
$parent_query_args['number'] = 0;
$level_comments = get_comments( $parent_query_args );

View File

@ -2543,6 +2543,40 @@ class Tests_Comment_Query extends WP_UnitTestCase {
$this->assertEqualSets( $q1_ids, $q2_ids );
}
/**
* @ticket 37966
* @ticket 37696
*/
public function test_fill_hierarchy_should_disregard_offset_and_number() {
$c0 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c1 ) );
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) );
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) );
$q = new WP_Comment_Query();
$found = $q->query( array(
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'post_id' => self::$post_id,
'no_found_rows' => false,
'hierarchical' => 'threaded',
'number' => 2,
'offset' => 1,
) );
$found_1 = $found[ $c1 ];
$children_1 = $found_1->get_children();
$this->assertEqualSets( array( $c2 ), array_keys( $children_1 ) );
$found_3 = $found[ $c3 ];
$children_3 = $found_3->get_children();
$this->assertEqualSets( array( $c4, $c5 ), array_keys( $children_3 ) );
}
/**
* @ticket 27571
*/