Changeset 30113
- Timestamp:
- 10/30/2014 04:15:03 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/getTerms.php
r30107 r30113 15 15 * @ticket 23326 16 16 */ 17 function test_get_terms_cache() {17 public function test_get_terms_cache() { 18 18 global $wpdb; 19 19 20 $posts = $this->factory->post->create_many( 15, array( 'post_type' => 'post' ) ); 21 foreach ( $posts as $post ) 22 wp_set_object_terms( $post, rand_str(), 'post_tag' ); 23 wp_cache_delete( 'last_changed', 'terms' ); 24 25 $this->assertFalse( wp_cache_get( 'last_changed', 'terms' ) ); 20 $this->set_up_three_posts_and_tags(); 26 21 27 22 $num_queries = $wpdb->num_queries; … … 29 24 // last_changed and num_queries should bump 30 25 $terms = get_terms( 'post_tag' ); 31 $this->assertEquals( 15, count( $terms ) );26 $this->assertEquals( 3, count( $terms ) ); 32 27 $time1 = wp_cache_get( 'last_changed', 'terms' ); 33 28 $this->assertNotEmpty( $time1 ); … … 38 33 // Again. last_changed and num_queries should remain the same. 39 34 $terms = get_terms( 'post_tag' ); 40 $this->assertEquals( 15, count( $terms ) );35 $this->assertEquals( 3, count( $terms ) ); 41 36 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'terms' ) ); 42 37 $this->assertEquals( $num_queries, $wpdb->num_queries ); 43 38 } 39 40 /** 41 * @ticket 23326 42 */ 43 public function test_get_terms_cache_should_be_missed_when_passing_number() { 44 global $wpdb; 45 46 $this->set_up_three_posts_and_tags(); 47 48 // Prime cache 49 $terms = get_terms( 'post_tag' ); 50 $time1 = wp_cache_get( 'last_changed', 'terms' ); 44 51 $num_queries = $wpdb->num_queries; 45 52 46 47 // Different query. num_queries should bump, last_changed should remain the same. 48 $terms = get_terms( 'post_tag', array( 'number' => 10 ) ); 49 $this->assertEquals( 10, count( $terms ) ); 53 // num_queries should bump, last_changed should remain the same. 54 $terms = get_terms( 'post_tag', array( 'number' => 2 ) ); 55 $this->assertEquals( 2, count( $terms ) ); 50 56 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'terms' ) ); 51 57 $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); … … 54 60 55 61 // Again. last_changed and num_queries should remain the same. 56 $terms = get_terms( 'post_tag', array( 'number' => 10) );57 $this->assertEquals( 10, count( $terms ) );62 $terms = get_terms( 'post_tag', array( 'number' => 2 ) ); 63 $this->assertEquals( 2, count( $terms ) ); 58 64 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'terms' ) ); 59 65 $this->assertEquals( $num_queries, $wpdb->num_queries ); 60 61 // Force last_changed to bump 66 } 67 68 /** 69 * @ticket 23326 70 */ 71 public function test_wp_delete_term_should_invalidate_cache() { 72 global $wpdb; 73 74 $this->set_up_three_posts_and_tags(); 75 76 // Prime cache 77 $terms = get_terms( 'post_tag' ); 78 $time1 = wp_cache_get( 'last_changed', 'terms' ); 79 $num_queries = $wpdb->num_queries; 80 81 // Force last_changed to bump. 62 82 wp_delete_term( $terms[0]->term_id, 'post_tag' ); 63 83 … … 65 85 $this->assertNotEquals( $time1, $time2 = wp_cache_get( 'last_changed', 'terms' ) ); 66 86 67 // last_changed and num_queries should bump after a term is deleted 87 // last_changed and num_queries should bump after a term is deleted. 68 88 $terms = get_terms( 'post_tag' ); 69 $this->assertEquals( 14, count( $terms ) );89 $this->assertEquals( 2, count( $terms ) ); 70 90 $this->assertEquals( $time2, wp_cache_get( 'last_changed', 'terms' ) ); 71 91 $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); … … 75 95 // Again. last_changed and num_queries should remain the same. 76 96 $terms = get_terms( 'post_tag' ); 77 $this->assertEquals( 14, count( $terms ) );97 $this->assertEquals( 2, count( $terms ) ); 78 98 $this->assertEquals( $time2, wp_cache_get( 'last_changed', 'terms' ) ); 79 99 $this->assertEquals( $num_queries, $wpdb->num_queries ); … … 1053 1073 ); 1054 1074 } 1075 1076 protected function set_up_three_posts_and_tags() { 1077 $posts = $this->factory->post->create_many( 3, array( 'post_type' => 'post' ) ); 1078 foreach ( $posts as $post ) { 1079 wp_set_object_terms( $post, rand_str(), 'post_tag' ); 1080 } 1081 1082 wp_cache_delete( 'last_changed', 'terms' ); 1083 } 1055 1084 }
Note: See TracChangeset
for help on using the changeset viewer.