Changeset 42343 for trunk/tests/phpunit/tests/term/getTerms.php
- Timestamp:
- 11/30/2017 11:09:33 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/term/getTerms.php (modified) (105 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/getTerms.php
r40293 r42343 27 27 wp_set_post_terms( $post, array( $term1, $term2 ), 'wptests_tax' ); 28 28 29 $found = get_terms( array( 30 'meta_key' => 'somekey', 31 'meta_value' => 'thevalue', 32 ) ); 29 $found = get_terms( 30 array( 31 'meta_key' => 'somekey', 32 'meta_value' => 'thevalue', 33 ) 34 ); 33 35 34 36 $this->assertEqualSets( array( $term1 ), wp_list_pluck( $found, 'term_id' ) ); … … 42 44 $term = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); 43 45 44 $found = get_terms( array( 45 'taxonomy' => 'wptests_tax', 46 'hide_empty' => false, 47 'fields' => 'ids', 48 'update_term_meta_cache' => false, 49 ) ); 46 $found = get_terms( 47 array( 48 'taxonomy' => 'wptests_tax', 49 'hide_empty' => false, 50 'fields' => 'ids', 51 'update_term_meta_cache' => false, 52 ) 53 ); 50 54 51 55 $this->assertEqualSets( array( $term ), $found ); … … 87 91 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); 88 92 89 $found = get_terms( array( 90 'hide_empty' => false, 91 'fields' => 'ids', 92 'update_term_meta_cache' => false, 93 ) ); 93 $found = get_terms( 94 array( 95 'hide_empty' => false, 96 'fields' => 'ids', 97 'update_term_meta_cache' => false, 98 ) 99 ); 94 100 95 101 // There may be other terms lying around, so don't do an exact match. … … 133 139 134 140 // Prime cache 135 $terms = get_terms( 'post_tag' );136 $time1 = wp_cache_get( 'last_changed', 'terms' );141 $terms = get_terms( 'post_tag' ); 142 $time1 = wp_cache_get( 'last_changed', 'terms' ); 137 143 $num_queries = $wpdb->num_queries; 138 144 … … 161 167 162 168 // Prime cache 163 $terms = get_terms( 'post_tag' );164 $time1 = wp_cache_get( 'last_changed', 'terms' );169 $terms = get_terms( 'post_tag' ); 170 $time1 = wp_cache_get( 'last_changed', 'terms' ); 165 171 $num_queries = $wpdb->num_queries; 166 172 … … 168 174 wp_delete_term( $terms[0]->term_id, 'post_tag' ); 169 175 170 $num_queries = $wpdb->num_queries;176 $num_queries = $wpdb->num_queries; 171 177 $this->assertNotEquals( $time1, $time2 = wp_cache_get( 'last_changed', 'terms' ) ); 172 178 … … 193 199 function test_get_terms_should_allow_arbitrary_indexed_taxonomies_array() { 194 200 $term_id = self::factory()->tag->create(); 195 $terms = get_terms( array( '111' => 'post_tag' ), array( 'hide_empty' => false ) );201 $terms = get_terms( array( '111' => 'post_tag' ), array( 'hide_empty' => false ) ); 196 202 $this->assertEquals( $term_id, reset( $terms )->term_id ); 197 203 } … … 201 207 */ 202 208 function test_get_terms_fields() { 203 $term_id1 = self::factory()->tag->create( array( 'slug' => 'woo', 'name' => 'WOO!' ) ); 204 $term_id2 = self::factory()->tag->create( array( 'slug' => 'hoo', 'name' => 'HOO!', 'parent' => $term_id1 ) ); 205 206 $terms_id_parent = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'id=>parent' ) ); 207 $this->assertEquals( array( 208 $term_id1 => 0, 209 $term_id2 => $term_id1 210 ), $terms_id_parent ); 211 212 $terms_ids = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'ids' ) ); 209 $term_id1 = self::factory()->tag->create( 210 array( 211 'slug' => 'woo', 212 'name' => 'WOO!', 213 ) 214 ); 215 $term_id2 = self::factory()->tag->create( 216 array( 217 'slug' => 'hoo', 218 'name' => 'HOO!', 219 'parent' => $term_id1, 220 ) 221 ); 222 223 $terms_id_parent = get_terms( 224 'post_tag', array( 225 'hide_empty' => false, 226 'fields' => 'id=>parent', 227 ) 228 ); 229 $this->assertEquals( 230 array( 231 $term_id1 => 0, 232 $term_id2 => $term_id1, 233 ), $terms_id_parent 234 ); 235 236 $terms_ids = get_terms( 237 'post_tag', array( 238 'hide_empty' => false, 239 'fields' => 'ids', 240 ) 241 ); 213 242 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms_ids ); 214 243 215 $terms_name = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'names' ) ); 244 $terms_name = get_terms( 245 'post_tag', array( 246 'hide_empty' => false, 247 'fields' => 'names', 248 ) 249 ); 216 250 $this->assertEqualSets( array( 'WOO!', 'HOO!' ), $terms_name ); 217 251 218 $terms_id_name = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'id=>name' ) ); 219 $this->assertEquals( array( 220 $term_id1 => 'WOO!', 221 $term_id2 => 'HOO!', 222 ), $terms_id_name ); 223 224 $terms_id_slug = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'id=>slug' ) ); 225 $this->assertEquals( array( 226 $term_id1 => 'woo', 227 $term_id2 => 'hoo' 228 ), $terms_id_slug ); 229 } 230 231 /** 252 $terms_id_name = get_terms( 253 'post_tag', array( 254 'hide_empty' => false, 255 'fields' => 'id=>name', 256 ) 257 ); 258 $this->assertEquals( 259 array( 260 $term_id1 => 'WOO!', 261 $term_id2 => 'HOO!', 262 ), $terms_id_name 263 ); 264 265 $terms_id_slug = get_terms( 266 'post_tag', array( 267 'hide_empty' => false, 268 'fields' => 'id=>slug', 269 ) 270 ); 271 $this->assertEquals( 272 array( 273 $term_id1 => 'woo', 274 $term_id2 => 'hoo', 275 ), $terms_id_slug 276 ); 277 } 278 279 /** 232 280 * @ticket 11823 233 */281 */ 234 282 function test_get_terms_include_exclude() { 235 283 global $wpdb; 236 284 237 $term_id1 = self::factory()->tag->create(); 238 $term_id2 = self::factory()->tag->create(); 239 $inc_terms = get_terms( 'post_tag', array( 240 'include' => array( $term_id1, $term_id2 ), 241 'hide_empty' => false 242 ) ); 285 $term_id1 = self::factory()->tag->create(); 286 $term_id2 = self::factory()->tag->create(); 287 $inc_terms = get_terms( 288 'post_tag', array( 289 'include' => array( $term_id1, $term_id2 ), 290 'hide_empty' => false, 291 ) 292 ); 243 293 $this->assertEquals( array( $term_id1, $term_id2 ), wp_list_pluck( $inc_terms, 'term_id' ) ); 244 294 245 $exc_terms = get_terms( 'post_tag', array( 246 'exclude' => array( $term_id1, $term_id2 ), 247 'hide_empty' => false 248 ) ); 295 $exc_terms = get_terms( 296 'post_tag', array( 297 'exclude' => array( $term_id1, $term_id2 ), 298 'hide_empty' => false, 299 ) 300 ); 249 301 $this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) ); 250 302 251 303 // These should not generate query errors. 252 get_terms( 'post_tag', array( 'exclude' => array( 0 ), 'hide_empty' => false ) ); 304 get_terms( 305 'post_tag', array( 306 'exclude' => array( 0 ), 307 'hide_empty' => false, 308 ) 309 ); 253 310 $this->assertEmpty( $wpdb->last_error ); 254 311 255 get_terms( 'post_tag', array( 'exclude' => array( 'unexpected-string' ), 'hide_empty' => false ) ); 312 get_terms( 313 'post_tag', array( 314 'exclude' => array( 'unexpected-string' ), 315 'hide_empty' => false, 316 ) 317 ); 256 318 $this->assertEmpty( $wpdb->last_error ); 257 319 258 get_terms( 'post_tag', array( 'include' => array( 'unexpected-string' ), 'hide_empty' => false ) ); 320 get_terms( 321 'post_tag', array( 322 'include' => array( 'unexpected-string' ), 323 'hide_empty' => false, 324 ) 325 ); 259 326 $this->assertEmpty( $wpdb->last_error ); 260 327 } … … 266 333 register_taxonomy( 'wptests_tax', 'post' ); 267 334 268 $terms = self::factory()->term->create_many( 2, array( 269 'taxonomy' => 'wptests_tax', 270 ) ); 271 272 $found = get_terms( 'wptests_tax', array( 273 'taxonomy' => 'wptests_tax', 274 'hide_empty' => false, 275 'exclude_tree' => array( $terms[0] ), 276 'hierarchical' => true, 277 ) ); 335 $terms = self::factory()->term->create_many( 336 2, array( 337 'taxonomy' => 'wptests_tax', 338 ) 339 ); 340 341 $found = get_terms( 342 'wptests_tax', array( 343 'taxonomy' => 'wptests_tax', 344 'hide_empty' => false, 345 'exclude_tree' => array( $terms[0] ), 346 'hierarchical' => true, 347 ) 348 ); 278 349 279 350 $this->assertEquals( array( $terms[1] ), wp_list_pluck( $found, 'term_id' ) ); … … 289 360 $term_id_uncategorized = get_option( 'default_category' ); 290 361 291 $term_id1 = self::factory()->category->create();362 $term_id1 = self::factory()->category->create(); 292 363 $term_id11 = self::factory()->category->create( array( 'parent' => $term_id1 ) ); 293 $term_id2 = self::factory()->category->create();364 $term_id2 = self::factory()->category->create(); 294 365 $term_id22 = self::factory()->category->create( array( 'parent' => $term_id2 ) ); 295 366 296 $terms = get_terms( 'category', array( 297 'exclude' => $term_id_uncategorized, 298 'fields' => 'ids', 299 'hide_empty' => false, 300 ) ); 367 $terms = get_terms( 368 'category', array( 369 'exclude' => $term_id_uncategorized, 370 'fields' => 'ids', 371 'hide_empty' => false, 372 ) 373 ); 301 374 $this->assertEquals( array( $term_id1, $term_id11, $term_id2, $term_id22 ), $terms ); 302 375 303 $terms = get_terms( 'category', array( 304 'fields' => 'ids', 305 'exclude_tree' => "$term_id1,$term_id_uncategorized", 306 'hide_empty' => false, 307 ) ); 376 $terms = get_terms( 377 'category', array( 378 'fields' => 'ids', 379 'exclude_tree' => "$term_id1,$term_id_uncategorized", 380 'hide_empty' => false, 381 ) 382 ); 308 383 309 384 $this->assertEquals( array( $term_id2, $term_id22 ), $terms ); … … 319 394 $term_id3 = self::factory()->tag->create( array( 'name' => 'Foo' ) ); 320 395 321 $terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'search' => 'bur', 'fields' => 'ids' ) ); 396 $terms = get_terms( 397 'post_tag', array( 398 'hide_empty' => false, 399 'search' => 'bur', 400 'fields' => 'ids', 401 ) 402 ); 322 403 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms ); 323 404 } … … 327 408 */ 328 409 function test_get_terms_like() { 329 $term_id1 = self::factory()->tag->create( array( 'name' => 'burrito', 'description' => 'This is a burrito.' ) ); 330 $term_id2 = self::factory()->tag->create( array( 'name' => 'taco', 'description' => 'Burning man.' ) ); 331 332 $terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'bur', 'fields' => 'ids' ) ); 410 $term_id1 = self::factory()->tag->create( 411 array( 412 'name' => 'burrito', 413 'description' => 'This is a burrito.', 414 ) 415 ); 416 $term_id2 = self::factory()->tag->create( 417 array( 418 'name' => 'taco', 419 'description' => 'Burning man.', 420 ) 421 ); 422 423 $terms = get_terms( 424 'post_tag', array( 425 'hide_empty' => false, 426 'name__like' => 'bur', 427 'fields' => 'ids', 428 ) 429 ); 333 430 $this->assertEqualSets( array( $term_id1 ), $terms ); 334 431 335 $terms2 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'bur', 'fields' => 'ids' ) ); 432 $terms2 = get_terms( 433 'post_tag', array( 434 'hide_empty' => false, 435 'description__like' => 'bur', 436 'fields' => 'ids', 437 ) 438 ); 336 439 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms2 ); 337 440 338 $terms3 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'Bur', 'fields' => 'ids' ) ); 441 $terms3 = get_terms( 442 'post_tag', array( 443 'hide_empty' => false, 444 'name__like' => 'Bur', 445 'fields' => 'ids', 446 ) 447 ); 339 448 $this->assertEqualSets( array( $term_id1 ), $terms3 ); 340 449 341 $terms4 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'Bur', 'fields' => 'ids' ) ); 450 $terms4 = get_terms( 451 'post_tag', array( 452 'hide_empty' => false, 453 'description__like' => 'Bur', 454 'fields' => 'ids', 455 ) 456 ); 342 457 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms4 ); 343 458 344 $terms5 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'ENCHILADA', 'fields' => 'ids' ) ); 459 $terms5 = get_terms( 460 'post_tag', array( 461 'hide_empty' => false, 462 'name__like' => 'ENCHILADA', 463 'fields' => 'ids', 464 ) 465 ); 345 466 $this->assertEmpty( $terms5 ); 346 467 347 $terms6 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'ENCHILADA', 'fields' => 'ids' ) ); 468 $terms6 = get_terms( 469 'post_tag', array( 470 'hide_empty' => false, 471 'description__like' => 'ENCHILADA', 472 'fields' => 'ids', 473 ) 474 ); 348 475 $this->assertEmpty( $terms6 ); 349 476 350 $terms7 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'o', 'fields' => 'ids' ) ); 477 $terms7 = get_terms( 478 'post_tag', array( 479 'hide_empty' => false, 480 'name__like' => 'o', 481 'fields' => 'ids', 482 ) 483 ); 351 484 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms7 ); 352 485 353 $terms8 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => '.', 'fields' => 'ids' ) ); 486 $terms8 = get_terms( 487 'post_tag', array( 488 'hide_empty' => false, 489 'description__like' => '.', 490 'fields' => 'ids', 491 ) 492 ); 354 493 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms8 ); 355 494 } … … 362 501 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 363 502 364 $cheese = self::factory()->term->create( array( 'name' => 'Cheese', 'taxonomy' => $tax ) ); 365 366 $cheddar = self::factory()->term->create( array( 'name' => 'Cheddar', 'parent' => $cheese, 'taxonomy' => $tax ) ); 503 $cheese = self::factory()->term->create( 504 array( 505 'name' => 'Cheese', 506 'taxonomy' => $tax, 507 ) 508 ); 509 510 $cheddar = self::factory()->term->create( 511 array( 512 'name' => 'Cheddar', 513 'parent' => $cheese, 514 'taxonomy' => $tax, 515 ) 516 ); 367 517 368 518 $post_ids = self::factory()->post->create_many( 2 ); … … 373 523 $this->assertEquals( 2, $term->count ); 374 524 375 $brie = self::factory()->term->create( array( 'name' => 'Brie', 'parent' => $cheese, 'taxonomy' => $tax ) ); 525 $brie = self::factory()->term->create( 526 array( 527 'name' => 'Brie', 528 'parent' => $cheese, 529 'taxonomy' => $tax, 530 ) 531 ); 376 532 $post_id = self::factory()->post->create(); 377 533 wp_set_post_terms( $post_id, $brie, $tax ); … … 379 535 $this->assertEquals( 1, $term->count ); 380 536 381 $crackers = self::factory()->term->create( array( 'name' => 'Crackers', 'taxonomy' => $tax ) ); 382 383 $butter = self::factory()->term->create( array( 'name' => 'Butter', 'parent' => $crackers, 'taxonomy' => $tax ) ); 537 $crackers = self::factory()->term->create( 538 array( 539 'name' => 'Crackers', 540 'taxonomy' => $tax, 541 ) 542 ); 543 544 $butter = self::factory()->term->create( 545 array( 546 'name' => 'Butter', 547 'parent' => $crackers, 548 'taxonomy' => $tax, 549 ) 550 ); 384 551 $post_ids = self::factory()->post->create_many( 1 ); 385 552 foreach ( $post_ids as $id ) { … … 389 556 $this->assertEquals( 1, $term->count ); 390 557 391 $multigrain = self::factory()->term->create( array( 'name' => 'Multigrain', 'parent' => $crackers, 'taxonomy' => $tax ) ); 392 $post_ids = self::factory()->post->create_many( 1 ); 558 $multigrain = self::factory()->term->create( 559 array( 560 'name' => 'Multigrain', 561 'parent' => $crackers, 562 'taxonomy' => $tax, 563 ) 564 ); 565 $post_ids = self::factory()->post->create_many( 1 ); 393 566 foreach ( $post_ids as $id ) { 394 567 wp_set_post_terms( $id, $multigrain, $tax ); … … 397 570 $this->assertEquals( 1, $term->count ); 398 571 399 $fruit = self::factory()->term->create( array( 'name' => 'Fruit', 'taxonomy' => $tax ) ); 400 $cranberries = self::factory()->term->create( array( 'name' => 'Cranberries', 'parent' => $fruit, 'taxonomy' => $tax ) ); 401 402 $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) ); 572 $fruit = self::factory()->term->create( 573 array( 574 'name' => 'Fruit', 575 'taxonomy' => $tax, 576 ) 577 ); 578 $cranberries = self::factory()->term->create( 579 array( 580 'name' => 'Cranberries', 581 'parent' => $fruit, 582 'taxonomy' => $tax, 583 ) 584 ); 585 586 $terms = get_terms( 587 $tax, array( 588 'parent' => 0, 589 'cache_domain' => $tax, 590 ) 591 ); 403 592 $this->assertEquals( 2, count( $terms ) ); 404 593 $this->assertEquals( wp_list_pluck( $terms, 'name' ), array( 'Cheese', 'Crackers' ) ); … … 412 601 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 413 602 414 $cheese = self::factory()->term->create( array( 'name' => 'Cheese', 'taxonomy' => $tax ) ); 415 $cheddar = self::factory()->term->create( array( 'name' => 'Cheddar', 'parent' => $cheese, 'taxonomy' => $tax ) ); 416 $spread = self::factory()->term->create( array( 'name' => 'Spread', 'parent' => $cheddar, 'taxonomy' => $tax ) ); 603 $cheese = self::factory()->term->create( 604 array( 605 'name' => 'Cheese', 606 'taxonomy' => $tax, 607 ) 608 ); 609 $cheddar = self::factory()->term->create( 610 array( 611 'name' => 'Cheddar', 612 'parent' => $cheese, 613 'taxonomy' => $tax, 614 ) 615 ); 616 $spread = self::factory()->term->create( 617 array( 618 'name' => 'Spread', 619 'parent' => $cheddar, 620 'taxonomy' => $tax, 621 ) 622 ); 417 623 $post_id = self::factory()->post->create(); 418 624 wp_set_post_terms( $post_id, $spread, $tax ); … … 420 626 $this->assertEquals( 1, $term->count ); 421 627 422 $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) ); 628 $terms = get_terms( 629 $tax, array( 630 'parent' => 0, 631 'cache_domain' => $tax, 632 ) 633 ); 423 634 $this->assertEquals( 1, count( $terms ) ); 424 635 $this->assertEquals( array( 'Cheese' ), wp_list_pluck( $terms, 'name' ) ); … … 434 645 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 435 646 $parent = 0; 436 $t = array();647 $t = array(); 437 648 foreach ( range( 1, 7 ) as $depth ) { 438 $t[$depth] = self::factory()->term->create( array( 'name' => 'term' . $depth, 'taxonomy' => $tax, 'parent' => $parent ) ); 439 $parent = $t[$depth]; 649 $t[ $depth ] = self::factory()->term->create( 650 array( 651 'name' => 'term' . $depth, 652 'taxonomy' => $tax, 653 'parent' => $parent, 654 ) 655 ); 656 $parent = $t[ $depth ]; 440 657 } 441 658 $post_id = self::factory()->post->create(); … … 444 661 $this->assertEquals( 1, $term->count ); 445 662 446 $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) ); 663 $terms = get_terms( 664 $tax, array( 665 'parent' => 0, 666 'cache_domain' => $tax, 667 ) 668 ); 447 669 $this->assertEquals( 1, count( $terms ) ); 448 670 $this->assertEquals( array( 'term1' ), wp_list_pluck( $terms, 'name' ) ); … … 456 678 function test_get_terms_child_of() { 457 679 $parent = self::factory()->category->create(); 458 $child = self::factory()->category->create( array( 'parent' => $parent ) ); 459 460 $terms = get_terms( 'category', array( 'child_of' => $parent, 'hide_empty' => false ) ); 680 $child = self::factory()->category->create( array( 'parent' => $parent ) ); 681 682 $terms = get_terms( 683 'category', array( 684 'child_of' => $parent, 685 'hide_empty' => false, 686 ) 687 ); 461 688 $this->assertEquals( 1, count( $terms ) ); 462 689 } … … 468 695 global $wpdb; 469 696 470 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ,) );697 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 471 698 472 699 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); … … 474 701 $num_queries = $wpdb->num_queries; 475 702 476 $found = get_terms( 'wptests_tax', array( 477 'hide_empty' => false, 478 'child_of' => $terms[0], 479 ) ); 703 $found = get_terms( 704 'wptests_tax', array( 705 'hide_empty' => false, 706 'child_of' => $terms[0], 707 ) 708 ); 480 709 481 710 $this->assertEmpty( $found ); … … 492 721 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); 493 722 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); 494 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t2 ) ); 495 496 $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array( 497 'fields' => 'ids', 498 'hide_empty' => false, 499 'child_of' => $t2, 500 ) ); 723 $t3 = self::factory()->term->create( 724 array( 725 'taxonomy' => 'wptests_tax2', 726 'parent' => $t2, 727 ) 728 ); 729 730 $found = get_terms( 731 array( 'wptests_tax1', 'wptests_tax2' ), array( 732 'fields' => 'ids', 733 'hide_empty' => false, 734 'child_of' => $t2, 735 ) 736 ); 501 737 502 738 $this->assertEqualSets( array( $t3 ), $found ); … … 563 799 $t2 = self::factory()->tag->create( array( 'slug' => 'bar' ) ); 564 800 565 $found = get_terms( 'post_tag', array( 566 'hide_empty' => false, 567 'fields' => 'ids', 568 'slug' => 'foo', 569 ) ); 801 $found = get_terms( 802 'post_tag', array( 803 'hide_empty' => false, 804 'fields' => 'ids', 805 'slug' => 'foo', 806 ) 807 ); 570 808 571 809 $this->assertEquals( array( $t1 ), $found ); … … 580 818 $t3 = self::factory()->tag->create( array( 'slug' => 'barry' ) ); 581 819 582 $found = get_terms( 'post_tag', array( 583 'hide_empty' => false, 584 'fields' => 'ids', 585 'slug' => array( 'foo', 'barry' ) 586 ) ); 820 $found = get_terms( 821 'post_tag', array( 822 'hide_empty' => false, 823 'fields' => 'ids', 824 'slug' => array( 'foo', 'barry' ), 825 ) 826 ); 587 827 588 828 $this->assertEquals( array( $t1, $t3 ), $found ); … … 596 836 $t2 = self::factory()->tag->create( array( 'name' => 'Bar' ) ); 597 837 598 $found = get_terms( 'post_tag', array( 599 'hide_empty' => false, 600 'fields' => 'ids', 601 'name' => 'Foo', 602 ) ); 838 $found = get_terms( 839 'post_tag', array( 840 'hide_empty' => false, 841 'fields' => 'ids', 842 'name' => 'Foo', 843 ) 844 ); 603 845 604 846 $this->assertEquals( array( $t1 ), $found ); … … 613 855 $t3 = self::factory()->tag->create( array( 'name' => 'Barry' ) ); 614 856 615 $found = get_terms( 'post_tag', array( 616 'hide_empty' => false, 617 'fields' => 'ids', 618 'name' => array( 'Foo', 'Barry' ) 619 ) ); 857 $found = get_terms( 858 'post_tag', array( 859 'hide_empty' => false, 860 'fields' => 'ids', 861 'name' => array( 'Foo', 'Barry' ), 862 ) 863 ); 620 864 621 865 $this->assertEqualSets( array( $t3, $t1 ), $found ); … … 628 872 register_taxonomy( 'wptests_tax', 'post' ); 629 873 630 $t = self::factory()->term->create( array( 631 'taxonomy' => 'wptests_tax', 632 'name' => 'Foo & Bar', 633 'slug' => 'foo-and-bar', 634 ) ); 635 636 $found = get_terms( 'wptests_tax', array( 637 'hide_empty' => false, 638 'fields' => 'ids', 639 'name' => 'Foo & Bar', 640 ) ); 874 $t = self::factory()->term->create( 875 array( 876 'taxonomy' => 'wptests_tax', 877 'name' => 'Foo & Bar', 878 'slug' => 'foo-and-bar', 879 ) 880 ); 881 882 $found = get_terms( 883 'wptests_tax', array( 884 'hide_empty' => false, 885 'fields' => 'ids', 886 'name' => 'Foo & Bar', 887 ) 888 ); 641 889 $this->assertEqualSets( array( $t ), $found ); 642 890 643 891 // array format. 644 $found = get_terms( 'wptests_tax', array( 645 'hide_empty' => false, 646 'fields' => 'ids', 647 'name' => array( 'Foo & Bar' ), 648 ) ); 892 $found = get_terms( 893 'wptests_tax', array( 894 'hide_empty' => false, 895 'fields' => 'ids', 896 'name' => array( 'Foo & Bar' ), 897 ) 898 ); 649 899 $this->assertEqualSets( array( $t ), $found ); 650 900 } … … 658 908 $name = "Foo'Bar"; 659 909 660 $t = self::factory()->term->create( array( 661 'taxonomy' => 'wptests_tax', 662 'name' => $name, 663 ) ); 910 $t = self::factory()->term->create( 911 array( 912 'taxonomy' => 'wptests_tax', 913 'name' => $name, 914 ) 915 ); 664 916 665 917 $term = get_term( $t, 'wptests_tax' ); … … 667 919 $this->assertSame( $name, $term->name ); 668 920 669 $found = get_terms( 'wptests_tax', array( 670 'hide_empty' => false, 671 'fields' => 'ids', 672 'name' => $name, 673 ) ); 921 $found = get_terms( 922 'wptests_tax', array( 923 'hide_empty' => false, 924 'fields' => 'ids', 925 'name' => $name, 926 ) 927 ); 674 928 675 929 $this->assertEqualSets( array( $t ), $found ); … … 683 937 $flat_tax = 'countries'; 684 938 register_taxonomy( $flat_tax, 'post', array( 'hierarchical' => false ) ); 685 $australia = self::factory()->term->create( array( 'name' => 'Australia', 'taxonomy' => $flat_tax ) ); 686 $china = self::factory()->term->create( array( 'name' => 'China', 'taxonomy' => $flat_tax ) ); 687 $tanzania = self::factory()->term->create( array( 'name' => 'Tanzania', 'taxonomy' => $flat_tax ) ); 688 689 $terms = get_terms( $flat_tax, array( 690 'childless' => true, 691 'hide_empty' => false, 692 'fields' => 'ids', 693 ) ); 939 $australia = self::factory()->term->create( 940 array( 941 'name' => 'Australia', 942 'taxonomy' => $flat_tax, 943 ) 944 ); 945 $china = self::factory()->term->create( 946 array( 947 'name' => 'China', 948 'taxonomy' => $flat_tax, 949 ) 950 ); 951 $tanzania = self::factory()->term->create( 952 array( 953 'name' => 'Tanzania', 954 'taxonomy' => $flat_tax, 955 ) 956 ); 957 958 $terms = get_terms( 959 $flat_tax, array( 960 'childless' => true, 961 'hide_empty' => false, 962 'fields' => 'ids', 963 ) 964 ); 694 965 695 966 $expected = array( $australia, $china, $tanzania ); … … 715 986 */ 716 987 // Level 1 717 $canada = self::factory()->term->create( array( 'name' => 'Canada', 'taxonomy' => $tax ) ); 988 $canada = self::factory()->term->create( 989 array( 990 'name' => 'Canada', 991 'taxonomy' => $tax, 992 ) 993 ); 718 994 719 995 // Level 2 720 $ontario = self::factory()->term->create( array( 'name' => 'Ontario', 'parent' => $canada, 'taxonomy' => $tax ) ); 721 $quebec = self::factory()->term->create( array( 'name' => 'Quebec', 'parent' => $canada, 'taxonomy' => $tax ) ); 722 $pei = self::factory()->term->create( array( 'name' => 'PEI', 'parent' => $canada, 'taxonomy' => $tax ) ); 996 $ontario = self::factory()->term->create( 997 array( 998 'name' => 'Ontario', 999 'parent' => $canada, 1000 'taxonomy' => $tax, 1001 ) 1002 ); 1003 $quebec = self::factory()->term->create( 1004 array( 1005 'name' => 'Quebec', 1006 'parent' => $canada, 1007 'taxonomy' => $tax, 1008 ) 1009 ); 1010 $pei = self::factory()->term->create( 1011 array( 1012 'name' => 'PEI', 1013 'parent' => $canada, 1014 'taxonomy' => $tax, 1015 ) 1016 ); 723 1017 724 1018 // Level 3 725 $toronto = self::factory()->term->create( array( 'name' => 'Toronto', 'parent' => $ontario, 'taxonomy' => $tax ) ); 726 $ottawa = self::factory()->term->create( array( 'name' => 'Ottawa', 'parent' => $ontario, 'taxonomy' => $tax ) ); 727 $montreal = self::factory()->term->create( array( 'name' => 'Montreal', 'parent' => $quebec, 'taxonomy' => $tax ) ); 1019 $toronto = self::factory()->term->create( 1020 array( 1021 'name' => 'Toronto', 1022 'parent' => $ontario, 1023 'taxonomy' => $tax, 1024 ) 1025 ); 1026 $ottawa = self::factory()->term->create( 1027 array( 1028 'name' => 'Ottawa', 1029 'parent' => $ontario, 1030 'taxonomy' => $tax, 1031 ) 1032 ); 1033 $montreal = self::factory()->term->create( 1034 array( 1035 'name' => 'Montreal', 1036 'parent' => $quebec, 1037 'taxonomy' => $tax, 1038 ) 1039 ); 728 1040 729 1041 // Level 4 730 $nepean = self::factory()->term->create( array( 'name' => 'Nepean', 'parent' => $ottawa, 'taxonomy' => $tax ) ); 731 732 $terms = get_terms( $tax, array( 733 'childless' => true, 734 'hide_empty' => false, 735 'fields' => 'ids', 736 ) ); 1042 $nepean = self::factory()->term->create( 1043 array( 1044 'name' => 'Nepean', 1045 'parent' => $ottawa, 1046 'taxonomy' => $tax, 1047 ) 1048 ); 1049 1050 $terms = get_terms( 1051 $tax, array( 1052 'childless' => true, 1053 'hide_empty' => false, 1054 'fields' => 'ids', 1055 ) 1056 ); 737 1057 738 1058 $this->assertEqualSets( array( $montreal, $nepean, $toronto, $pei ), $terms ); … … 747 1067 748 1068 // Level 1 749 $canada = self::factory()->term->create( array( 'name' => 'Canada', 'taxonomy' => $tax ) ); 1069 $canada = self::factory()->term->create( 1070 array( 1071 'name' => 'Canada', 1072 'taxonomy' => $tax, 1073 ) 1074 ); 750 1075 751 1076 // Level 2 752 $ontario = self::factory()->term->create( array( 'name' => 'Ontario', 'parent' => $canada, 'taxonomy' => $tax ) ); 753 $quebec = self::factory()->term->create( array( 'name' => 'Quebec', 'parent' => $canada, 'taxonomy' => $tax ) ); 1077 $ontario = self::factory()->term->create( 1078 array( 1079 'name' => 'Ontario', 1080 'parent' => $canada, 1081 'taxonomy' => $tax, 1082 ) 1083 ); 1084 $quebec = self::factory()->term->create( 1085 array( 1086 'name' => 'Quebec', 1087 'parent' => $canada, 1088 'taxonomy' => $tax, 1089 ) 1090 ); 754 1091 755 1092 // Level 3 756 $laval = self::factory()->term->create( array( 'name' => 'Laval', 'parent' => $quebec, 'taxonomy' => $tax ) ); 757 $montreal = self::factory()->term->create( array( 'name' => 'Montreal', 'parent' => $quebec, 'taxonomy' => $tax ) ); 1093 $laval = self::factory()->term->create( 1094 array( 1095 'name' => 'Laval', 1096 'parent' => $quebec, 1097 'taxonomy' => $tax, 1098 ) 1099 ); 1100 $montreal = self::factory()->term->create( 1101 array( 1102 'name' => 'Montreal', 1103 'parent' => $quebec, 1104 'taxonomy' => $tax, 1105 ) 1106 ); 758 1107 759 1108 // Level 4 760 $dorval = self::factory()->term->create( array( 'name' => 'Dorval', 'parent' => $montreal, 'taxonomy' => $tax ) ); 761 762 $terms = get_terms( $tax, array( 763 'childless' => true, 764 'child_of' => $quebec, 765 'hide_empty' => false, 766 'fields' => 'ids', 767 ) ); 1109 $dorval = self::factory()->term->create( 1110 array( 1111 'name' => 'Dorval', 1112 'parent' => $montreal, 1113 'taxonomy' => $tax, 1114 ) 1115 ); 1116 1117 $terms = get_terms( 1118 $tax, array( 1119 'childless' => true, 1120 'child_of' => $quebec, 1121 'hide_empty' => false, 1122 'fields' => 'ids', 1123 ) 1124 ); 768 1125 769 1126 $this->assertEqualSets( array( $laval ), $terms ); … … 778 1135 779 1136 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); 780 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1', 'parent' => $t1 ) ); 1137 $t2 = self::factory()->term->create( 1138 array( 1139 'taxonomy' => 'wptests_tax1', 1140 'parent' => $t1, 1141 ) 1142 ); 781 1143 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); 782 $t4 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t3 ) ); 783 784 $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array( 785 'fields' => 'ids', 786 'hide_empty' => false, 787 'childless' => true, 788 ) ); 1144 $t4 = self::factory()->term->create( 1145 array( 1146 'taxonomy' => 'wptests_tax2', 1147 'parent' => $t3, 1148 ) 1149 ); 1150 1151 $found = get_terms( 1152 array( 'wptests_tax1', 'wptests_tax2' ), array( 1153 'fields' => 'ids', 1154 'hide_empty' => false, 1155 'childless' => true, 1156 ) 1157 ); 789 1158 790 1159 $this->assertEqualSets( array( $t2, $t4 ), $found ); … … 798 1167 $terms = $this->create_hierarchical_terms_and_posts(); 799 1168 800 $found = get_terms( $tax, array( 801 'hide_empty' => false, 802 'fields' => 'ids', 803 ) ); 1169 $found = get_terms( 1170 $tax, array( 1171 'hide_empty' => false, 1172 'fields' => 'ids', 1173 ) 1174 ); 804 1175 805 1176 $expected = array( … … 823 1194 $terms = $this->create_hierarchical_terms_and_posts(); 824 1195 825 $found = get_terms( $tax, array( 826 'hide_empty' => true, 827 'fields' => 'ids', 828 ) ); 1196 $found = get_terms( 1197 $tax, array( 1198 'hide_empty' => true, 1199 'fields' => 'ids', 1200 ) 1201 ); 829 1202 830 1203 $expected = array( … … 846 1219 $terms = $this->create_hierarchical_terms_and_posts(); 847 1220 848 $found = get_terms( $tax, array( 849 'hide_empty' => true, 850 'fields' => 'ids', 851 'hierarchical' => false, 852 ) ); 1221 $found = get_terms( 1222 $tax, array( 1223 'hide_empty' => true, 1224 'fields' => 'ids', 1225 'hierarchical' => false, 1226 ) 1227 ); 853 1228 854 1229 $expected = array( … … 869 1244 $terms = $this->create_hierarchical_terms_and_posts(); 870 1245 871 $found = get_terms( $tax, array( 872 'hide_empty' => false, 873 'fields' => 'names', 874 ) ); 1246 $found = get_terms( 1247 $tax, array( 1248 'hide_empty' => false, 1249 'fields' => 'names', 1250 ) 1251 ); 875 1252 876 1253 $expected = array( … … 894 1271 $terms = $this->create_hierarchical_terms_and_posts(); 895 1272 896 $found = get_terms( $tax, array( 897 'hide_empty' => true, 898 'fields' => 'names', 899 ) ); 1273 $found = get_terms( 1274 $tax, array( 1275 'hide_empty' => true, 1276 'fields' => 'names', 1277 ) 1278 ); 900 1279 901 1280 $expected = array( … … 917 1296 $terms = $this->create_hierarchical_terms_and_posts(); 918 1297 919 $found = get_terms( $tax, array( 920 'hide_empty' => true, 921 'fields' => 'names', 922 'hierarchical' => false, 923 ) ); 1298 $found = get_terms( 1299 $tax, array( 1300 'hide_empty' => true, 1301 'fields' => 'names', 1302 'hierarchical' => false, 1303 ) 1304 ); 924 1305 925 1306 $expected = array( … … 940 1321 $terms = $this->create_hierarchical_terms_and_posts(); 941 1322 942 $found = get_terms( $tax, array( 943 'hide_empty' => false, 944 'fields' => 'count', 945 ) ); 1323 $found = get_terms( 1324 $tax, array( 1325 'hide_empty' => false, 1326 'fields' => 'count', 1327 ) 1328 ); 946 1329 947 1330 _unregister_taxonomy( 'hierarchical_fields' ); … … 957 1340 $terms = $this->create_hierarchical_terms_and_posts(); 958 1341 959 $found = get_terms( $tax, array( 960 'hide_empty' => true, 961 'fields' => 'count', 962 ) ); 1342 $found = get_terms( 1343 $tax, array( 1344 'hide_empty' => true, 1345 'fields' => 'count', 1346 ) 1347 ); 963 1348 964 1349 _unregister_taxonomy( 'hierarchical_fields' ); … … 975 1360 $terms = $this->create_hierarchical_terms_and_posts(); 976 1361 977 $found = get_terms( $tax, array( 978 'hide_empty' => true, 979 'fields' => 'count', 980 'hierarchical' => false, 981 ) ); 1362 $found = get_terms( 1363 $tax, array( 1364 'hide_empty' => true, 1365 'fields' => 'count', 1366 'hierarchical' => false, 1367 ) 1368 ); 982 1369 983 1370 _unregister_taxonomy( 'hierarchical_fields' ); … … 993 1380 $terms = $this->create_hierarchical_terms_and_posts(); 994 1381 995 $found = get_terms( $tax, array( 996 'hide_empty' => false, 997 'fields' => 'id=>parent', 998 ) ); 1382 $found = get_terms( 1383 $tax, array( 1384 'hide_empty' => false, 1385 'fields' => 'id=>parent', 1386 ) 1387 ); 999 1388 1000 1389 $expected = array( 1001 $terms['parent1'] => 0,1002 $terms['parent2'] => 0,1003 $terms['child1'] => $terms['parent1'],1004 $terms['child2'] => $terms['parent1'],1390 $terms['parent1'] => 0, 1391 $terms['parent2'] => 0, 1392 $terms['child1'] => $terms['parent1'], 1393 $terms['child2'] => $terms['parent1'], 1005 1394 $terms['grandchild1'] => $terms['child1'], 1006 1395 ); … … 1018 1407 $terms = $this->create_hierarchical_terms_and_posts(); 1019 1408 1020 $found = get_terms( $tax, array( 1021 'hide_empty' => true, 1022 'fields' => 'id=>parent', 1023 ) ); 1409 $found = get_terms( 1410 $tax, array( 1411 'hide_empty' => true, 1412 'fields' => 'id=>parent', 1413 ) 1414 ); 1024 1415 1025 1416 $expected = array( 1026 1417 $terms['parent1'] => 0, 1027 1418 $terms['parent2'] => 0, 1028 $terms['child1'] => $terms['parent1'],1419 $terms['child1'] => $terms['parent1'], 1029 1420 ); 1030 1421 … … 1041 1432 $terms = $this->create_hierarchical_terms_and_posts(); 1042 1433 1043 $found = get_terms( $tax, array( 1044 'hide_empty' => true, 1045 'fields' => 'id=>parent', 1046 'hierarchical' => false, 1047 ) ); 1434 $found = get_terms( 1435 $tax, array( 1436 'hide_empty' => true, 1437 'fields' => 'id=>parent', 1438 'hierarchical' => false, 1439 ) 1440 ); 1048 1441 1049 1442 $expected = array( 1050 1443 $terms['parent2'] => 0, 1051 $terms['child1'] => $terms['parent1'],1444 $terms['child1'] => $terms['parent1'], 1052 1445 ); 1053 1446 … … 1064 1457 $terms = $this->create_hierarchical_terms_and_posts(); 1065 1458 1066 $found = get_terms( $tax, array( 1067 'hide_empty' => false, 1068 'fields' => 'id=>slug', 1069 ) ); 1459 $found = get_terms( 1460 $tax, array( 1461 'hide_empty' => false, 1462 'fields' => 'id=>slug', 1463 ) 1464 ); 1070 1465 1071 1466 $expected = array( 1072 $terms['parent1'] => 'parent-1',1073 $terms['parent2'] => 'parent-2',1074 $terms['child1'] => 'child-1',1075 $terms['child2'] => 'child-2',1467 $terms['parent1'] => 'parent-1', 1468 $terms['parent2'] => 'parent-2', 1469 $terms['child1'] => 'child-1', 1470 $terms['child2'] => 'child-2', 1076 1471 $terms['grandchild1'] => 'grandchild-1', 1077 1472 ); … … 1092 1487 $terms = $this->create_hierarchical_terms_and_posts(); 1093 1488 1094 $found = get_terms( $tax, array( 1095 'hide_empty' => true, 1096 'fields' => 'id=>slug', 1097 ) ); 1489 $found = get_terms( 1490 $tax, array( 1491 'hide_empty' => true, 1492 'fields' => 'id=>slug', 1493 ) 1494 ); 1098 1495 1099 1496 $expected = array( 1100 1497 $terms['parent1'] => 'parent-1', 1101 1498 $terms['parent2'] => 'parent-2', 1102 $terms['child1'] => 'child-1',1499 $terms['child1'] => 'child-1', 1103 1500 ); 1104 1501 … … 1115 1512 $terms = $this->create_hierarchical_terms_and_posts(); 1116 1513 1117 $found = get_terms( $tax, array( 1118 'hide_empty' => true, 1119 'fields' => 'id=>slug', 1120 'hierarchical' => false, 1121 ) ); 1514 $found = get_terms( 1515 $tax, array( 1516 'hide_empty' => true, 1517 'fields' => 'id=>slug', 1518 'hierarchical' => false, 1519 ) 1520 ); 1122 1521 1123 1522 $expected = array( 1124 1523 $terms['parent2'] => 'parent-2', 1125 $terms['child1'] => 'child-1',1524 $terms['child1'] => 'child-1', 1126 1525 ); 1127 1526 … … 1138 1537 $terms = $this->create_hierarchical_terms_and_posts(); 1139 1538 1140 $found = get_terms( $tax, array( 1141 'hide_empty' => false, 1142 'fields' => 'id=>name', 1143 ) ); 1539 $found = get_terms( 1540 $tax, array( 1541 'hide_empty' => false, 1542 'fields' => 'id=>name', 1543 ) 1544 ); 1144 1545 1145 1546 $expected = array( 1146 $terms['parent1'] => 'Parent 1',1147 $terms['parent2'] => 'Parent 2',1148 $terms['child1'] => 'Child 1',1149 $terms['child2'] => 'Child 2',1547 $terms['parent1'] => 'Parent 1', 1548 $terms['parent2'] => 'Parent 2', 1549 $terms['child1'] => 'Child 1', 1550 $terms['child2'] => 'Child 2', 1150 1551 $terms['grandchild1'] => 'Grandchild 1', 1151 1552 ); … … 1166 1567 $terms = $this->create_hierarchical_terms_and_posts(); 1167 1568 1168 $found = get_terms( $tax, array( 1169 'hide_empty' => true, 1170 'fields' => 'id=>name', 1171 ) ); 1569 $found = get_terms( 1570 $tax, array( 1571 'hide_empty' => true, 1572 'fields' => 'id=>name', 1573 ) 1574 ); 1172 1575 1173 1576 $expected = array( 1174 1577 $terms['parent1'] => 'Parent 1', 1175 1578 $terms['parent2'] => 'Parent 2', 1176 $terms['child1'] => 'Child 1',1579 $terms['child1'] => 'Child 1', 1177 1580 ); 1178 1581 … … 1189 1592 $terms = $this->create_hierarchical_terms_and_posts(); 1190 1593 1191 $found = get_terms( $tax, array( 1192 'hide_empty' => true, 1193 'fields' => 'id=>name', 1194 'hierarchical' => false, 1195 ) ); 1594 $found = get_terms( 1595 $tax, array( 1596 'hide_empty' => true, 1597 'fields' => 'id=>name', 1598 'hierarchical' => false, 1599 ) 1600 ); 1196 1601 1197 1602 $expected = array( 1198 1603 $terms['parent2'] => 'Parent 2', 1199 $terms['child1'] => 'Child 1',1604 $terms['child1'] => 'Child 1', 1200 1605 ); 1201 1606 … … 1213 1618 1214 1619 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); 1215 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1', 'parent' => $t1 ) ); 1216 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1', 'parent' => $t2 ) ); 1620 $t2 = self::factory()->term->create( 1621 array( 1622 'taxonomy' => 'wptests_tax1', 1623 'parent' => $t1, 1624 ) 1625 ); 1626 $t3 = self::factory()->term->create( 1627 array( 1628 'taxonomy' => 'wptests_tax1', 1629 'parent' => $t2, 1630 ) 1631 ); 1217 1632 1218 1633 $t4 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); 1219 $t5 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t4 ) ); 1220 $t6 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t5 ) ); 1634 $t5 = self::factory()->term->create( 1635 array( 1636 'taxonomy' => 'wptests_tax2', 1637 'parent' => $t4, 1638 ) 1639 ); 1640 $t6 = self::factory()->term->create( 1641 array( 1642 'taxonomy' => 'wptests_tax2', 1643 'parent' => $t5, 1644 ) 1645 ); 1221 1646 1222 1647 $p = self::factory()->post->create(); … … 1225 1650 wp_set_object_terms( $p, $t6, 'wptests_tax2' ); 1226 1651 1227 $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array( 1228 'hierarchical' => true, 1229 'hide_empty' => true, 1230 'fields' => 'ids', 1231 ) ); 1652 $found = get_terms( 1653 array( 'wptests_tax1', 'wptests_tax2' ), array( 1654 'hierarchical' => true, 1655 'hide_empty' => true, 1656 'fields' => 'ids', 1657 ) 1658 ); 1232 1659 1233 1660 /* … … 1259 1686 $t4 = self::factory()->term->create( array( 'taxonomy' => $tax ) ); 1260 1687 1261 $found = get_terms( $tax, array( 1262 'fields' => 'ids', 1263 'include' => array( $t4, $t1, $t2 ), 1264 'orderby' => 'include', 1265 'hide_empty' => false, 1266 ) ); 1688 $found = get_terms( 1689 $tax, array( 1690 'fields' => 'ids', 1691 'include' => array( $t4, $t1, $t2 ), 1692 'orderby' => 'include', 1693 'hide_empty' => false, 1694 ) 1695 ); 1267 1696 1268 1697 _unregister_taxonomy( 'wptests_tax' ); … … 1278 1707 register_taxonomy( $tax, 'post' ); 1279 1708 1280 $t1 = self::factory()->term->create( array( 'taxonomy' => $tax, 'description' => 'fff' ) ); 1281 $t2 = self::factory()->term->create( array( 'taxonomy' => $tax, 'description' => 'aaa' ) ); 1282 $t3 = self::factory()->term->create( array( 'taxonomy' => $tax, 'description' => 'zzz' ) ); 1283 $t4 = self::factory()->term->create( array( 'taxonomy' => $tax, 'description' => 'jjj' ) ); 1284 1285 $found = get_terms( $tax, array( 1286 'fields' => 'ids', 1287 'orderby' => 'description', 1288 'hide_empty' => false, 1289 ) ); 1709 $t1 = self::factory()->term->create( 1710 array( 1711 'taxonomy' => $tax, 1712 'description' => 'fff', 1713 ) 1714 ); 1715 $t2 = self::factory()->term->create( 1716 array( 1717 'taxonomy' => $tax, 1718 'description' => 'aaa', 1719 ) 1720 ); 1721 $t3 = self::factory()->term->create( 1722 array( 1723 'taxonomy' => $tax, 1724 'description' => 'zzz', 1725 ) 1726 ); 1727 $t4 = self::factory()->term->create( 1728 array( 1729 'taxonomy' => $tax, 1730 'description' => 'jjj', 1731 ) 1732 ); 1733 1734 $found = get_terms( 1735 $tax, array( 1736 'fields' => 'ids', 1737 'orderby' => 'description', 1738 'hide_empty' => false, 1739 ) 1740 ); 1290 1741 1291 1742 _unregister_taxonomy( 'wptests_tax' ); … … 1299 1750 public function test_orderby_term_id() { 1300 1751 register_taxonomy( 'wptests_tax', 'post' ); 1301 $t1 = self::factory()->term->create( array( 1302 'taxonomy' => 'wptests_tax', 1303 'name' => 'AAA', 1304 ) ); 1305 $t2 = self::factory()->term->create( array( 1306 'taxonomy' => 'wptests_tax', 1307 'name' => 'ZZZ', 1308 ) ); 1309 $t3 = self::factory()->term->create( array( 1310 'taxonomy' => 'wptests_tax', 1311 'name' => 'JJJ', 1312 ) ); 1313 1314 $found = get_terms( 'wptests_tax', array( 1315 'orderby' => 'term_id', 1316 'hide_empty' => false, 1317 'fields' => 'ids', 1318 ) ); 1752 $t1 = self::factory()->term->create( 1753 array( 1754 'taxonomy' => 'wptests_tax', 1755 'name' => 'AAA', 1756 ) 1757 ); 1758 $t2 = self::factory()->term->create( 1759 array( 1760 'taxonomy' => 'wptests_tax', 1761 'name' => 'ZZZ', 1762 ) 1763 ); 1764 $t3 = self::factory()->term->create( 1765 array( 1766 'taxonomy' => 'wptests_tax', 1767 'name' => 'JJJ', 1768 ) 1769 ); 1770 1771 $found = get_terms( 1772 'wptests_tax', array( 1773 'orderby' => 'term_id', 1774 'hide_empty' => false, 1775 'fields' => 'ids', 1776 ) 1777 ); 1319 1778 1320 1779 $this->assertEquals( array( $t1, $t2, $t3 ), $found ); … … 1335 1794 1336 1795 // Matches the first meta query clause. 1337 $found = get_terms( 'wptests_tax', array( 1338 'hide_empty' => false, 1339 'meta_query' => array( 1340 'relation' => 'AND', 1341 array( 1342 'key' => 'foo', 1343 'compare' => 'EXISTS', 1796 $found = get_terms( 1797 'wptests_tax', array( 1798 'hide_empty' => false, 1799 'meta_query' => array( 1800 'relation' => 'AND', 1801 array( 1802 'key' => 'foo', 1803 'compare' => 'EXISTS', 1804 ), 1805 array( 1806 'key' => 'fee', 1807 'compare' => 'EXISTS', 1808 ), 1344 1809 ), 1345 array( 1346 'key' => 'fee', 1347 'compare' => 'EXISTS', 1348 ), 1349 ), 1350 'orderby' => 'meta_value', 1351 'order' => 'ASC', 1352 'fields' => 'ids', 1353 ) ); 1810 'orderby' => 'meta_value', 1811 'order' => 'ASC', 1812 'fields' => 'ids', 1813 ) 1814 ); 1354 1815 1355 1816 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); … … 1370 1831 1371 1832 // Matches the first meta query clause. 1372 $found = get_terms( 'wptests_tax', array( 1373 'hide_empty' => false, 1374 'meta_query' => array( 1375 'relation' => 'AND', 1376 array( 1377 'key' => 'foo', 1378 'compare' => 'EXISTS', 1833 $found = get_terms( 1834 'wptests_tax', array( 1835 'hide_empty' => false, 1836 'meta_query' => array( 1837 'relation' => 'AND', 1838 array( 1839 'key' => 'foo', 1840 'compare' => 'EXISTS', 1841 ), 1842 array( 1843 'key' => 'fee', 1844 'compare' => 'EXISTS', 1845 ), 1379 1846 ), 1380 array( 1381 'key' => 'fee', 1382 'compare' => 'EXISTS', 1383 ), 1384 ), 1385 'orderby' => 'meta_value_num', 1386 'order' => 'ASC', 1387 'fields' => 'ids', 1388 ) ); 1847 'orderby' => 'meta_value_num', 1848 'order' => 'ASC', 1849 'fields' => 'ids', 1850 ) 1851 ); 1389 1852 1390 1853 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); … … 1407 1870 add_term_meta( $terms[2], 'faa', 'zzz' ); 1408 1871 1409 $found = get_terms( 'wptests_tax', array( 1410 'hide_empty' => false, 1411 'meta_key' => 'fee', 1412 'orderby' => 'meta_value', 1413 'order' => 'ASC', 1414 'fields' => 'ids', 1415 ) ); 1872 $found = get_terms( 1873 'wptests_tax', array( 1874 'hide_empty' => false, 1875 'meta_key' => 'fee', 1876 'orderby' => 'meta_value', 1877 'order' => 'ASC', 1878 'fields' => 'ids', 1879 ) 1880 ); 1416 1881 1417 1882 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1418 1883 1419 $found = get_terms( 'wptests_tax', array( 1420 'hide_empty' => false, 1421 'meta_query' => array( 1422 array( 1423 'key' => 'foo', 1424 'compare' => 'EXISTS', 1884 $found = get_terms( 1885 'wptests_tax', array( 1886 'hide_empty' => false, 1887 'meta_query' => array( 1888 array( 1889 'key' => 'foo', 1890 'compare' => 'EXISTS', 1891 ), 1425 1892 ), 1426 ),1427 'meta_key' => 'fee',1428 'orderby' => 'meta_value',1429 'order' => 'ASC',1430 'fields' => 'ids',1431 ) );1893 'meta_key' => 'fee', 1894 'orderby' => 'meta_value', 1895 'order' => 'ASC', 1896 'fields' => 'ids', 1897 ) 1898 ); 1432 1899 1433 1900 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1434 1901 1435 1902 // Matches the first meta query clause. 1436 $found = get_terms( 'wptests_tax', array( 1437 'hide_empty' => false, 1438 'meta_query' => array( 1439 'relation' => 'AND', 1440 array( 1441 'key' => 'foo', 1442 'compare' => 'EXISTS', 1903 $found = get_terms( 1904 'wptests_tax', array( 1905 'hide_empty' => false, 1906 'meta_query' => array( 1907 'relation' => 'AND', 1908 array( 1909 'key' => 'foo', 1910 'compare' => 'EXISTS', 1911 ), 1912 array( 1913 'key' => 'fee', 1914 'compare' => 'EXISTS', 1915 ), 1443 1916 ), 1444 array( 1445 'key' => 'fee', 1446 'compare' => 'EXISTS', 1917 'meta_key' => 'fee', 1918 'orderby' => 'meta_value', 1919 'order' => 'ASC', 1920 'fields' => 'ids', 1921 ) 1922 ); 1923 1924 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1925 1926 // Matches the meta query clause corresponding to the 'meta_key' param. 1927 $found = get_terms( 1928 'wptests_tax', array( 1929 'hide_empty' => false, 1930 'meta_query' => array( 1931 'relation' => 'AND', 1932 array( 1933 'key' => 'foo', 1934 'compare' => 'EXISTS', 1935 ), 1936 array( 1937 'key' => 'fee', 1938 'compare' => 'EXISTS', 1939 ), 1447 1940 ), 1448 ), 1449 'meta_key' => 'fee', 1450 'orderby' => 'meta_value', 1451 'order' => 'ASC', 1452 'fields' => 'ids', 1453 ) ); 1454 1455 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1456 1457 // Matches the meta query clause corresponding to the 'meta_key' param. 1458 $found = get_terms( 'wptests_tax', array( 1459 'hide_empty' => false, 1460 'meta_query' => array( 1461 'relation' => 'AND', 1462 array( 1463 'key' => 'foo', 1464 'compare' => 'EXISTS', 1465 ), 1466 array( 1467 'key' => 'fee', 1468 'compare' => 'EXISTS', 1469 ), 1470 ), 1471 'meta_key' => 'faa', 1472 'orderby' => 'meta_value', 1473 'order' => 'ASC', 1474 'fields' => 'ids', 1475 ) ); 1941 'meta_key' => 'faa', 1942 'orderby' => 'meta_value', 1943 'order' => 'ASC', 1944 'fields' => 'ids', 1945 ) 1946 ); 1476 1947 1477 1948 $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found ); … … 1494 1965 add_term_meta( $terms[2], 'faa', '999' ); 1495 1966 1496 $found = get_terms( 'wptests_tax', array( 1497 'hide_empty' => false, 1498 'meta_key' => 'fee', 1499 'orderby' => 'meta_value', 1500 'order' => 'ASC', 1501 'fields' => 'ids', 1502 ) ); 1967 $found = get_terms( 1968 'wptests_tax', array( 1969 'hide_empty' => false, 1970 'meta_key' => 'fee', 1971 'orderby' => 'meta_value', 1972 'order' => 'ASC', 1973 'fields' => 'ids', 1974 ) 1975 ); 1503 1976 1504 1977 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1505 1978 1506 $found = get_terms( 'wptests_tax', array( 1507 'hide_empty' => false, 1508 'meta_query' => array( 1509 array( 1510 'key' => 'foo', 1511 'compare' => 'EXISTS', 1979 $found = get_terms( 1980 'wptests_tax', array( 1981 'hide_empty' => false, 1982 'meta_query' => array( 1983 array( 1984 'key' => 'foo', 1985 'compare' => 'EXISTS', 1986 ), 1512 1987 ), 1513 ),1514 'meta_key' => 'fee',1515 'orderby' => 'meta_value',1516 'order' => 'ASC',1517 'fields' => 'ids',1518 ) );1988 'meta_key' => 'fee', 1989 'orderby' => 'meta_value', 1990 'order' => 'ASC', 1991 'fields' => 'ids', 1992 ) 1993 ); 1519 1994 1520 1995 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1521 1996 1522 $found = get_terms( 'wptests_tax', array( 1523 'hide_empty' => false, 1524 'meta_query' => array( 1525 'relation' => 'AND', 1526 array( 1527 'key' => 'foo', 1528 'compare' => 'EXISTS', 1997 $found = get_terms( 1998 'wptests_tax', array( 1999 'hide_empty' => false, 2000 'meta_query' => array( 2001 'relation' => 'AND', 2002 array( 2003 'key' => 'foo', 2004 'compare' => 'EXISTS', 2005 ), 2006 array( 2007 'key' => 'fee', 2008 'compare' => 'EXISTS', 2009 ), 1529 2010 ), 1530 array( 1531 'key' => 'fee', 1532 'compare' => 'EXISTS', 2011 'meta_key' => 'fee', 2012 'orderby' => 'meta_value', 2013 'order' => 'ASC', 2014 'fields' => 'ids', 2015 ) 2016 ); 2017 2018 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 2019 2020 $found = get_terms( 2021 'wptests_tax', array( 2022 'hide_empty' => false, 2023 'meta_query' => array( 2024 'relation' => 'AND', 2025 array( 2026 'key' => 'foo', 2027 'compare' => 'EXISTS', 2028 ), 2029 array( 2030 'key' => 'fee', 2031 'compare' => 'EXISTS', 2032 ), 1533 2033 ), 1534 ), 1535 'meta_key' => 'fee', 1536 'orderby' => 'meta_value', 1537 'order' => 'ASC', 1538 'fields' => 'ids', 1539 ) ); 1540 1541 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1542 1543 $found = get_terms( 'wptests_tax', array( 1544 'hide_empty' => false, 1545 'meta_query' => array( 1546 'relation' => 'AND', 1547 array( 1548 'key' => 'foo', 1549 'compare' => 'EXISTS', 1550 ), 1551 array( 1552 'key' => 'fee', 1553 'compare' => 'EXISTS', 1554 ), 1555 ), 1556 'meta_key' => 'faa', 1557 'orderby' => 'meta_value', 1558 'order' => 'ASC', 1559 'fields' => 'ids', 1560 ) ); 2034 'meta_key' => 'faa', 2035 'orderby' => 'meta_value', 2036 'order' => 'ASC', 2037 'fields' => 'ids', 2038 ) 2039 ); 1561 2040 1562 2041 $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found ); … … 1576 2055 add_term_meta( $terms[2], 'fee', 'zzz' ); 1577 2056 1578 $found = get_terms( 'wptests_tax', array( 1579 'hide_empty' => false, 1580 'meta_query' => array( 1581 'relation' => 'AND', 1582 'foo_key' => array( 1583 'key' => 'foo', 1584 'compare' => 'EXISTS', 2057 $found = get_terms( 2058 'wptests_tax', array( 2059 'hide_empty' => false, 2060 'meta_query' => array( 2061 'relation' => 'AND', 2062 'foo_key' => array( 2063 'key' => 'foo', 2064 'compare' => 'EXISTS', 2065 ), 2066 'fee_key' => array( 2067 'key' => 'fee', 2068 'compare' => 'EXISTS', 2069 ), 1585 2070 ), 1586 'fee_key' => array( 1587 'key' => 'fee', 1588 'compare' => 'EXISTS', 2071 'orderby' => 'foo_key', 2072 'order' => 'ASC', 2073 'fields' => 'ids', 2074 ) 2075 ); 2076 2077 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 2078 2079 $found = get_terms( 2080 'wptests_tax', array( 2081 'hide_empty' => false, 2082 'meta_query' => array( 2083 'relation' => 'AND', 2084 'foo_key' => array( 2085 'key' => 'foo', 2086 'compare' => 'EXISTS', 2087 ), 2088 'fee_key' => array( 2089 'key' => 'fee', 2090 'compare' => 'EXISTS', 2091 ), 1589 2092 ), 1590 ), 1591 'orderby' => 'foo_key', 1592 'order' => 'ASC', 1593 'fields' => 'ids', 1594 ) ); 1595 1596 $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found ); 1597 1598 $found = get_terms( 'wptests_tax', array( 1599 'hide_empty' => false, 1600 'meta_query' => array( 1601 'relation' => 'AND', 1602 'foo_key' => array( 1603 'key' => 'foo', 1604 'compare' => 'EXISTS', 2093 'orderby' => 'fee_key', 2094 'order' => 'ASC', 2095 'fields' => 'ids', 2096 ) 2097 ); 2098 2099 $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found ); 2100 2101 $expected = get_terms( 2102 'wptests_tax', array( 2103 'hide_empty' => false, 2104 'meta_query' => array( 2105 'relation' => 'AND', 2106 'foo_key' => array( 2107 'key' => 'foo', 2108 'compare' => 'EXISTS', 2109 ), 2110 'fee_key' => array( 2111 'key' => 'fee', 2112 'compare' => 'EXISTS', 2113 ), 1605 2114 ), 1606 'fee_key' => array( 1607 'key' => 'fee', 1608 'compare' => 'EXISTS', 2115 'fields' => 'ids', 2116 ) 2117 ); 2118 2119 $found = get_terms( 2120 'wptests_tax', array( 2121 'hide_empty' => false, 2122 'meta_query' => array( 2123 'relation' => 'AND', 2124 'foo_key' => array( 2125 'key' => 'foo', 2126 'compare' => 'EXISTS', 2127 ), 2128 'fee_key' => array( 2129 'key' => 'fee', 2130 'compare' => 'EXISTS', 2131 ), 1609 2132 ), 1610 ), 1611 'orderby' => 'fee_key', 1612 'order' => 'ASC', 1613 'fields' => 'ids', 1614 ) ); 1615 1616 $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found ); 1617 1618 $expected = get_terms( 'wptests_tax', array( 1619 'hide_empty' => false, 1620 'meta_query' => array( 1621 'relation' => 'AND', 1622 'foo_key' => array( 1623 'key' => 'foo', 1624 'compare' => 'EXISTS', 1625 ), 1626 'fee_key' => array( 1627 'key' => 'fee', 1628 'compare' => 'EXISTS', 1629 ), 1630 ), 1631 'fields' => 'ids', 1632 ) ); 1633 1634 $found = get_terms( 'wptests_tax', array( 1635 'hide_empty' => false, 1636 'meta_query' => array( 1637 'relation' => 'AND', 1638 'foo_key' => array( 1639 'key' => 'foo', 1640 'compare' => 'EXISTS', 1641 ), 1642 'fee_key' => array( 1643 'key' => 'fee', 1644 'compare' => 'EXISTS', 1645 ), 1646 ), 1647 'orderby' => 'faa_key', 1648 'fields' => 'ids', 1649 ) ); 2133 'orderby' => 'faa_key', 2134 'fields' => 'ids', 2135 ) 2136 ); 1650 2137 1651 2138 $this->assertEqualSets( $expected, $found ); … … 1656 2143 1657 2144 // Case where hierarchical is false 1658 $terms = get_terms( 'category', array( 1659 'hierarchical' => false, 1660 'parent' => $initial_terms['one_term']['term_id'] 1661 ) ); 2145 $terms = get_terms( 2146 'category', array( 2147 'hierarchical' => false, 2148 'parent' => $initial_terms['one_term']['term_id'], 2149 ) 2150 ); 1662 2151 1663 2152 // Verify that there are no children … … 1672 2161 1673 2162 // Case where hierarchical is true 1674 $terms = get_terms( 'category', array( 1675 'hierarchical' => true, 1676 'parent' => $initial_terms['one_term']['term_id'] 1677 ) ); 2163 $terms = get_terms( 2164 'category', array( 2165 'hierarchical' => true, 2166 'parent' => $initial_terms['one_term']['term_id'], 2167 ) 2168 ); 1678 2169 1679 2170 // Verify that the children with non-empty descendants are returned … … 1682 2173 $initial_terms['five_term']['term_id'], 1683 2174 ); 1684 $actual = wp_list_pluck( $terms, 'term_id' );2175 $actual = wp_list_pluck( $terms, 'term_id' ); 1685 2176 $this->assertEqualSets( $expected, $actual ); 1686 2177 } … … 1688 2179 public function test_hierarchical_false_with_child_of_and_direct_child() { 1689 2180 $initial_terms = $this->create_hierarchical_terms(); 1690 $post_id = self::factory()->post->create();2181 $post_id = self::factory()->post->create(); 1691 2182 wp_set_post_terms( 1692 2183 $post_id, … … 1696 2187 1697 2188 // Case where hierarchical is false 1698 $terms = get_terms( 'category', array( 1699 'hierarchical' => false, 1700 'child_of' => $initial_terms['one_term']['term_id'] 1701 ) ); 2189 $terms = get_terms( 2190 'category', array( 2191 'hierarchical' => false, 2192 'child_of' => $initial_terms['one_term']['term_id'], 2193 ) 2194 ); 1702 2195 1703 2196 $expected = array( … … 1713 2206 1714 2207 // Case where hierarchical is false 1715 $terms = get_terms( 'category', array( 1716 'hierarchical' => false, 1717 'child_of' => $initial_terms['one_term']['term_id'] 1718 ) ); 2208 $terms = get_terms( 2209 'category', array( 2210 'hierarchical' => false, 2211 'child_of' => $initial_terms['one_term']['term_id'], 2212 ) 2213 ); 1719 2214 1720 2215 // Verify that there are no children … … 1726 2221 1727 2222 // Case where hierarchical is true 1728 $terms = get_terms( 'category', array( 1729 'hierarchical' => true, 1730 'child_of' => $initial_terms['one_term']['term_id'] 1731 ) ); 2223 $terms = get_terms( 2224 'category', array( 2225 'hierarchical' => true, 2226 'child_of' => $initial_terms['one_term']['term_id'], 2227 ) 2228 ); 1732 2229 1733 2230 $expected = array( … … 1737 2234 $initial_terms['six_term']['term_id'], 1738 2235 ); 1739 $actual = wp_list_pluck( $terms, 'term_id' );2236 $actual = wp_list_pluck( $terms, 'term_id' ); 1740 2237 $this->assertEqualSets( $expected, $actual ); 1741 2238 } … … 1744 2241 $initial_terms = $this->create_hierarchical_terms(); 1745 2242 1746 $terms = get_terms( 'category', array( 1747 'hide_empty' => false, 1748 'child_of' => $initial_terms['one_term']['term_id'], 1749 'parent' => $initial_terms['one_term']['term_id'] 1750 ) ); 2243 $terms = get_terms( 2244 'category', array( 2245 'hide_empty' => false, 2246 'child_of' => $initial_terms['one_term']['term_id'], 2247 'parent' => $initial_terms['one_term']['term_id'], 2248 ) 2249 ); 1751 2250 1752 2251 // Verify that parent takes precedence over child_of and returns only direct children. … … 1754 2253 $initial_terms['two_term']['term_id'], 1755 2254 $initial_terms['five_term']['term_id'], 1756 $initial_terms['seven_term']['term_id'] 1757 ); 1758 $actual = wp_list_pluck( $terms, 'term_id' );2255 $initial_terms['seven_term']['term_id'], 2256 ); 2257 $actual = wp_list_pluck( $terms, 'term_id' ); 1759 2258 $this->assertEqualSets( $expected, $actual ); 1760 2259 } … … 1766 2265 global $wpdb; 1767 2266 1768 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ,) );2267 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 1769 2268 1770 2269 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); … … 1772 2271 $num_queries = $wpdb->num_queries; 1773 2272 1774 $found = get_terms( 'wptests_tax', array( 1775 'hide_empty' => false, 1776 'parent' => $terms[0], 1777 ) ); 2273 $found = get_terms( 2274 'wptests_tax', array( 2275 'hide_empty' => false, 2276 'parent' => $terms[0], 2277 ) 2278 ); 1778 2279 1779 2280 $this->assertEmpty( $found ); … … 1790 2291 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); 1791 2292 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); 1792 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t2 ) ); 1793 1794 $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array( 1795 'fields' => 'ids', 1796 'hide_empty' => false, 1797 'parent' => $t2, 1798 ) ); 2293 $t3 = self::factory()->term->create( 2294 array( 2295 'taxonomy' => 'wptests_tax2', 2296 'parent' => $t2, 2297 ) 2298 ); 2299 2300 $found = get_terms( 2301 array( 'wptests_tax1', 'wptests_tax2' ), array( 2302 'fields' => 'ids', 2303 'hide_empty' => false, 2304 'parent' => $t2, 2305 ) 2306 ); 1799 2307 1800 2308 $this->assertEqualSets( array( $t3 ), $found ); … … 1805 2313 1806 2314 // Case where hierarchical is false 1807 $terms = get_terms( 'category', array( 1808 'hierarchical' => false, 1809 'child_of' => $initial_terms['one_term']['term_id'], 1810 'parent' => $initial_terms['one_term']['term_id'] 1811 ) ); 2315 $terms = get_terms( 2316 'category', array( 2317 'hierarchical' => false, 2318 'child_of' => $initial_terms['one_term']['term_id'], 2319 'parent' => $initial_terms['one_term']['term_id'], 2320 ) 2321 ); 1812 2322 1813 2323 // hierarchical=false means that descendants are not fetched. … … 1822 2332 1823 2333 // Case where hierarchical is true 1824 $terms = get_terms( 'category', array( 1825 'hierarchical' => true, 1826 'child_of' => $initial_terms['one_term']['term_id'], 1827 'parent' => $initial_terms['one_term']['term_id'], 1828 ) ); 2334 $terms = get_terms( 2335 'category', array( 2336 'hierarchical' => true, 2337 'child_of' => $initial_terms['one_term']['term_id'], 2338 'parent' => $initial_terms['one_term']['term_id'], 2339 ) 2340 ); 1829 2341 1830 2342 // Verify that parent takes precedence over child_of … … 1833 2345 $initial_terms['five_term']['term_id'], 1834 2346 ); 1835 $actual = wp_list_pluck( $terms, 'term_id' );2347 $actual = wp_list_pluck( $terms, 'term_id' ); 1836 2348 $this->assertEqualSets( $expected, $actual ); 1837 2349 } … … 1842 2354 $posts = self::factory()->post->create_many( 3 ); 1843 2355 1844 $t1 = self::factory()->term->create( array( 1845 'taxonomy' => 'wptests_tax_1', 1846 ) ); 1847 $t2 = self::factory()->term->create( array( 1848 'taxonomy' => 'wptests_tax_1', 1849 'parent' => $t1, 1850 ) ); 1851 $t3 = self::factory()->term->create( array( 1852 'taxonomy' => 'wptests_tax_1', 1853 'parent' => $t2, 1854 ) ); 2356 $t1 = self::factory()->term->create( 2357 array( 2358 'taxonomy' => 'wptests_tax_1', 2359 ) 2360 ); 2361 $t2 = self::factory()->term->create( 2362 array( 2363 'taxonomy' => 'wptests_tax_1', 2364 'parent' => $t1, 2365 ) 2366 ); 2367 $t3 = self::factory()->term->create( 2368 array( 2369 'taxonomy' => 'wptests_tax_1', 2370 'parent' => $t2, 2371 ) 2372 ); 1855 2373 1856 2374 wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax_1' ); … … 1858 2376 wp_set_object_terms( $posts[2], array( $t3 ), 'wptests_tax_1' ); 1859 2377 1860 $found = get_terms( 'wptests_tax_1', array( 1861 'pad_counts' => true, 1862 ) ); 2378 $found = get_terms( 2379 'wptests_tax_1', array( 2380 'pad_counts' => true, 2381 ) 2382 ); 1863 2383 1864 2384 $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) ); … … 1893 2413 wp_set_post_terms( $posts[2], $c3, 'category' ); 1894 2414 1895 $terms = get_terms( 'category', array( 1896 'pad_counts' => true, 1897 ) ); 2415 $terms = get_terms( 2416 'category', array( 2417 'pad_counts' => true, 2418 ) 2419 ); 1898 2420 1899 2421 $this->assertEqualSets( array( $c1, $c2, $c3 ), wp_list_pluck( $terms, 'term_id' ) ); … … 1913 2435 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) ); 1914 2436 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) ); 1915 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t2 ) ); 2437 $t3 = self::factory()->term->create( 2438 array( 2439 'taxonomy' => 'wptests_tax2', 2440 'parent' => $t2, 2441 ) 2442 ); 1916 2443 1917 2444 $posts = self::factory()->post->create_many( 3 ); … … 1920 2447 wp_set_object_terms( $posts[2], $t3, 'wptests_tax2' ); 1921 2448 1922 $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array( 1923 'pad_counts' => true, 1924 ) ); 2449 $found = get_terms( 2450 array( 'wptests_tax1', 'wptests_tax2' ), array( 2451 'pad_counts' => true, 2452 ) 2453 ); 1925 2454 1926 2455 $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) ); … … 1949 2478 add_term_meta( $terms[2], 'foo', 'bar' ); 1950 2479 1951 $found = get_terms( 'wptests_tax', array( 1952 'hide_empty' => false, 1953 'include' => $terms, 1954 ) ); 2480 $found = get_terms( 2481 'wptests_tax', array( 2482 'hide_empty' => false, 2483 'include' => $terms, 2484 ) 2485 ); 1955 2486 1956 2487 $num_queries = $wpdb->num_queries; … … 1975 2506 add_term_meta( $terms[2], 'foo', 'bar' ); 1976 2507 1977 $found = get_terms( 'wptests_tax', array( 1978 'hide_empty' => false, 1979 'include' => $terms, 1980 'update_term_meta_cache' => false, 1981 ) ); 2508 $found = get_terms( 2509 'wptests_tax', array( 2510 'hide_empty' => false, 2511 'include' => $terms, 2512 'update_term_meta_cache' => false, 2513 ) 2514 ); 1982 2515 1983 2516 $num_queries = $wpdb->num_queries; … … 2001 2534 add_term_meta( $terms[3], 'foob', 'ar' ); 2002 2535 2003 $found = get_terms( 'wptests_tax', array( 2004 'hide_empty' => false, 2005 'meta_query' => array( 2006 array( 2007 'key' => 'foo', 2008 'value' => 'bar', 2536 $found = get_terms( 2537 'wptests_tax', array( 2538 'hide_empty' => false, 2539 'meta_query' => array( 2540 array( 2541 'key' => 'foo', 2542 'value' => 'bar', 2543 ), 2009 2544 ), 2010 ),2011 'fields' => 'ids',2012 ) );2545 'fields' => 'ids', 2546 ) 2547 ); 2013 2548 2014 2549 $this->assertEqualSets( array( $terms[0], $terms[1] ), $found ); … … 2024 2559 add_term_meta( $terms[0], 'foo', 'ber' ); 2025 2560 2026 $found = get_terms( 'wptests_tax', array( 2027 'hide_empty' => false, 2028 'meta_query' => array( 2029 array( 2030 'key' => 'foo', 2031 'value' => 'bur', 2032 'compare' => '!=', 2561 $found = get_terms( 2562 'wptests_tax', array( 2563 'hide_empty' => false, 2564 'meta_query' => array( 2565 array( 2566 'key' => 'foo', 2567 'value' => 'bur', 2568 'compare' => '!=', 2569 ), 2033 2570 ), 2034 ),2035 'fields' => 'ids',2036 ) );2571 'fields' => 'ids', 2572 ) 2573 ); 2037 2574 2038 2575 $this->assertEqualSets( array( $terms[0] ), $found ); … … 2046 2583 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2047 2584 2048 $found = get_terms( 'wptests_tax', array( 2049 'hide_empty' => false, 2050 'fields' => 'all', 2051 ) ); 2585 $found = get_terms( 2586 'wptests_tax', array( 2587 'hide_empty' => false, 2588 'fields' => 'all', 2589 ) 2590 ); 2052 2591 2053 2592 $this->assertNotEmpty( $found ); … … 2069 2608 2070 2609 // Prime the cache. 2071 get_terms( 'wptests_tax', array( 2072 'hide_empty' => false, 2073 'fields' => 'all', 2074 ) ); 2610 get_terms( 2611 'wptests_tax', array( 2612 'hide_empty' => false, 2613 'fields' => 'all', 2614 ) 2615 ); 2075 2616 2076 2617 $num_queries = $wpdb->num_queries; 2077 2618 2078 $found = get_terms( 'wptests_tax', array( 2079 'hide_empty' => false, 2080 'fields' => 'all', 2081 ) ); 2619 $found = get_terms( 2620 'wptests_tax', array( 2621 'hide_empty' => false, 2622 'fields' => 'all', 2623 ) 2624 ); 2082 2625 2083 2626 $this->assertSame( $num_queries, $wpdb->num_queries ); … … 2099 2642 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2100 2643 2101 $found = get_terms( 'wptests_tax', array( 2102 'hide_empty' => false, 2103 'fields' => 'all', 2104 ) ); 2644 $found = get_terms( 2645 'wptests_tax', array( 2646 'hide_empty' => false, 2647 'fields' => 'all', 2648 ) 2649 ); 2105 2650 2106 2651 $num_queries = $wpdb->num_queries; 2107 $term0 = get_term( $terms[0] );2652 $term0 = get_term( $terms[0] ); 2108 2653 $this->assertSame( $num_queries, $wpdb->num_queries ); 2109 2654 … … 2117 2662 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); 2118 2663 2119 $found = get_terms( 'wptests_tax', array( 2120 'hide_empty' => false, 2121 'fields' => 'id=>parent', 2122 'number' => 2, 2123 'orderby' => 'id', 2124 'order' => 'ASC', 2125 'hierarchical' => true, 2126 ) ); 2664 $found = get_terms( 2665 'wptests_tax', array( 2666 'hide_empty' => false, 2667 'fields' => 'id=>parent', 2668 'number' => 2, 2669 'orderby' => 'id', 2670 'order' => 'ASC', 2671 'hierarchical' => true, 2672 ) 2673 ); 2127 2674 2128 2675 $this->assertSame( array( $terms[0], $terms[1] ), array_keys( $found ) ); … … 2137 2684 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2138 2685 2139 $found = get_terms( 'wptests_tax', array( 2140 'number' => 3, 2141 'offset' => 0, 2142 'hide_empty' => false, 2143 'fields' => 'ids', 2144 ) ); 2686 $found = get_terms( 2687 'wptests_tax', array( 2688 'number' => 3, 2689 'offset' => 0, 2690 'hide_empty' => false, 2691 'fields' => 'ids', 2692 ) 2693 ); 2145 2694 $this->assertEqualSets( $terms, $found ); 2146 2695 } … … 2154 2703 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); 2155 2704 2156 $found = get_terms( 'wptests_tax', array( 2157 'number' => 1, 2158 'offset' => 1, 2159 'hide_empty' => false, 2160 'fields' => 'ids', 2161 'orderby' => 'term_id', 2162 'order' => 'ASC', 2163 ) ); 2705 $found = get_terms( 2706 'wptests_tax', array( 2707 'number' => 1, 2708 'offset' => 1, 2709 'hide_empty' => false, 2710 'fields' => 'ids', 2711 'orderby' => 'term_id', 2712 'order' => 'ASC', 2713 ) 2714 ); 2164 2715 $this->assertEqualSets( array( $terms[1] ), $found ); 2165 2716 } … … 2173 2724 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2174 2725 2175 $found = get_terms( 'wptests_tax', array( 2176 'number' => 2, 2177 'offset' => 1, 2178 'hide_empty' => false, 2179 'fields' => 'ids', 2180 'orderby' => 'term_id', 2181 'order' => 'ASC', 2182 ) ); 2726 $found = get_terms( 2727 'wptests_tax', array( 2728 'number' => 2, 2729 'offset' => 1, 2730 'hide_empty' => false, 2731 'fields' => 'ids', 2732 'orderby' => 'term_id', 2733 'order' => 'ASC', 2734 ) 2735 ); 2183 2736 $this->assertEqualSets( array( $terms[1] ), $found ); 2184 2737 } … … 2192 2745 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2193 2746 2194 $found = get_terms( 'wptests_tax', array( 2195 'number' => 100, 2196 'offset' => 3, 2197 'hide_empty' => false, 2198 'fields' => 'ids', 2199 'orderby' => 'term_id', 2200 'order' => 'ASC', 2201 ) ); 2747 $found = get_terms( 2748 'wptests_tax', array( 2749 'number' => 100, 2750 'offset' => 3, 2751 'hide_empty' => false, 2752 'fields' => 'ids', 2753 'orderby' => 'term_id', 2754 'order' => 'ASC', 2755 ) 2756 ); 2202 2757 $this->assertEqualSets( array(), $found ); 2203 2758 } … … 2210 2765 add_filter( 'get_terms', array( __CLASS__, 'maybe_filter_count' ) ); 2211 2766 2212 $found = get_terms( array( 2213 'hide_empty' => 0, 2214 'fields' => 'count', 2215 ) ); 2767 $found = get_terms( 2768 array( 2769 'hide_empty' => 0, 2770 'fields' => 'count', 2771 ) 2772 ); 2216 2773 2217 2774 remove_filter( 'get_terms', array( __CLASS__, 'maybe_filter_count' ) ); … … 2230 2787 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2231 2788 2232 $term_id = self::factory()->term->create( array( 2233 'name' => '0', 2234 'slug' => '0', 2235 'taxonomy' => 'wptests_tax', 2236 ) ); 2237 2238 $found = get_terms( array( 2239 'taxonomy' => 'wptests_tax', 2240 'hide_empty' => 0, 2241 'slug' => '0', 2242 ) ); 2789 $term_id = self::factory()->term->create( 2790 array( 2791 'name' => '0', 2792 'slug' => '0', 2793 'taxonomy' => 'wptests_tax', 2794 ) 2795 ); 2796 2797 $found = get_terms( 2798 array( 2799 'taxonomy' => 'wptests_tax', 2800 'hide_empty' => 0, 2801 'slug' => '0', 2802 ) 2803 ); 2243 2804 2244 2805 $this->assertEqualSets( array( $term_id ), wp_list_pluck( $found, 'term_id' ) ); … … 2251 2812 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2252 2813 2253 $term_id1 = self::factory()->term->create( array( 2254 'name' => '0', 2255 'slug' => '0', 2256 'taxonomy' => 'wptests_tax', 2257 ) ); 2258 2259 $term_id2 = self::factory()->term->create( array( 2260 'name' => 'Test', 2261 'slug' => 'test', 2262 'taxonomy' => 'wptests_tax', 2263 ) ); 2264 2265 $found = get_terms( array( 2266 'taxonomy' => 'wptests_tax', 2267 'hide_empty' => 0, 2268 'slug' => array( 2269 '0', 2270 'test', 2271 ), 2272 ) ); 2814 $term_id1 = self::factory()->term->create( 2815 array( 2816 'name' => '0', 2817 'slug' => '0', 2818 'taxonomy' => 'wptests_tax', 2819 ) 2820 ); 2821 2822 $term_id2 = self::factory()->term->create( 2823 array( 2824 'name' => 'Test', 2825 'slug' => 'test', 2826 'taxonomy' => 'wptests_tax', 2827 ) 2828 ); 2829 2830 $found = get_terms( 2831 array( 2832 'taxonomy' => 'wptests_tax', 2833 'hide_empty' => 0, 2834 'slug' => array( 2835 '0', 2836 'test', 2837 ), 2838 ) 2839 ); 2273 2840 2274 2841 $this->assertEqualSets( array( $term_id1, $term_id2 ), wp_list_pluck( $found, 'term_id' ) ); … … 2278 2845 $terms = array(); 2279 2846 2280 $terms['parent1'] = self::factory()->term->create( array( 'slug' => 'parent-1', 'name' => 'Parent 1', 'taxonomy' => 'hierarchical_fields' ) ); 2281 $terms['parent2'] = self::factory()->term->create( array( 'slug' => 'parent-2', 'name' => 'Parent 2', 'taxonomy' => 'hierarchical_fields' ) ); 2282 $terms['child1'] = self::factory()->term->create( array( 'slug' => 'child-1', 'name' => 'Child 1', 'taxonomy' => 'hierarchical_fields', 'parent' => $terms['parent1'] ) ); 2283 $terms['child2'] = self::factory()->term->create( array( 'slug' => 'child-2', 'name' => 'Child 2', 'taxonomy' => 'hierarchical_fields', 'parent' => $terms['parent1'] ) ); 2284 $terms['grandchild1'] = self::factory()->term->create( array( 'slug' => 'grandchild-1', 'name' => 'Grandchild 1', 'taxonomy' => 'hierarchical_fields', 'parent' => $terms['child1'] ) ); 2847 $terms['parent1'] = self::factory()->term->create( 2848 array( 2849 'slug' => 'parent-1', 2850 'name' => 'Parent 1', 2851 'taxonomy' => 'hierarchical_fields', 2852 ) 2853 ); 2854 $terms['parent2'] = self::factory()->term->create( 2855 array( 2856 'slug' => 'parent-2', 2857 'name' => 'Parent 2', 2858 'taxonomy' => 'hierarchical_fields', 2859 ) 2860 ); 2861 $terms['child1'] = self::factory()->term->create( 2862 array( 2863 'slug' => 'child-1', 2864 'name' => 'Child 1', 2865 'taxonomy' => 'hierarchical_fields', 2866 'parent' => $terms['parent1'], 2867 ) 2868 ); 2869 $terms['child2'] = self::factory()->term->create( 2870 array( 2871 'slug' => 'child-2', 2872 'name' => 'Child 2', 2873 'taxonomy' => 'hierarchical_fields', 2874 'parent' => $terms['parent1'], 2875 ) 2876 ); 2877 $terms['grandchild1'] = self::factory()->term->create( 2878 array( 2879 'slug' => 'grandchild-1', 2880 'name' => 'Grandchild 1', 2881 'taxonomy' => 'hierarchical_fields', 2882 'parent' => $terms['child1'], 2883 ) 2884 ); 2285 2885 2286 2886 $post_id = self::factory()->post->create(); … … 2300 2900 // - Six (1) 2301 2901 // - Seven 2302 $one_term = wp_insert_term(2902 $one_term = wp_insert_term( 2303 2903 'One', 2304 2904 'category' 2305 2905 ); 2306 $two_term = wp_insert_term(2906 $two_term = wp_insert_term( 2307 2907 'Two', 2308 2908 'category', 2309 2909 array( 2310 'parent' => $one_term['term_id'] 2910 'parent' => $one_term['term_id'], 2311 2911 ) 2312 2912 ); … … 2315 2915 'category', 2316 2916 array( 2317 'parent' => $two_term['term_id'] 2318 ) 2319 ); 2320 $four_term = wp_insert_term(2917 'parent' => $two_term['term_id'], 2918 ) 2919 ); 2920 $four_term = wp_insert_term( 2321 2921 'Four', 2322 2922 'category', 2323 2923 array( 2324 'parent' => $two_term['term_id'] 2325 ) 2326 ); 2327 $five_term = wp_insert_term(2924 'parent' => $two_term['term_id'], 2925 ) 2926 ); 2927 $five_term = wp_insert_term( 2328 2928 'Five', 2329 2929 'category', 2330 2930 array( 2331 'parent' => $one_term['term_id'] 2332 ) 2333 ); 2334 $six_term = wp_insert_term(2931 'parent' => $one_term['term_id'], 2932 ) 2933 ); 2934 $six_term = wp_insert_term( 2335 2935 'Six', 2336 2936 'category', 2337 2937 array( 2338 'parent' => $five_term['term_id'] 2938 'parent' => $five_term['term_id'], 2339 2939 ) 2340 2940 ); … … 2343 2943 'category', 2344 2944 array( 2345 'parent' => $one_term['term_id'] 2945 'parent' => $one_term['term_id'], 2346 2946 ) 2347 2947 ); 2348 2948 2349 2949 // Ensure child terms are not empty 2350 $first_post_id = self::factory()->post->create();2950 $first_post_id = self::factory()->post->create(); 2351 2951 $second_post_id = self::factory()->post->create(); 2352 2952 wp_set_post_terms( $first_post_id, array( $three_term['term_id'] ), 'category' ); … … 2354 2954 2355 2955 return array( 2356 'one_term' => $one_term,2357 'two_term' => $two_term,2956 'one_term' => $one_term, 2957 'two_term' => $two_term, 2358 2958 'three_term' => $three_term, 2359 'four_term' => $four_term,2360 'five_term' => $five_term,2361 'six_term' => $six_term,2362 'seven_term' => $seven_term 2959 'four_term' => $four_term, 2960 'five_term' => $five_term, 2961 'six_term' => $six_term, 2962 'seven_term' => $seven_term, 2363 2963 ); 2364 2964 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)