Changeset 27104
- Timestamp:
- 02/06/2014 05:19:05 AM (11 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term.php
r27102 r27104 568 568 $this->assertEquals( 0, $count ); 569 569 } 570 571 /**572 * @ticket 22526573 */574 function test_get_taxonomy_last_changed() {575 $last_changed = get_taxonomy_last_changed( 'category' );576 $last_changed_cache = wp_cache_get( 'last_changed', 'category' );577 $this->assertEquals( $last_changed, $last_changed_cache );578 wp_cache_delete( 'last_changed', 'category' );579 $this->assertEquals( $last_changed, $last_changed_cache );580 $last_changed = get_taxonomy_last_changed( 'category' );581 $this->assertNotEquals( $last_changed, $last_changed_cache );582 583 $last_changed2 = get_taxonomy_last_changed( 'category' );584 $this->factory->category->create();585 $last_changed3 = get_taxonomy_last_changed( 'category' );586 $this->assertNotEquals( $last_changed2, $last_changed3 );587 }588 589 /**590 * @ticket 22526591 */592 function test_set_taxonomy_last_changed() {593 $last_changed1 = set_taxonomy_last_changed( 'category' );594 $last_changed2 = set_taxonomy_last_changed( 'category' );595 $this->assertNotEquals( $last_changed1, $last_changed2 );596 597 $last_changed3 = set_taxonomy_last_changed( 'category' );598 $last_changed4 = get_taxonomy_last_changed( 'category' );599 $this->assertEquals( $last_changed3, $last_changed4 );600 }601 602 /**603 * @ticket 22526604 */605 function test_post_taxonomy_is_fresh() {606 $post_id = $this->factory->post->create();607 $term_id = $this->factory->category->create( array( 'name' => 'Foo' ) );608 wp_set_post_categories( $post_id, $term_id );609 610 $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) );611 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );612 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );613 614 wp_update_term( $term_id, 'category', array( 'name' => 'Bar' ) );615 616 $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) );617 get_the_category( $post_id );618 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );619 }620 621 /**622 * @ticket 22526623 */624 function test_category_name_change() {625 $term = $this->factory->category->create_and_get( array( 'name' => 'Foo' ) );626 $post_id = $this->factory->post->create();627 wp_set_post_categories( $post_id, $term->term_id );628 629 $post = get_post( $post_id );630 $cats1 = get_the_category( $post->ID );631 $this->assertEquals( $term->name, reset( $cats1 )->name );632 633 wp_update_term( $term->term_id, 'category', array( 'name' => 'Bar' ) );634 $cats2 = get_the_category( $post->ID );635 $this->assertNotEquals( $term->name, reset( $cats2 )->name );636 }637 638 function test_hierachy_invalidation() {639 $tax = 'burrito';640 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );641 $this->assertTrue( get_taxonomy( $tax )->hierarchical );642 643 $step = 1;644 $parent_id = 0;645 $children = 0;646 647 foreach ( range( 1, 99 ) as $i ) {648 switch ( $step ) {649 case 1:650 $parent = wp_insert_term( 'Parent' . $i, $tax );651 $parent_id = $parent['term_id'];652 break;653 case 2:654 $parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) );655 $parent_id = $parent['term_id'];656 $children++;657 break;658 case 3:659 wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) );660 $parent_id = 0;661 $children++;662 break;663 }664 665 $terms = get_terms( $tax, array( 'hide_empty' => false ) );666 $this->assertEquals( $i, count( $terms ) );667 if ( 1 < $i ) {668 $hierarchy = _get_term_hierarchy( $tax );669 $this->assertNotEmpty( $hierarchy );670 $this->assertEquals( $children, count( $hierarchy, COUNT_RECURSIVE ) - count( $hierarchy ) );671 }672 673 if ( $i % 3 === 0 ) {674 $step = 1;675 } else {676 $step++;677 }678 }679 680 _unregister_taxonomy( $tax );681 }682 570 } -
trunk/tests/phpunit/tests/term/cache.php
r27103 r27104 28 28 29 29 $this->assertEquals( array( $term_id1 => array( $term_id1_child ), $term_id2 => array( $term_id2_child ) ), $hierarchy ); 30 } 30 31 32 /** 33 * @ticket 22526 34 */ 35 function test_get_taxonomy_last_changed() { 36 $last_changed = get_taxonomy_last_changed( 'category' ); 37 $last_changed_cache = wp_cache_get( 'last_changed', 'category' ); 38 $this->assertEquals( $last_changed, $last_changed_cache ); 39 wp_cache_delete( 'last_changed', 'category' ); 40 $this->assertEquals( $last_changed, $last_changed_cache ); 41 $last_changed = get_taxonomy_last_changed( 'category' ); 42 $this->assertNotEquals( $last_changed, $last_changed_cache ); 43 44 $last_changed2 = get_taxonomy_last_changed( 'category' ); 45 $this->factory->category->create(); 46 $last_changed3 = get_taxonomy_last_changed( 'category' ); 47 $this->assertNotEquals( $last_changed2, $last_changed3 ); 48 } 49 50 /** 51 * @ticket 22526 52 */ 53 function test_set_taxonomy_last_changed() { 54 $last_changed1 = set_taxonomy_last_changed( 'category' ); 55 $last_changed2 = set_taxonomy_last_changed( 'category' ); 56 $this->assertNotEquals( $last_changed1, $last_changed2 ); 57 58 $last_changed3 = set_taxonomy_last_changed( 'category' ); 59 $last_changed4 = get_taxonomy_last_changed( 'category' ); 60 $this->assertEquals( $last_changed3, $last_changed4 ); 61 } 62 63 /** 64 * @ticket 22526 65 */ 66 function test_post_taxonomy_is_fresh() { 67 $post_id = $this->factory->post->create(); 68 $term_id = $this->factory->category->create( array( 'name' => 'Foo' ) ); 69 wp_set_post_categories( $post_id, $term_id ); 70 71 $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) ); 72 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) ); 73 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) ); 74 75 wp_update_term( $term_id, 'category', array( 'name' => 'Bar' ) ); 76 77 $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) ); 78 get_the_category( $post_id ); 79 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) ); 80 } 81 82 /** 83 * @ticket 22526 84 */ 85 function test_category_name_change() { 86 $term = $this->factory->category->create_and_get( array( 'name' => 'Foo' ) ); 87 $post_id = $this->factory->post->create(); 88 wp_set_post_categories( $post_id, $term->term_id ); 89 90 $post = get_post( $post_id ); 91 $cats1 = get_the_category( $post->ID ); 92 $this->assertEquals( $term->name, reset( $cats1 )->name ); 93 94 wp_update_term( $term->term_id, 'category', array( 'name' => 'Bar' ) ); 95 $cats2 = get_the_category( $post->ID ); 96 $this->assertNotEquals( $term->name, reset( $cats2 )->name ); 97 } 98 99 function test_hierachy_invalidation() { 100 $tax = 'burrito'; 101 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 102 $this->assertTrue( get_taxonomy( $tax )->hierarchical ); 103 104 $step = 1; 105 $parent_id = 0; 106 $children = 0; 107 108 foreach ( range( 1, 99 ) as $i ) { 109 switch ( $step ) { 110 case 1: 111 $parent = wp_insert_term( 'Parent' . $i, $tax ); 112 $parent_id = $parent['term_id']; 113 break; 114 case 2: 115 $parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) ); 116 $parent_id = $parent['term_id']; 117 $children++; 118 break; 119 case 3: 120 wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) ); 121 $parent_id = 0; 122 $children++; 123 break; 124 } 125 126 $terms = get_terms( $tax, array( 'hide_empty' => false ) ); 127 $this->assertEquals( $i, count( $terms ) ); 128 if ( 1 < $i ) { 129 $hierarchy = _get_term_hierarchy( $tax ); 130 $this->assertNotEmpty( $hierarchy ); 131 $this->assertEquals( $children, count( $hierarchy, COUNT_RECURSIVE ) - count( $hierarchy ) ); 132 } 133 134 if ( $i % 3 === 0 ) { 135 $step = 1; 136 } else { 137 $step++; 138 } 139 } 140 141 _unregister_taxonomy( $tax ); 31 142 } 32 143 }
Note: See TracChangeset
for help on using the changeset viewer.