Allow comments to be queried by 'any' post_type or post_status.

Props kouratoras.
Fixes #35512.

git-svn-id: https://develop.svn.wordpress.org/trunk@36486 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-02-06 04:50:05 +00:00
parent eb8e2fb6ed
commit ddc9f3dccb
2 changed files with 104 additions and 4 deletions

View File

@@ -1749,6 +1749,84 @@ class Tests_Comment_Query extends WP_UnitTestCase {
$this->assertEqualSets( array_merge( $c1, $c3 ), $found );
}
/**
* @ticket 35512
*/
public function test_post_type_any_should_override_other_post_types() {
register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) );
register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) );
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) );
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) );
$c1 = self::factory()->comment->create_post_comments( $p1, 1 );
$c2 = self::factory()->comment->create_post_comments( $p2, 1 );
$q = new WP_Comment_Query();
$found = $q->query( array(
'fields' => 'ids',
'post_type' => array( 'any', 'post-type-1' ),
) );
$this->assertEqualSets( array_merge( $c1, $c2 ), $found );
}
/**
* @ticket 35512
*/
public function test_post_type_any_as_part_of_an_array_of_post_types() {
register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) );
register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) );
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) );
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) );
$c1 = self::factory()->comment->create_post_comments( $p1, 1 );
$c2 = self::factory()->comment->create_post_comments( $p2, 1 );
$q = new WP_Comment_Query();
$found = $q->query( array(
'fields' => 'ids',
'post_type' => array( 'any' ),
) );
$this->assertEqualSets( array_merge( $c1, $c2 ), $found );
}
/**
* @ticket 35512
*/
public function test_post_status_any_should_override_other_post_statuses() {
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$c1 = self::factory()->comment->create_post_comments( $p1, 1 );
$c2 = self::factory()->comment->create_post_comments( $p2, 1 );
$q = new WP_Comment_Query();
$found = $q->query( array(
'fields' => 'ids',
'post_status' => array( 'any', 'draft' ),
) );
$this->assertEqualSets( array_merge( $c1, $c2 ), $found );
}
/**
* @ticket 35512
*/
public function test_post_status_any_as_part_of_an_array_of_post_statuses() {
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$c1 = self::factory()->comment->create_post_comments( $p1, 1 );
$c2 = self::factory()->comment->create_post_comments( $p2, 1 );
$q = new WP_Comment_Query();
$found = $q->query( array(
'fields' => 'ids',
'post_status' => array( 'any' ),
) );
$this->assertEqualSets( array_merge( $c1, $c2 ), $found );
}
/**
* @ticket 24826
*/