Changeset 37480
- Timestamp:
- 05/21/2016 05:56:40 PM (8 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term.php
r36056 r37480 493 493 494 494 /** 495 * @ticket 22560496 */497 function test_object_term_cache() {498 $post_id = self::$post_ids[0];499 500 $terms_1 = array('foo', 'bar', 'baz');501 $terms_2 = array('bar', 'bing');502 503 // Cache should be empty after a set.504 $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );505 $this->assertEquals( 3, count($tt_1) );506 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') );507 508 // wp_get_object_terms() does not prime the cache.509 wp_get_object_terms( $post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id') );510 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') );511 512 // get_the_terms() does prime the cache.513 $terms = get_the_terms( $post_id, $this->taxonomy );514 $cache = wp_cache_get( $post_id, $this->taxonomy . '_relationships');515 $this->assertInternalType( 'array', $cache );516 517 // Cache should be empty after a set.518 $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );519 $this->assertEquals( 2, count($tt_2) );520 $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') );521 }522 523 /**524 * @ticket 24189525 */526 function test_object_term_cache_when_term_changes() {527 $post_id = self::$post_ids[0];528 $tag_id = self::factory()->tag->create( array(529 'name' => 'Amaze Tag',530 'description' => 'My Amazing Tag'531 ) );532 533 $tt_1 = wp_set_object_terms( $post_id, $tag_id, 'post_tag' );534 535 $terms = get_the_terms( $post_id, 'post_tag' );536 $this->assertEquals( $tag_id, $terms[0]->term_id );537 $this->assertEquals( 'My Amazing Tag', $terms[0]->description );538 539 $_updated = wp_update_term( $tag_id, 'post_tag', array(540 'description' => 'This description is even more amazing!'541 ) );542 543 $_new_term = get_term( $tag_id, 'post_tag' );544 $this->assertEquals( $tag_id, $_new_term->term_id );545 $this->assertEquals( 'This description is even more amazing!', $_new_term->description );546 547 $terms = get_the_terms( $post_id, 'post_tag' );548 $this->assertEquals( $tag_id, $terms[0]->term_id );549 $this->assertEquals( 'This description is even more amazing!', $terms[0]->description );550 }551 552 /**553 * @ticket 34262554 */555 public function test_get_the_terms_should_not_cache_wp_term_objects() {556 $p = self::$post_ids[0];557 register_taxonomy( 'wptests_tax', 'post' );558 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );559 wp_set_object_terms( $p, $t, 'wptests_tax' );560 561 // Prime the cache.562 $terms = get_the_terms( $p, 'wptests_tax' );563 564 $cached = get_object_term_cache( $p, 'wptests_tax' );565 566 $this->assertNotEmpty( $cached );567 $this->assertSame( $t, (int) $cached[0]->term_id );568 $this->assertNotInstanceOf( 'WP_Term', $cached[0] );569 }570 571 /**572 * @ticket 34262573 */574 public function test_get_the_terms_should_return_wp_term_objects_from_cache() {575 $p = self::$post_ids[0];576 register_taxonomy( 'wptests_tax', 'post' );577 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );578 wp_set_object_terms( $p, $t, 'wptests_tax' );579 580 // Prime the cache.581 get_the_terms( $p, 'wptests_tax' );582 583 $cached = get_the_terms( $p, 'wptests_tax' );584 585 $this->assertNotEmpty( $cached );586 $this->assertSame( $t, (int) $cached[0]->term_id );587 $this->assertInstanceOf( 'WP_Term', $cached[0] );588 }589 590 /**591 * @ticket 31086592 */593 public function test_get_the_terms_should_return_zero_indexed_array_when_cache_is_empty() {594 register_taxonomy( 'wptests_tax', 'post' );595 $p = self::$post_ids[0];596 wp_set_object_terms( $p, array( 'foo', 'bar' ), 'wptests_tax' );597 598 $found = get_the_terms( $p, 'wptests_tax' );599 600 $this->assertEqualSets( array( 0, 1 ), array_keys( $found ) );601 }602 603 /**604 * @ticket 31086605 */606 public function test_get_the_terms_should_return_zero_indexed_array_when_cache_is_primed() {607 register_taxonomy( 'wptests_tax', 'post' );608 $p = self::$post_ids[0];609 wp_set_object_terms( $p, array( 'foo', 'bar' ), 'wptests_tax' );610 611 // Prime cache.612 update_object_term_cache( array( $p ), array( 'post' ) );613 614 $found = get_the_terms( $p, 'wptests_tax' );615 616 $this->assertEqualSets( array( 0, 1 ), array_keys( $found ) );617 }618 619 /**620 * @ticket 35180621 * @ticket 28922622 */623 public function test_get_the_terms_should_return_results_ordered_by_name_when_pulling_from_cache() {624 register_taxonomy( 'wptests_tax', 'post' );625 $p = self::$post_ids[0];626 627 $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'fff' ) );628 $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'aaa' ) );629 $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'zzz' ) );630 631 wp_set_object_terms( $p, array( $t1, $t2, $t3 ), 'wptests_tax' );632 update_object_term_cache( $p, 'post' );633 634 $found = get_the_terms( $p, 'wptests_tax' );635 636 $this->assertSame( array( $t2, $t1, $t3 ), wp_list_pluck( $found, 'term_id' ) );637 }638 639 /**640 495 * @ticket 19205 641 496 */ … … 648 503 $this->assertWPError( $cat_id2 ); 649 504 } 650 651 /**652 * @ticket 34723653 */654 function test_get_the_terms_should_return_wp_error_when_taxonomy_is_unregistered() {655 $p = self::$post_ids[0];656 $terms = get_the_terms( $p, 'this-taxonomy-does-not-exist' );657 $this->assertTrue( is_wp_error( $terms ) );658 }659 505 }
Note: See TracChangeset
for help on using the changeset viewer.