Support multiple 'status' values in WP_Comment_Query.

This change required turning the SQL concatenation into the generation of an
array, for greater flexibility.

Props karpstrucking, ebinnion.
Fixes #29612.

git-svn-id: https://develop.svn.wordpress.org/trunk@30084 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2014-10-29 02:21:10 +00:00
parent 5569f01459
commit 7c4aada4a6
2 changed files with 142 additions and 37 deletions
+64
View File
@@ -75,6 +75,70 @@ class Tests_Comment_Query extends WP_UnitTestCase {
$this->assertEqualSets( array( $c1, $c3 ), $found );
}
public function test_status_default_to_all() {
$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' => 'foo' ) );
$c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
$q = new WP_Comment_Query();
$found = $q->query( array(
'fields' => 'ids',
) );
$this->assertEqualSets( array( $c1, $c3 ), $found );
}
/**
* @ticket 29612
*/
public function test_status_comma_any() {
$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' => 'foo' ) );
$c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
$q = new WP_Comment_Query();
$found = $q->query( array(
'status' => 'any',
'fields' => 'ids',
) );
$this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
}
/**
* @ticket 29612
*/
public function test_status_comma_separated() {
$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' => 'foo' ) );
$c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
$q = new WP_Comment_Query();
$found = $q->query( array(
'status' => 'approve,foo,bar',
'fields' => 'ids',
) );
$this->assertEqualSets( array( $c1, $c2 ), $found );
}
/**
* @ticket 29612
*/
public function test_status_array() {
$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' => 'foo' ) );
$c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
$q = new WP_Comment_Query();
$found = $q->query( array(
'status' => array( 'approve', 'foo', 'bar', ),
'fields' => 'ids',
) );
$this->assertEqualSets( array( $c1, $c2 ), $found );
}
function test_get_comments_for_post() {
$post_id = $this->factory->post->create();
$this->factory->comment->create_post_comments( $post_id, 10 );