Changeset 42343 for trunk/tests/phpunit/tests/taxonomy.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/taxonomy.php (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/taxonomy.php
r42211 r42343 6 6 class Tests_Taxonomy extends WP_UnitTestCase { 7 7 function test_get_post_taxonomies() { 8 $this->assertEquals( array('category', 'post_tag', 'post_format'), get_object_taxonomies('post'));8 $this->assertEquals( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) ); 9 9 } 10 10 11 11 function test_get_link_taxonomies() { 12 $this->assertEquals( array('link_category'), get_object_taxonomies('link'));12 $this->assertEquals( array( 'link_category' ), get_object_taxonomies( 'link' ) ); 13 13 } 14 14 … … 18 18 function test_get_unknown_taxonomies() { 19 19 // taxonomies for an unknown object type 20 $this->assertEquals( array(), get_object_taxonomies( rand_str()) );21 $this->assertEquals( array(), get_object_taxonomies( '') );22 $this->assertEquals( array(), get_object_taxonomies( 0) );23 $this->assertEquals( array(), get_object_taxonomies( NULL) );20 $this->assertEquals( array(), get_object_taxonomies( rand_str() ) ); 21 $this->assertEquals( array(), get_object_taxonomies( '' ) ); 22 $this->assertEquals( array(), get_object_taxonomies( 0 ) ); 23 $this->assertEquals( array(), get_object_taxonomies( null ) ); 24 24 } 25 25 26 26 function test_get_post_taxonomy() { 27 foreach ( get_object_taxonomies( 'post') as $taxonomy ) {28 $tax = get_taxonomy( $taxonomy);27 foreach ( get_object_taxonomies( 'post' ) as $taxonomy ) { 28 $tax = get_taxonomy( $taxonomy ); 29 29 // should return an object with the correct taxonomy object type 30 30 $this->assertTrue( is_object( $tax ) ); … … 60 60 61 61 $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ); 62 $link = get_category_link( 1 );62 $link = get_category_link( 1 ); 63 63 $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $taxes['category'] ); 64 64 } … … 71 71 $output = ob_get_clean(); 72 72 73 $link = get_category_link( 1 );73 $link = get_category_link( 1 ); 74 74 $expected = 'Categories: <a href="' . $link . '">Uncategorized</a>.'; 75 75 $this->assertEquals( $expected, $output ); … … 82 82 $post_id = self::factory()->post->create(); 83 83 84 $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '%2$s' ) ) ); 84 $output = get_echo( 85 'the_taxonomies', array( 86 array( 87 'post' => $post_id, 88 'term_template' => '%2$s', 89 ), 90 ) 91 ); 85 92 $this->assertEquals( 'Categories: Uncategorized.', $output ); 86 93 87 $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ) ); 88 $link = get_category_link( 1 ); 94 $output = get_echo( 95 'the_taxonomies', array( 96 array( 97 'post' => $post_id, 98 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>', 99 ), 100 ) 101 ); 102 $link = get_category_link( 1 ); 89 103 $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $output ); 90 104 } 91 105 92 106 function test_get_link_taxonomy() { 93 foreach ( get_object_taxonomies( 'link') as $taxonomy ) {94 $tax = get_taxonomy( $taxonomy);107 foreach ( get_object_taxonomies( 'link' ) as $taxonomy ) { 108 $tax = get_taxonomy( $taxonomy ); 95 109 // should return an object with the correct taxonomy object type 96 $this->assertTrue( is_object( $tax) );110 $this->assertTrue( is_object( $tax ) ); 97 111 $this->assertTrue( is_array( $tax->object_type ) ); 98 112 $this->assertEquals( array( 'link' ), $tax->object_type ); … … 101 115 102 116 function test_taxonomy_exists_known() { 103 $this->assertTrue( taxonomy_exists( 'category') );104 $this->assertTrue( taxonomy_exists( 'post_tag') );105 $this->assertTrue( taxonomy_exists( 'link_category') );117 $this->assertTrue( taxonomy_exists( 'category' ) ); 118 $this->assertTrue( taxonomy_exists( 'post_tag' ) ); 119 $this->assertTrue( taxonomy_exists( 'link_category' ) ); 106 120 } 107 121 108 122 function test_taxonomy_exists_unknown() { 109 $this->assertFalse( taxonomy_exists( rand_str()) );110 $this->assertFalse( taxonomy_exists( '') );111 $this->assertFalse( taxonomy_exists( 0) );112 $this->assertFalse( taxonomy_exists( NULL) );123 $this->assertFalse( taxonomy_exists( rand_str() ) ); 124 $this->assertFalse( taxonomy_exists( '' ) ); 125 $this->assertFalse( taxonomy_exists( 0 ) ); 126 $this->assertFalse( taxonomy_exists( null ) ); 113 127 } 114 128 115 129 function test_is_taxonomy_hierarchical() { 116 $this->assertTrue( is_taxonomy_hierarchical( 'category') );117 $this->assertFalse( is_taxonomy_hierarchical( 'post_tag') );118 $this->assertFalse( is_taxonomy_hierarchical( 'link_category') );130 $this->assertTrue( is_taxonomy_hierarchical( 'category' ) ); 131 $this->assertFalse( is_taxonomy_hierarchical( 'post_tag' ) ); 132 $this->assertFalse( is_taxonomy_hierarchical( 'link_category' ) ); 119 133 } 120 134 121 135 function test_is_taxonomy_hierarchical_unknown() { 122 $this->assertFalse( is_taxonomy_hierarchical( rand_str()) );123 $this->assertFalse( is_taxonomy_hierarchical( '') );124 $this->assertFalse( is_taxonomy_hierarchical( 0) );125 $this->assertFalse( is_taxonomy_hierarchical( NULL) );136 $this->assertFalse( is_taxonomy_hierarchical( rand_str() ) ); 137 $this->assertFalse( is_taxonomy_hierarchical( '' ) ); 138 $this->assertFalse( is_taxonomy_hierarchical( 0 ) ); 139 $this->assertFalse( is_taxonomy_hierarchical( null ) ); 126 140 } 127 141 … … 130 144 // make up a new taxonomy name, and ensure it's unused 131 145 $tax = rand_str(); 132 $this->assertFalse( taxonomy_exists( $tax) );146 $this->assertFalse( taxonomy_exists( $tax ) ); 133 147 134 148 register_taxonomy( $tax, 'post' ); 135 $this->assertTrue( taxonomy_exists( $tax) );136 $this->assertFalse( is_taxonomy_hierarchical( $tax) );149 $this->assertTrue( taxonomy_exists( $tax ) ); 150 $this->assertFalse( is_taxonomy_hierarchical( $tax ) ); 137 151 138 152 // clean up 139 unset( $GLOBALS['wp_taxonomies'][$tax]);153 unset( $GLOBALS['wp_taxonomies'][ $tax ] ); 140 154 } 141 155 … … 144 158 // make up a new taxonomy name, and ensure it's unused 145 159 $tax = rand_str(); 146 $this->assertFalse( taxonomy_exists( $tax) );147 148 register_taxonomy( $tax, 'post', array( 'hierarchical'=>true) );149 $this->assertTrue( taxonomy_exists( $tax) );150 $this->assertTrue( is_taxonomy_hierarchical( $tax) );160 $this->assertFalse( taxonomy_exists( $tax ) ); 161 162 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 163 $this->assertTrue( taxonomy_exists( $tax ) ); 164 $this->assertTrue( is_taxonomy_hierarchical( $tax ) ); 151 165 152 166 // clean up 153 unset( $GLOBALS['wp_taxonomies'][$tax]);167 unset( $GLOBALS['wp_taxonomies'][ $tax ] ); 154 168 } 155 169 … … 176 190 */ 177 191 public function test_register_taxonomy_show_in_quick_edit_should_default_to_value_of_show_ui() { 178 register_taxonomy( 'wptests_tax_1', 'post', array( 179 'show_ui' => true, 180 ) ); 181 182 register_taxonomy( 'wptests_tax_2', 'post', array( 183 'show_ui' => false, 184 ) ); 192 register_taxonomy( 193 'wptests_tax_1', 'post', array( 194 'show_ui' => true, 195 ) 196 ); 197 198 register_taxonomy( 199 'wptests_tax_2', 'post', array( 200 'show_ui' => false, 201 ) 202 ); 185 203 186 204 $tax_1 = get_taxonomy( 'wptests_tax_1' ); … … 197 215 // Create a taxonomy to test with 198 216 $tax = 'test_tax'; 199 $this->assertFalse( taxonomy_exists( $tax) );217 $this->assertFalse( taxonomy_exists( $tax ) ); 200 218 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 201 219 … … 235 253 $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) ); 236 254 237 unset( $GLOBALS['wp_taxonomies'][$tax]);255 unset( $GLOBALS['wp_taxonomies'][ $tax ] ); 238 256 _unregister_post_type( $post_type ); 239 257 … … 263 281 264 282 public function test_get_objects_in_term_should_return_objects_ids() { 265 $tag_id = self::factory()->tag->create();266 $cat_id = self::factory()->category->create();267 $posts_with_tag = array();283 $tag_id = self::factory()->tag->create(); 284 $cat_id = self::factory()->category->create(); 285 $posts_with_tag = array(); 268 286 $posts_with_category = array(); 269 287 … … 298 316 register_taxonomy( 'wptests_tax', 'post' ); 299 317 300 $posts = self::factory()->post->create_many( 2 ); 301 $term_id = self::factory()->term->create( array( 302 'taxonomy' => 'wptests_tax', 303 ) ); 318 $posts = self::factory()->post->create_many( 2 ); 319 $term_id = self::factory()->term->create( 320 array( 321 'taxonomy' => 'wptests_tax', 322 ) 323 ); 304 324 305 325 wp_set_object_terms( $posts[1], $term_id, 'wptests_tax' ); … … 321 341 register_taxonomy( 'wptests_tax', 'post' ); 322 342 323 $posts = self::factory()->post->create_many( 2 ); 324 $term_id = self::factory()->term->create( array( 325 'taxonomy' => 'wptests_tax', 326 ) ); 343 $posts = self::factory()->post->create_many( 2 ); 344 $term_id = self::factory()->term->create( 345 array( 346 'taxonomy' => 'wptests_tax', 347 ) 348 ); 327 349 328 350 wp_set_object_terms( $posts[1], $term_id, 'wptests_tax' ); … … 344 366 register_taxonomy( 'wptests_tax', 'post' ); 345 367 346 $posts = self::factory()->post->create_many( 2 ); 347 $term_id = self::factory()->term->create( array( 348 'taxonomy' => 'wptests_tax', 349 ) ); 368 $posts = self::factory()->post->create_many( 2 ); 369 $term_id = self::factory()->term->create( 370 array( 371 'taxonomy' => 'wptests_tax', 372 ) 373 ); 350 374 351 375 wp_set_object_terms( $posts[1], $term_id, 'wptests_tax' ); … … 380 404 function test_insert_category_create() { 381 405 $cat = array( 382 'cat_ID' => 0,406 'cat_ID' => 0, 383 407 'taxonomy' => 'category', 384 'cat_name' => 'test1' 408 'cat_name' => 'test1', 385 409 ); 386 410 $this->assertTrue( is_numeric( wp_insert_category( $cat, true ) ) ); … … 389 413 function test_insert_category_update() { 390 414 $cat = array( 391 'cat_ID' => 1,415 'cat_ID' => 1, 392 416 'taxonomy' => 'category', 393 'cat_name' => 'Updated Name' 417 'cat_name' => 'Updated Name', 394 418 ); 395 419 $this->assertEquals( 1, wp_insert_category( $cat ) ); … … 398 422 function test_insert_category_force_error_handle() { 399 423 $cat = array( 400 'cat_ID' => 0,424 'cat_ID' => 0, 401 425 'taxonomy' => 'force_error', 402 'cat_name' => 'Error' 426 'cat_name' => 'Error', 403 427 ); 404 428 $this->assertTrue( is_a( wp_insert_category( $cat, true ), 'WP_Error' ) ); … … 407 431 function test_insert_category_force_error_no_handle() { 408 432 $cat = array( 409 'cat_ID' => 0,433 'cat_ID' => 0, 410 434 'taxonomy' => 'force_error', 411 'cat_name' => 'Error' 435 'cat_name' => 'Error', 412 436 ); 413 437 $this->assertEquals( 0, wp_insert_category( $cat, false ) ); … … 416 440 public function test_get_ancestors_taxonomy_non_hierarchical() { 417 441 register_taxonomy( 'wptests_tax', 'post' ); 418 $t = self::factory()->term->create( array( 419 'taxonomy' => 'wptests_tax', 420 ) ); 442 $t = self::factory()->term->create( 443 array( 444 'taxonomy' => 'wptests_tax', 445 ) 446 ); 421 447 422 448 $this->assertSame( array(), get_ancestors( $t, 'wptests_tax' ) ); … … 425 451 426 452 public function test_get_ancestors_taxonomy() { 427 register_taxonomy( 'wptests_tax', 'post', array( 428 'hierarchical' => true, 429 ) ); 430 $t1 = self::factory()->term->create( array( 431 'taxonomy' => 'wptests_tax', 432 ) ); 433 $t2 = self::factory()->term->create( array( 434 'taxonomy' => 'wptests_tax', 435 'parent' => $t1, 436 ) ); 437 $t3 = self::factory()->term->create( array( 438 'taxonomy' => 'wptests_tax', 439 'parent' => $t2, 440 ) ); 441 $t4 = self::factory()->term->create( array( 442 'taxonomy' => 'wptests_tax', 443 'parent' => $t1, 444 ) ); 453 register_taxonomy( 454 'wptests_tax', 'post', array( 455 'hierarchical' => true, 456 ) 457 ); 458 $t1 = self::factory()->term->create( 459 array( 460 'taxonomy' => 'wptests_tax', 461 ) 462 ); 463 $t2 = self::factory()->term->create( 464 array( 465 'taxonomy' => 'wptests_tax', 466 'parent' => $t1, 467 ) 468 ); 469 $t3 = self::factory()->term->create( 470 array( 471 'taxonomy' => 'wptests_tax', 472 'parent' => $t2, 473 ) 474 ); 475 $t4 = self::factory()->term->create( 476 array( 477 'taxonomy' => 'wptests_tax', 478 'parent' => $t1, 479 ) 480 ); 445 481 446 482 $this->assertEqualSets( array( $t2, $t1 ), get_ancestors( $t3, 'wptests_tax' ) ); … … 450 486 public function test_get_ancestors_post_type_non_hierarchical() { 451 487 register_post_type( 'wptests_pt' ); 452 $p = self::factory()->post->create( array( 453 'taxonomy' => 'wptests_pt', 454 ) ); 488 $p = self::factory()->post->create( 489 array( 490 'taxonomy' => 'wptests_pt', 491 ) 492 ); 455 493 456 494 $this->assertEqualSets( array(), get_ancestors( $p, 'wptests_tax' ) ); … … 458 496 459 497 public function test_get_ancestors_post_type() { 460 register_post_type( 'wptests_pt', array( 461 'hierarchical' => true, 462 ) ); 463 $p1 = self::factory()->post->create( array( 464 'post_type' => 'wptests_pt', 465 ) ); 466 $p2 = self::factory()->post->create( array( 467 'post_type' => 'wptests_pt', 468 'post_parent' => $p1, 469 ) ); 470 $p3 = self::factory()->post->create( array( 471 'post_type' => 'wptests_pt', 472 'post_parent' => $p2, 473 ) ); 474 $p4 = self::factory()->post->create( array( 475 'post_type' => 'wptests_pt', 476 'post_parent' => $p1, 477 ) ); 498 register_post_type( 499 'wptests_pt', array( 500 'hierarchical' => true, 501 ) 502 ); 503 $p1 = self::factory()->post->create( 504 array( 505 'post_type' => 'wptests_pt', 506 ) 507 ); 508 $p2 = self::factory()->post->create( 509 array( 510 'post_type' => 'wptests_pt', 511 'post_parent' => $p1, 512 ) 513 ); 514 $p3 = self::factory()->post->create( 515 array( 516 'post_type' => 'wptests_pt', 517 'post_parent' => $p2, 518 ) 519 ); 520 $p4 = self::factory()->post->create( 521 array( 522 'post_type' => 'wptests_pt', 523 'post_parent' => $p1, 524 ) 525 ); 478 526 479 527 $this->assertEqualSets( array( $p2, $p1 ), get_ancestors( $p3, 'wptests_pt' ) ); … … 485 533 */ 486 534 public function test_get_ancestors_taxonomy_post_type_conflict_resource_type_taxonomy() { 487 register_post_type( 'wptests_conflict', array( 488 'hierarchical' => true, 489 ) ); 490 $p1 = self::factory()->post->create( array( 491 'post_type' => 'wptests_conflict', 492 ) ); 493 $p2 = self::factory()->post->create( array( 494 'post_type' => 'wptests_conflict', 495 'post_parent' => $p1, 496 ) ); 497 498 register_taxonomy( 'wptests_conflict', 'post', array( 499 'hierarchical' => true, 500 ) ); 501 $t1 = self::factory()->term->create( array( 502 'taxonomy' => 'wptests_conflict', 503 ) ); 504 $t2 = self::factory()->term->create( array( 505 'taxonomy' => 'wptests_conflict', 506 'parent' => $t1, 507 ) ); 535 register_post_type( 536 'wptests_conflict', array( 537 'hierarchical' => true, 538 ) 539 ); 540 $p1 = self::factory()->post->create( 541 array( 542 'post_type' => 'wptests_conflict', 543 ) 544 ); 545 $p2 = self::factory()->post->create( 546 array( 547 'post_type' => 'wptests_conflict', 548 'post_parent' => $p1, 549 ) 550 ); 551 552 register_taxonomy( 553 'wptests_conflict', 'post', array( 554 'hierarchical' => true, 555 ) 556 ); 557 $t1 = self::factory()->term->create( 558 array( 559 'taxonomy' => 'wptests_conflict', 560 ) 561 ); 562 $t2 = self::factory()->term->create( 563 array( 564 'taxonomy' => 'wptests_conflict', 565 'parent' => $t1, 566 ) 567 ); 508 568 509 569 $this->assertEqualSets( array( $p1 ), get_ancestors( $p2, 'wptests_conflict', 'post_type' ) ); … … 517 577 */ 518 578 public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxname_query_var() { 519 register_taxonomy( 'wptests_tax', 'post', array( 520 'publicly_queryable' => false, 521 ) ); 522 523 $t = self::factory()->term->create_and_get( array( 524 'taxonomy' => 'wptests_tax', 525 ) ); 579 register_taxonomy( 580 'wptests_tax', 'post', array( 581 'publicly_queryable' => false, 582 ) 583 ); 584 585 $t = self::factory()->term->create_and_get( 586 array( 587 'taxonomy' => 'wptests_tax', 588 ) 589 ); 526 590 527 591 $p = self::factory()->post->create(); … … 539 603 global $wp; 540 604 541 register_taxonomy( 'wptests_tax', 'post', array( 542 'publicly_queryable' => false, 543 ) ); 544 $t = $this->factory->term->create_and_get( array( 545 'taxonomy' => 'wptests_tax', 546 ) ); 605 register_taxonomy( 606 'wptests_tax', 'post', array( 607 'publicly_queryable' => false, 608 ) 609 ); 610 $t = $this->factory->term->create_and_get( 611 array( 612 'taxonomy' => 'wptests_tax', 613 ) 614 ); 547 615 548 616 $p = $this->factory->post->create(); … … 572 640 */ 573 641 public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() { 574 register_taxonomy( 'wptests_tax', 'post', array( 575 'publicly_queryable' => false, 576 ) ); 577 578 $t = self::factory()->term->create_and_get( array( 579 'taxonomy' => 'wptests_tax', 580 ) ); 642 register_taxonomy( 643 'wptests_tax', 'post', array( 644 'publicly_queryable' => false, 645 ) 646 ); 647 648 $t = self::factory()->term->create_and_get( 649 array( 650 'taxonomy' => 'wptests_tax', 651 ) 652 ); 581 653 582 654 $p = self::factory()->post->create(); … … 592 664 */ 593 665 public function test_public_taxonomy_should_be_publicly_queryable() { 594 register_taxonomy( 'wptests_tax', 'post', array( 595 'public' => true, 596 ) ); 666 register_taxonomy( 667 'wptests_tax', 'post', array( 668 'public' => true, 669 ) 670 ); 597 671 598 672 $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) ); 599 673 600 $t = self::factory()->term->create_and_get( array( 601 'taxonomy' => 'wptests_tax', 602 ) ); 674 $t = self::factory()->term->create_and_get( 675 array( 676 'taxonomy' => 'wptests_tax', 677 ) 678 ); 603 679 604 680 $p = self::factory()->post->create(); … … 614 690 */ 615 691 public function test_private_taxonomy_should_not_be_publicly_queryable() { 616 register_taxonomy( 'wptests_tax', 'post', array( 617 'public' => false, 618 ) ); 692 register_taxonomy( 693 'wptests_tax', 'post', array( 694 'public' => false, 695 ) 696 ); 619 697 620 698 $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => false ) ) ); 621 699 622 $t = self::factory()->term->create_and_get( array( 623 'taxonomy' => 'wptests_tax', 624 ) ); 700 $t = self::factory()->term->create_and_get( 701 array( 702 'taxonomy' => 'wptests_tax', 703 ) 704 ); 625 705 626 706 $p = self::factory()->post->create(); … … 636 716 */ 637 717 public function test_private_taxonomy_should_be_overridden_by_publicly_queryable() { 638 register_taxonomy( 'wptests_tax', 'post', array( 639 'public' => false, 640 'publicly_queryable' => true, 641 ) ); 718 register_taxonomy( 719 'wptests_tax', 'post', array( 720 'public' => false, 721 'publicly_queryable' => true, 722 ) 723 ); 642 724 643 725 $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) ); 644 726 645 $t = self::factory()->term->create_and_get( array( 646 'taxonomy' => 'wptests_tax', 647 ) ); 727 $t = self::factory()->term->create_and_get( 728 array( 729 'taxonomy' => 'wptests_tax', 730 ) 731 ); 648 732 649 733 $p = self::factory()->post->create(); … … 659 743 */ 660 744 public function test_query_var_should_be_forced_to_false_for_non_public_taxonomy() { 661 register_taxonomy( 'wptests_tax', 'post', array( 662 'public' => false, 663 'query_var' => true, 664 ) ); 745 register_taxonomy( 746 'wptests_tax', 'post', array( 747 'public' => false, 748 'query_var' => true, 749 ) 750 ); 665 751 666 752 $tax = get_taxonomy( 'wptests_tax' ); … … 713 799 global $wp_rewrite; 714 800 715 register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar', 'rewrite' => true ) ); 801 register_taxonomy( 802 'foo', 'post', array( 803 'query_var' => 'bar', 804 'rewrite' => true, 805 ) 806 ); 716 807 717 808 $this->assertInternalType( 'array', $wp_rewrite->extra_permastructs['foo'] ); 718 809 $this->assertTrue( unregister_taxonomy( 'foo' ) ); 719 $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) );810 $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) ); 720 811 } 721 812 … … 801 892 $term_name = 'bar'; 802 893 803 register_taxonomy( $taxonomy_name, array( 'post' ), array( 804 'hierarchical' => false, 805 'meta_box_cb' => 'post_categories_meta_box', 806 ) ); 807 $post = self::factory()->post->create_and_get( array( 808 'post_type' => 'post', 809 ) ); 810 811 $term_id = self::factory()->term->create_object( array( 812 'name' => $term_name, 813 'taxonomy' => $taxonomy_name, 814 ) ); 894 register_taxonomy( 895 $taxonomy_name, array( 'post' ), array( 896 'hierarchical' => false, 897 'meta_box_cb' => 'post_categories_meta_box', 898 ) 899 ); 900 $post = self::factory()->post->create_and_get( 901 array( 902 'post_type' => 'post', 903 ) 904 ); 905 906 $term_id = self::factory()->term->create_object( 907 array( 908 'name' => $term_name, 909 'taxonomy' => $taxonomy_name, 910 ) 911 ); 815 912 816 913 wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); 817 $updated_post_id = edit_post( array( 818 'post_ID' => $post->ID, 819 'post_type' => 'post', 820 'tax_input' => array( 821 $taxonomy_name => array( 822 (string) $term_id // Cast term_id as string to match whats sent in WP Admin. 914 $updated_post_id = edit_post( 915 array( 916 'post_ID' => $post->ID, 917 'post_type' => 'post', 918 'tax_input' => array( 919 $taxonomy_name => array( 920 (string) $term_id, // Cast term_id as string to match whats sent in WP Admin. 921 ), 823 922 ), 824 ) ,825 ) );826 827 $terms_obj = get_the_terms( $updated_post_id, $taxonomy_name );923 ) 924 ); 925 926 $terms_obj = get_the_terms( $updated_post_id, $taxonomy_name ); 828 927 $problematic_term = current( wp_list_pluck( $terms_obj, 'name' ) ); 829 928
Note: See TracChangeset
for help on using the changeset viewer.