Changeset 42343 for trunk/tests/phpunit/tests/term/query.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/query.php
r42209 r42343 15 15 $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) ); 16 16 17 $q = new WP_Term_Query( array( 18 'taxonomy' => 'wptests_tax_2', 19 'fields' => 'ids', 20 'hide_empty' => false, 21 ) ); 17 $q = new WP_Term_Query( 18 array( 19 'taxonomy' => 'wptests_tax_2', 20 'fields' => 'ids', 21 'hide_empty' => false, 22 ) 23 ); 22 24 23 25 $this->assertEqualSets( array( $term_2 ), $q->terms ); … … 31 33 $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) ); 32 34 33 $q = new WP_Term_Query( array( 34 'taxonomy' => array( 'wptests_tax_2' ), 35 'fields' => 'ids', 36 'hide_empty' => false, 37 ) ); 35 $q = new WP_Term_Query( 36 array( 37 'taxonomy' => array( 'wptests_tax_2' ), 38 'fields' => 'ids', 39 'hide_empty' => false, 40 ) 41 ); 38 42 39 43 $this->assertEqualSets( array( $term_2 ), $q->terms ); … … 57 61 ); 58 62 59 $q = new WP_Term_Query( array( 60 'term_taxonomy_id' => 12345, 61 'fields' => 'ids', 62 'hide_empty' => false, 63 ) ); 63 $q = new WP_Term_Query( 64 array( 65 'term_taxonomy_id' => 12345, 66 'fields' => 'ids', 67 'hide_empty' => false, 68 ) 69 ); 64 70 65 71 $this->assertEqualSets( array( $terms[0] ), $q->terms ); … … 89 95 ); 90 96 91 $q = new WP_Term_Query( array( 92 'term_taxonomy_id' => array( 12345, 6789 ), 93 'fields' => 'ids', 94 'hide_empty' => false, 95 ) ); 97 $q = new WP_Term_Query( 98 array( 99 'term_taxonomy_id' => array( 12345, 6789 ), 100 'fields' => 'ids', 101 'hide_empty' => false, 102 ) 103 ); 96 104 97 105 $this->assertEqualSets( array( $terms[0], $terms[2] ), $q->terms ); … … 110 118 add_term_meta( $terms[2], 'foo', 100 ); 111 119 112 $q = new WP_Term_Query( array( 113 'taxonomy' => array( 'wptests_tax' ), 114 'fields' => 'ids', 115 'hide_empty' => false, 116 'meta_key' => 'foo', 117 'orderby' => 'meta_value_num', 118 ) ); 120 $q = new WP_Term_Query( 121 array( 122 'taxonomy' => array( 'wptests_tax' ), 123 'fields' => 'ids', 124 'hide_empty' => false, 125 'meta_key' => 'foo', 126 'orderby' => 'meta_value_num', 127 ) 128 ); 119 129 120 130 $found = array_map( 'intval', $q->terms ); … … 129 139 130 140 add_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) ); 131 $q = new WP_Term_Query( array( 132 'taxonomy' => array( 'wptests_tax' ), 133 'orderby' => 'name', 134 ) ); 141 $q = new WP_Term_Query( 142 array( 143 'taxonomy' => array( 'wptests_tax' ), 144 'orderby' => 'name', 145 ) 146 ); 135 147 remove_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) ); 136 148 … … 152 164 sort( $terms ); 153 165 154 $q = new WP_Term_Query( array( 155 'taxonomy' => 'wptests_tax', 156 'orderby' => 'term_order', 157 'fields' => 'ids', 158 'hide_empty' => false, 159 ) ); 166 $q = new WP_Term_Query( 167 array( 168 'taxonomy' => 'wptests_tax', 169 'orderby' => 'term_order', 170 'fields' => 'ids', 171 'hide_empty' => false, 172 ) 173 ); 160 174 161 175 $this->assertSame( $terms, $q->get_terms() ); … … 170 184 self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 171 185 172 $q1 = new WP_Term_Query( array( 173 'taxonomy' => 'wptests_tax_1', 174 'hide_empty' => false 175 ) ); 186 $q1 = new WP_Term_Query( 187 array( 188 'taxonomy' => 'wptests_tax_1', 189 'hide_empty' => false, 190 ) 191 ); 176 192 177 193 $this->assertNotEmpty( $q1->terms ); 178 194 179 $q2 = new WP_Term_Query( array( 180 'taxonomy' => 'wptests_tax_1', 181 'hide_empty' => false 182 ) ); 195 $q2 = new WP_Term_Query( 196 array( 197 'taxonomy' => 'wptests_tax_1', 198 'hide_empty' => false, 199 ) 200 ); 183 201 184 202 $this->assertNotEmpty( $q2->terms ); … … 195 213 $t2 = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax_1' ) ); 196 214 197 $query = new WP_Term_Query( array( 198 'include' => "{$t1->term_id},{$t2->term_id}", 199 'orderby' => 'include', 200 'hide_empty' => false, 201 ) ); 215 $query = new WP_Term_Query( 216 array( 217 'include' => "{$t1->term_id},{$t2->term_id}", 218 'orderby' => 'include', 219 'hide_empty' => false, 220 ) 221 ); 202 222 $terms = $query->get_terms(); 203 223 … … 216 236 wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' ); 217 237 218 $query = new WP_Term_Query( array( 219 'taxonomy' => 'wptests_tax_1', 220 'object_ids' => $p, 221 'fields' => 'ids', 222 ) ); 238 $query = new WP_Term_Query( 239 array( 240 'taxonomy' => 'wptests_tax_1', 241 'object_ids' => $p, 242 'fields' => 'ids', 243 ) 244 ); 223 245 224 246 $this->assertEqualSets( array( $t ), $query->terms ); … … 236 258 wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' ); 237 259 238 $query = new WP_Term_Query( array( 239 'taxonomy' => 'wptests_tax_1', 240 'object_ids' => array( $p ), 241 'fields' => 'ids', 242 ) ); 260 $query = new WP_Term_Query( 261 array( 262 'taxonomy' => 'wptests_tax_1', 263 'object_ids' => array( $p ), 264 'fields' => 'ids', 265 ) 266 ); 243 267 244 268 $this->assertEqualSets( array( $t ), $query->terms ); … … 251 275 register_taxonomy( 'wptests_tax_1', 'post' ); 252 276 $posts = self::factory()->post->create_many( 2 ); 253 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );277 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 254 278 255 279 foreach ( $posts as $p ) { … … 257 281 } 258 282 259 $query = new WP_Term_Query( array( 260 'taxonomy' => 'wptests_tax_1', 261 'object_ids' => $posts, 262 'fields' => 'all', 263 ) ); 283 $query = new WP_Term_Query( 284 array( 285 'taxonomy' => 'wptests_tax_1', 286 'object_ids' => $posts, 287 'fields' => 'all', 288 ) 289 ); 264 290 265 291 $this->assertSame( 1, count( $query->terms ) ); … … 273 299 register_taxonomy( 'wptests_tax_1', 'post' ); 274 300 $posts = self::factory()->post->create_many( 2 ); 275 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );301 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 276 302 277 303 foreach ( $posts as $p ) { … … 279 305 } 280 306 281 $query = new WP_Term_Query( array( 282 'taxonomy' => 'wptests_tax_1', 283 'object_ids' => $posts, 284 'fields' => 'all_with_object_id', 285 ) ); 307 $query = new WP_Term_Query( 308 array( 309 'taxonomy' => 'wptests_tax_1', 310 'object_ids' => $posts, 311 'fields' => 'all_with_object_id', 312 ) 313 ); 286 314 287 315 $this->assertSame( 2, count( $query->terms ) ); … … 298 326 register_taxonomy( 'wptests_tax_1', 'post' ); 299 327 300 $p = self::factory()->post->create();328 $p = self::factory()->post->create(); 301 329 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) ); 302 330 303 331 wp_set_object_terms( $p, array( $terms[0] ), 'wptests_tax_1' ); 304 332 305 $query = new WP_Term_Query( array( 306 'taxonomy' => 'wptests_tax_1', 307 'object_ids' => $p, 308 'fields' => 'ids', 309 ) ); 333 $query = new WP_Term_Query( 334 array( 335 'taxonomy' => 'wptests_tax_1', 336 'object_ids' => $p, 337 'fields' => 'ids', 338 ) 339 ); 310 340 $found = $query->get_terms(); 311 341 … … 314 344 wp_set_object_terms( $p, array( $terms[1] ), 'wptests_tax_1' ); 315 345 316 $query = new WP_Term_Query( array( 317 'taxonomy' => 'wptests_tax_1', 318 'object_ids' => $p, 319 'fields' => 'ids', 320 ) ); 346 $query = new WP_Term_Query( 347 array( 348 'taxonomy' => 'wptests_tax_1', 349 'object_ids' => $p, 350 'fields' => 'ids', 351 ) 352 ); 321 353 $found = $query->get_terms(); 322 354 … … 335 367 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) ); 336 368 337 $query = new WP_Term_Query( array( 338 'taxonomy' => 'wptests_tax_1', 339 'fields' => 'count', 340 'hide_empty' => false, 341 ) ); 369 $query = new WP_Term_Query( 370 array( 371 'taxonomy' => 'wptests_tax_1', 372 'fields' => 'count', 373 'hide_empty' => false, 374 ) 375 ); 342 376 $count = $query->get_terms(); 343 377 $this->assertEquals( 2, $count ); … … 345 379 $num_queries = $wpdb->num_queries; 346 380 347 $query = new WP_Term_Query( array( 348 'taxonomy' => 'wptests_tax_1', 349 'fields' => 'count', 350 'hide_empty' => false, 351 ) ); 381 $query = new WP_Term_Query( 382 array( 383 'taxonomy' => 'wptests_tax_1', 384 'fields' => 'count', 385 'hide_empty' => false, 386 ) 387 ); 352 388 $count = $query->get_terms(); 353 389 $this->assertEquals( 2, $count ); … … 364 400 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) ); 365 401 366 $query = new WP_Term_Query( array( 367 'taxonomy' => 'wptests_tax_1', 368 'fields' => 'count', 369 'hide_empty' => false, 370 ) ); 402 $query = new WP_Term_Query( 403 array( 404 'taxonomy' => 'wptests_tax_1', 405 'fields' => 'count', 406 'hide_empty' => false, 407 ) 408 ); 371 409 $count = $query->get_terms(); 372 410 $this->assertEquals( 2, $count ); … … 374 412 wp_delete_term( $terms[0], 'wptests_tax_1' ); 375 413 376 $query = new WP_Term_Query( array( 377 'taxonomy' => 'wptests_tax_1', 378 'fields' => 'count', 379 'hide_empty' => false, 380 ) ); 414 $query = new WP_Term_Query( 415 array( 416 'taxonomy' => 'wptests_tax_1', 417 'fields' => 'count', 418 'hide_empty' => false, 419 ) 420 ); 381 421 $count = $query->get_terms(); 382 422 $this->assertEquals( 1, $count ); … … 387 427 */ 388 428 public function test_get_the_terms_should_respect_taxonomy_orderby() { 389 register_taxonomy( 'wptests_tax', 'post', array( 390 'sort' => true, 391 'args' => array( 392 'orderby' => 'term_order', 393 ), 394 ) ); 395 $term_ids = self::factory()->term->create_many( 2, array( 396 'taxonomy' => 'wptests_tax', 397 ) ); 398 $post_id = self::factory()->post->create(); 429 register_taxonomy( 430 'wptests_tax', 'post', array( 431 'sort' => true, 432 'args' => array( 433 'orderby' => 'term_order', 434 ), 435 ) 436 ); 437 $term_ids = self::factory()->term->create_many( 438 2, array( 439 'taxonomy' => 'wptests_tax', 440 ) 441 ); 442 $post_id = self::factory()->post->create(); 399 443 wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' ); 400 444 $terms = get_the_terms( $post_id, 'wptests_tax' ); … … 410 454 */ 411 455 public function test_wp_get_object_terms_should_respect_taxonomy_orderby() { 412 register_taxonomy( 'wptests_tax', 'post', array( 413 'sort' => true, 414 'args' => array( 415 'orderby' => 'term_order', 416 ), 417 ) ); 418 $term_ids = self::factory()->term->create_many( 2, array( 419 'taxonomy' => 'wptests_tax', 420 ) ); 421 $post_id = self::factory()->post->create(); 456 register_taxonomy( 457 'wptests_tax', 'post', array( 458 'sort' => true, 459 'args' => array( 460 'orderby' => 'term_order', 461 ), 462 ) 463 ); 464 $term_ids = self::factory()->term->create_many( 465 2, array( 466 'taxonomy' => 'wptests_tax', 467 ) 468 ); 469 $post_id = self::factory()->post->create(); 422 470 wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' ); 423 471 $terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) ); … … 435 483 register_post_type( 'wptests_pt' ); 436 484 register_taxonomy( 'wptests_tax', 'wptests_pt' ); 437 $t1 = self::factory()->term->create( array( 438 'taxonomy' => 'wptests_tax', 439 'name' => 'foo', 440 'slug' => 'bar', 441 ) ); 442 $t2 = self::factory()->term->create( array( 443 'taxonomy' => 'wptests_tax', 444 'name' => 'bar', 445 'slug' => 'foo', 446 ) ); 447 448 $p = self::factory()->post->create( array( 449 'post_type' => 'wptests_pt', 450 ) ); 485 $t1 = self::factory()->term->create( 486 array( 487 'taxonomy' => 'wptests_tax', 488 'name' => 'foo', 489 'slug' => 'bar', 490 ) 491 ); 492 $t2 = self::factory()->term->create( 493 array( 494 'taxonomy' => 'wptests_tax', 495 'name' => 'bar', 496 'slug' => 'foo', 497 ) 498 ); 499 500 $p = self::factory()->post->create( 501 array( 502 'post_type' => 'wptests_pt', 503 ) 504 ); 451 505 452 506 wp_set_object_terms( $p, array( $t1, $t2 ), 'wptests_tax' ); 453 507 454 $expected = wp_get_post_terms( $p, 'wptests_tax', array( 455 'fields' => 'ids', 456 ) ); 457 458 $found1 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array( 459 'fields' => 'id=>parent', 460 ) ) ); 461 462 $found2 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array( 463 'fields' => 'id=>slug', 464 ) ) ); 465 466 $found3 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array( 467 'fields' => 'id=>name', 468 ) ) ); 508 $expected = wp_get_post_terms( 509 $p, 'wptests_tax', array( 510 'fields' => 'ids', 511 ) 512 ); 513 514 $found1 = array_keys( 515 wp_get_object_terms( 516 $p, 'wptests_tax', array( 517 'fields' => 'id=>parent', 518 ) 519 ) 520 ); 521 522 $found2 = array_keys( 523 wp_get_object_terms( 524 $p, 'wptests_tax', array( 525 'fields' => 'id=>slug', 526 ) 527 ) 528 ); 529 530 $found3 = array_keys( 531 wp_get_object_terms( 532 $p, 'wptests_tax', array( 533 'fields' => 'id=>name', 534 ) 535 ) 536 ); 469 537 470 538 $this->assertSame( $expected, $found1 ); … … 482 550 register_taxonomy( 'wptests_tax', 'post' ); 483 551 484 $term_id = self::factory()->term->create( array( 485 'taxonomy' => 'wptests_tax', 486 ) ); 552 $term_id = self::factory()->term->create( 553 array( 554 'taxonomy' => 'wptests_tax', 555 ) 556 ); 487 557 wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' ); 488 558 489 $q = new WP_Term_Query();559 $q = new WP_Term_Query(); 490 560 $args = array( 491 561 'taxonomy' => 'wptests_tax', … … 505 575 register_taxonomy( 'wptests_tax', 'post' ); 506 576 507 $term_id = self::factory()->term->create( array( 508 'taxonomy' => 'wptests_tax', 509 ) ); 577 $term_id = self::factory()->term->create( 578 array( 579 'taxonomy' => 'wptests_tax', 580 ) 581 ); 510 582 wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' ); 511 583 512 $q = new WP_Term_Query();584 $q = new WP_Term_Query(); 513 585 $args = array( 514 586 'taxonomy' => 'wptests_tax', … … 528 600 register_taxonomy( 'wptests_tax', 'post' ); 529 601 530 $term_id = self::factory()->term->create( array( 531 'taxonomy' => 'wptests_tax', 532 ) ); 602 $term_id = self::factory()->term->create( 603 array( 604 'taxonomy' => 'wptests_tax', 605 ) 606 ); 533 607 wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' ); 534 608 535 $q = new WP_Term_Query( array( 536 'taxonomy' => 'wptests_tax', 537 'parent' => $term_id, 538 ) ); 609 $q = new WP_Term_Query( 610 array( 611 'taxonomy' => 'wptests_tax', 612 'parent' => $term_id, 613 ) 614 ); 539 615 $this->assertSame( array(), $q->terms ); 540 616 }
Note: See TracChangeset
for help on using the changeset viewer.