Comments: in WP_Comment::get_children(), accept an array so that the values for format, status, hierarchical, and orderby can be passed, instead of just format. The defaults for get_comments() include status = 'all' and orderby = '' - which is no bueno.

For threaded comments, we need comments to be retrieved within bounds, so logged-out users don't see unmoderated comments on the front end, etc.

Updates unit tests.

See #8071.


git-svn-id: https://develop.svn.wordpress.org/trunk@34569 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-09-26 02:24:17 +00:00
parent bc451880e5
commit e09edc2d7f
3 changed files with 124 additions and 15 deletions

View File

@@ -2023,23 +2023,89 @@ class Tests_Comment_Query extends WP_UnitTestCase {
'comment_parent' => $c5,
) );
$q = new WP_Comment_Query( array(
'post_id' => $this->post_id,
$args = array(
'hierarchical' => 'threaded',
'orderby' => 'comment_ID',
'order' => 'ASC',
);
$query_args = array_merge( $args, array(
'post_id' => $this->post_id,
) );
$q = new WP_Comment_Query( $query_args );
// Top-level comments.
$this->assertEqualSets( array( $c1, $c5 ), array_values( wp_list_pluck( $q->comments, 'comment_ID' ) ) );
// Direct descendants of $c1.
$this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children(), 'comment_ID' ) ) );
$this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children( $args ), 'comment_ID' ) ) );
// Direct descendants of $c2.
$this->assertEqualSets( array( $c3 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children(), 'comment_ID' ) ) );
$this->assertEqualSets( array( $c3 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) );
// Direct descendants of $c5.
$this->assertEqualSets( array( $c6 ), array_values( wp_list_pluck( $q->comments[ $c5 ]->get_children(), 'comment_ID' ) ) );
$this->assertEqualSets( array( $c6 ), array_values( wp_list_pluck( $q->comments[ $c5 ]->get_children( $args ), 'comment_ID' ) ) );
}
/**
* @ticket 8071
*/
public function test_hierarchical_threaded_approved() {
$c1 = $this->factory->comment->create( array(
'comment_post_ID' => $this->post_id,
'comment_approved' => '1',
) );
$c2 = $this->factory->comment->create( array(
'comment_post_ID' => $this->post_id,
'comment_approved' => '1',
'comment_parent' => $c1,
) );
$c3 = $this->factory->comment->create( array(
'comment_post_ID' => $this->post_id,
'comment_approved' => '0',
'comment_parent' => $c2,
) );
$c4 = $this->factory->comment->create( array(
'comment_post_ID' => $this->post_id,
'comment_approved' => '1',
'comment_parent' => $c1,
) );
$c5 = $this->factory->comment->create( array(
'comment_post_ID' => $this->post_id,
'comment_approved' => '1',
) );
$this->factory->comment->create( array(
'comment_post_ID' => $this->post_id,
'comment_approved' => '1',
'comment_parent' => $c5,
) );
$args = array(
'hierarchical' => 'threaded',
'status' => 'approve',
'orderby' => 'comment_ID',
'order' => 'ASC',
);
$query_args = array_merge( $args, array(
'post_id' => $this->post_id,
) );
$q = new WP_Comment_Query( $query_args );
// Top-level comments.
$this->assertEqualSets( array( $c1, $c5 ), array_values( wp_list_pluck( $q->comments, 'comment_ID' ) ) );
// Direct descendants of $c1.
$this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children( $args ), 'comment_ID' ) ) );
// Direct descendants of $c2.
$this->assertEqualSets( array(), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) );
}
}