| 234 | |
| 235 | public function test_operator_not_exists() { |
| 236 | $c1 = $this->factory->category->create(); |
| 237 | $t1 = $this->factory->term->create( array( 'taxonomy' => 'post_tag', 'name' => 'foo' ) ); |
| 238 | $t2 = $this->factory->term->create( array( 'taxonomy' => 'post_tag', 'name' => 'bar' ) ); |
| 239 | |
| 240 | $p1 = $this->factory->post->create(); |
| 241 | $p2 = $this->factory->post->create(); |
| 242 | $p3 = $this->factory->post->create(); |
| 243 | |
| 244 | wp_set_object_terms( $p1, array( $c1 ), 'category' ); |
| 245 | wp_set_object_terms( $p2, array( $t1 ), 'post_tag' ); |
| 246 | wp_set_object_terms( $p3, array( $t1 ), 'post_tag' ); |
| 247 | wp_set_object_terms( $p3, array( $t2 ), 'post_tag' ); |
| 248 | |
| 249 | $found1 = $this->q->query( array( |
| 250 | 'fields' => 'ids', |
| 251 | 'orderby' => 'ID', |
| 252 | 'order' => 'ASC', |
| 253 | 'tax_query' => array( |
| 254 | array( |
| 255 | 'taxonomy' => 'post_tag', |
| 256 | 'operator' => 'NOT EXISTS', |
| 257 | ), |
| 258 | ), |
| 259 | ) ); |
| 260 | |
| 261 | $this->assertSame( array( $p1 ), $found1 ); |
| 262 | } |
| 263 | |
| 264 | public function test_operator_exists() { |
| 265 | $c1 = $this->factory->category->create(); |
| 266 | $t1 = $this->factory->term->create( array( 'taxonomy' => 'post_tag', 'name' => 'foo' ) ); |
| 267 | $t2 = $this->factory->term->create( array( 'taxonomy' => 'post_tag', 'name' => 'bar' ) ); |
| 268 | $p1 = $this->factory->post->create(); |
| 269 | $p2 = $this->factory->post->create(); |
| 270 | $p3 = $this->factory->post->create(); |
| 271 | |
| 272 | wp_set_object_terms( $p1, array( $c1 ), 'category' ); |
| 273 | wp_set_object_terms( $p2, array( $t1 ), 'post_tag' ); |
| 274 | wp_set_object_terms( $p3, array( $t1 ), 'post_tag' ); |
| 275 | wp_set_object_terms( $p3, array( $t2 ), 'post_tag' ); |
| 276 | |
| 277 | $found1 = $this->q->query( array( |
| 278 | 'fields' => 'ids', |
| 279 | 'orderby' => 'ID', |
| 280 | 'order' => 'ASC', |
| 281 | 'tax_query' => array( |
| 282 | array( |
| 283 | 'taxonomy' => 'post_tag', |
| 284 | 'operator' => 'EXISTS', |
| 285 | ), |
| 286 | ), |
| 287 | ) ); |
| 288 | |
| 289 | $this->assertSame( array( $p2, $p3 ), $found1 ); |
| 290 | } |