Make WordPress Core


Ignore:
Timestamp:
06/04/2014 05:49:26 PM (11 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/query.php

    r28647 r28664  
    203203        $this->assertEquals( array( $posts[0], $posts[3] ), $results2, 'Relation: AND; Operator: IN' );
    204204    }
     205
     206    function test_empty__in() {
     207        $cat_id = $this->factory->category->create();
     208        $post_id = $this->factory->post->create();
     209        wp_set_post_categories( $post_id, $cat_id );
     210
     211        $q1 = get_posts( array( 'category__in' => array( $cat_id ) ) );
     212        $this->assertNotEmpty( $q1 );
     213        $q2 = get_posts( array( 'category__in' => array() ) );
     214        $this->assertEmpty( $q2 );
     215
     216        $tag = wp_insert_term( 'woo', 'post_tag' );
     217        $tag_id = $tag['term_id'];
     218        $slug = get_tag( $tag_id )->slug;
     219        wp_set_post_tags( $post_id, $slug );
     220
     221        $q3 = get_posts( array( 'tag__in' => array( $tag_id ) ) );
     222        $this->assertNotEmpty( $q3 );
     223        $q4 = get_posts( array( 'tag__in' => array() ) );
     224        $this->assertEmpty( $q4 );
     225
     226        $q5 = get_posts( array( 'tag_slug__in' => array( $slug ) ) );
     227        $this->assertNotEmpty( $q5 );
     228        $q6 = get_posts( array( 'tag_slug__in' => array() ) );
     229        $this->assertEmpty( $q6 );
     230    }
    205231}
Note: See TracChangeset for help on using the changeset viewer.