After [28613], also kill queries that explicityly pass empty arrays to category__in, tag__in, tag_slug__in, and author__in to WP_Query.

Adds unit tests.
Fixes #28099.


git-svn-id: https://develop.svn.wordpress.org/trunk@28664 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2014-06-04 17:49:26 +00:00
parent e0e0685ebd
commit ee9f2e48bb
3 changed files with 45 additions and 0 deletions

View File

@@ -513,6 +513,9 @@ class Tests_Query_Results extends WP_UnitTestCase {
$author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) );
$this->assertEqualSets( array( $author_1, $author_2 ), $author_ids );
$posts = $this->q->query( array( 'author__in' => array() ) );
$this->assertEmpty( $posts );
$posts = $this->q->query( array(
'author__not_in' => array( $author_1, $author_2 ),
'post__in' => array( $post_1, $post_2, $post_3, $post_4 )

View File

@@ -202,4 +202,30 @@ class Tests_Tax_Query extends WP_UnitTestCase {
$this->assertEquals( array( $posts[0], $posts[3] ), $results2, 'Relation: AND; Operator: IN' );
}
function test_empty__in() {
$cat_id = $this->factory->category->create();
$post_id = $this->factory->post->create();
wp_set_post_categories( $post_id, $cat_id );
$q1 = get_posts( array( 'category__in' => array( $cat_id ) ) );
$this->assertNotEmpty( $q1 );
$q2 = get_posts( array( 'category__in' => array() ) );
$this->assertEmpty( $q2 );
$tag = wp_insert_term( 'woo', 'post_tag' );
$tag_id = $tag['term_id'];
$slug = get_tag( $tag_id )->slug;
wp_set_post_tags( $post_id, $slug );
$q3 = get_posts( array( 'tag__in' => array( $tag_id ) ) );
$this->assertNotEmpty( $q3 );
$q4 = get_posts( array( 'tag__in' => array() ) );
$this->assertEmpty( $q4 );
$q5 = get_posts( array( 'tag_slug__in' => array( $slug ) ) );
$this->assertNotEmpty( $q5 );
$q6 = get_posts( array( 'tag_slug__in' => array() ) );
$this->assertEmpty( $q6 );
}
}