Make WordPress Core

Changeset 28188


Ignore:
Timestamp:
04/23/2014 05:40:25 PM (12 years ago)
Author:
wonderboymusic
Message:

Add a conditional unit test for Tax Query - one query that does an IN query for categories with relation for tax_query set to AND. Weird queries are being produced.

See #27193.

File:
1 edited

Legend:

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

    r25278 r28188  
    6363                $this->assertEquals( array( $image_id ), $posts );
    6464        }
     65
     66        /**
     67         * @ticket 27193
     68         */
     69        function test_cat_or_tag() {
     70                $category1 = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'alpha' ) );
     71                $category2 = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'beta' ) );
     72
     73                $tag1 = $this->factory->term->create( array( 'taxonomy' => 'post_tag', 'name' => 'gamma' ) );
     74                $tag2 = $this->factory->term->create( array( 'taxonomy' => 'post_tag', 'name' => 'delta' ) );
     75
     76                $post_id1 = $this->factory->post->create( array( 'post_title' => 'alpha', 'post_category' => array( $category1 ) ) );
     77                $terms1 = get_the_category( $post_id1 );
     78                $this->assertEquals( array( get_category( $category1 ) ), $terms1 );
     79
     80                $post_id2 = $this->factory->post->create( array( 'post_title' => 'beta', 'post_category' => array( $category2 ) ) );
     81                $terms2 = get_the_category( $post_id2 );
     82                $this->assertEquals( array( get_category( $category2 ) ), $terms2 );
     83
     84                $post_id3 = $this->factory->post->create( array( 'post_title' => 'gamma', 'post_tag' => array( $tag1 ) ) );
     85                $post_id4 = $this->factory->post->create( array( 'post_title' => 'delta', 'post_tag' => array( $tag2 ) ) );
     86
     87                $query = new WP_Query( array(
     88                        'fields' => 'ids',
     89                        'tax_query' => array(
     90                                //'relation' => 'OR',
     91                                array(
     92                                        'taxonomy' => 'category',
     93                                        'field' => 'term_id',
     94                                        'terms' => array( $category1, $category2 )
     95                                )
     96                        )
     97                ) );
     98                $ids = $query->get_posts();
     99                $this->assertEquals( array( $post_id1, $post_id2 ), $ids );
     100        }
    65101}
Note: See TracChangeset for help on using the changeset viewer.