Changeset 28562 for trunk/tests/phpunit/tests/term/query.php
- Timestamp:
- 05/23/2014 07:58:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/query.php
r28188 r28562 99 99 $this->assertEquals( array( $post_id1, $post_id2 ), $ids ); 100 100 } 101 102 function test_tax_query_no_taxonomy() { 103 $cat_id = $this->factory->category->create( array( 'name' => 'alpha' ) ); 104 $this->factory->post->create( array( 'post_title' => 'alpha', 'post_category' => array( $cat_id ) ) ); 105 106 $response1 = new WP_Query( array( 107 'tax_query' => array( 108 array( 'terms' => array( $cat_id ) ) 109 ) 110 ) ); 111 $this->assertEmpty( $response1->posts ); 112 113 $response2 = new WP_Query( array( 114 'tax_query' => array( 115 array( 116 'taxonomy' => 'category', 117 'terms' => array( $cat_id ) 118 ) 119 ) 120 ) ); 121 $this->assertNotEmpty( $response2->posts ); 122 123 $term = get_category( $cat_id ); 124 $response3 = new WP_Query( array( 125 'tax_query' => array( 126 array( 127 'field' => 'term_taxonomy_id', 128 'terms' => array( $term->term_taxonomy_id ) 129 ) 130 ) 131 ) ); 132 $this->assertNotEmpty( $response3->posts ); 133 } 134 135 function test_term_taxonomy_id_field_no_taxonomy() { 136 $posts = $this->factory->post->create_many( 5 ); 137 138 $cats = $tags = array(); 139 140 // need term_taxonomy_ids in addition to term_ids, so no factory 141 for ( $i = 0; $i < 5; $i++ ) { 142 $cats[$i] = wp_insert_term( 'category-' . $i , 'category' ); 143 $tags[$i] = wp_insert_term( 'tag-' . $i, 'post_tag' ); 144 145 // post 0 gets all terms 146 wp_set_object_terms( $posts[0], array( $cats[$i]['term_id'] ), 'category', true ); 147 wp_set_object_terms( $posts[0], array( $tags[$i]['term_id'] ), 'post_tag', true ); 148 } 149 150 wp_set_object_terms( $posts[1], array( $cats[0]['term_id'], $cats[2]['term_id'], $cats[4]['term_id'] ), 'category' ); 151 wp_set_object_terms( $posts[1], array( $tags[0]['term_id'], $tags[2]['term_id'], $cats[4]['term_id'] ), 'post_tag' ); 152 153 wp_set_object_terms( $posts[2], array( $cats[1]['term_id'], $cats[3]['term_id'] ), 'category' ); 154 wp_set_object_terms( $posts[2], array( $tags[1]['term_id'], $tags[3]['term_id'] ), 'post_tag' ); 155 156 wp_set_object_terms( $posts[3], array( $cats[0]['term_id'], $cats[2]['term_id'], $cats[4]['term_id'] ), 'category' ); 157 wp_set_object_terms( $posts[3], array( $tags[1]['term_id'], $tags[3]['term_id'] ), 'post_tag' ); 158 159 $results1 = $this->q->query( array( 160 'fields' => 'ids', 161 'orderby' => 'id', 162 'order' => 'ASC', 163 'tax_query' => array( 164 'relation' => 'OR', 165 array( 166 'field' => 'term_taxonomy_id', 167 'terms' => array( $cats[0]['term_taxonomy_id'], $cats[2]['term_taxonomy_id'], $cats[4]['term_taxonomy_id'], $tags[0]['term_taxonomy_id'], $tags[2]['term_taxonomy_id'], $cats[4]['term_taxonomy_id'] ), 168 'operator' => 'AND', 169 'include_children' => false, 170 ), 171 array( 172 'field' => 'term_taxonomy_id', 173 'terms' => array( $cats[1]['term_taxonomy_id'], $cats[3]['term_taxonomy_id'], $tags[1]['term_taxonomy_id'], $tags[3]['term_taxonomy_id'] ), 174 'operator' => 'AND', 175 'include_children' => false, 176 ) 177 ) 178 ) ); 179 180 $this->assertEquals( array( $posts[0], $posts[1], $posts[2] ), $results1, 'Relation: OR; Operator: AND' ); 181 182 $results2 = $this->q->query( array( 183 'fields' => 'ids', 184 'orderby' => 'id', 185 'order' => 'ASC', 186 'tax_query' => array( 187 'relation' => 'AND', 188 array( 189 'field' => 'term_taxonomy_id', 190 'terms' => array( $cats[0]['term_taxonomy_id'], $tags[0]['term_taxonomy_id'] ), 191 'operator' => 'IN', 192 'include_children' => false, 193 ), 194 array( 195 'field' => 'term_taxonomy_id', 196 'terms' => array( $cats[3]['term_taxonomy_id'], $tags[3]['term_taxonomy_id'] ), 197 'operator' => 'IN', 198 'include_children' => false, 199 ) 200 ) 201 ) ); 202 203 $this->assertEquals( array( $posts[0], $posts[3] ), $results2, 'Relation: AND; Operator: IN' ); 204 } 101 205 }
Note: See TracChangeset
for help on using the changeset viewer.