Changeset 30900 for trunk/tests/phpunit/tests/term/cache.php
- Timestamp:
- 12/16/2014 01:26:19 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/term/cache.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/cache.php
r30112 r30900 94 94 _unregister_taxonomy( $tax ); 95 95 } 96 97 /**98 * @ticket 2176099 */100 function test_get_term_by_slug_cache() {101 global $wpdb;102 $term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'taxonomy' => 'post_tag' ) );103 104 $queries = $wpdb->num_queries;105 get_term_by( 'slug', 'burrito', 'post_tag' );106 $initial = $queries + 1;107 $this->assertEquals( $initial, $wpdb->num_queries );108 $term = get_term_by( 'slug', 'burrito', 'post_tag' );109 $this->assertEquals( $initial, $wpdb->num_queries );110 111 $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );112 113 $this->assertEquals( get_term( $term_id, 'post_tag' ), $term );114 $this->assertEquals( $initial, $wpdb->num_queries );115 }116 117 /**118 * @ticket 21760119 */120 function test_get_term_by_slug_cache_update() {121 global $wpdb;122 $term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'taxonomy' => 'post_tag' ) );123 124 $queries = $wpdb->num_queries;125 get_term_by( 'slug', 'burrito', 'post_tag' );126 $initial = $queries + 1;127 $this->assertEquals( $initial, $wpdb->num_queries );128 $term = get_term_by( 'slug', 'burrito', 'post_tag' );129 $this->assertEquals( $initial, $wpdb->num_queries );130 131 $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );132 133 wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) );134 $this->assertNotEquals( $term, get_term( $term_id, 'post_tag' ) );135 $after_queries = $wpdb->num_queries;136 get_term_by( 'slug', 'burrito', 'post_tag' );137 $this->assertEquals( $after_queries, $wpdb->num_queries );138 }139 140 /**141 * @ticket 21760142 */143 function test_get_term_by_name_cache() {144 global $wpdb;145 $term_id = $this->factory->term->create( array( 'name' => 'burrito', 'taxonomy' => 'post_tag' ) );146 147 $queries = $wpdb->num_queries;148 get_term_by( 'name', 'burrito', 'post_tag' );149 $initial = $queries + 1;150 $this->assertEquals( $initial, $wpdb->num_queries );151 $term = get_term_by( 'name', 'burrito', 'post_tag' );152 $this->assertEquals( $initial, $wpdb->num_queries );153 154 $this->assertEquals( get_term( $term_id, 'post_tag' ), $term );155 $this->assertEquals( $initial, $wpdb->num_queries );156 }157 158 /**159 * @ticket 21760160 */161 function test_get_term_by_name_cache_update() {162 global $wpdb;163 $term_id = $this->factory->term->create( array( 'name' => 'burrito', 'taxonomy' => 'post_tag' ) );164 165 $queries = $wpdb->num_queries;166 get_term_by( 'name', 'burrito', 'post_tag' );167 $initial = $queries + 1;168 $this->assertEquals( $initial, $wpdb->num_queries );169 $term = get_term_by( 'name', 'burrito', 'post_tag' );170 $this->assertEquals( $initial, $wpdb->num_queries );171 172 wp_update_term( $term_id, 'post_tag', array( 'slug' => 'Taco' ) );173 $this->assertNotEquals( $term, get_term( $term_id, 'post_tag' ) );174 $after_queries = $wpdb->num_queries;175 get_term_by( 'name', 'burrito', 'post_tag' );176 $this->assertEquals( $after_queries, $wpdb->num_queries );177 }178 179 /**180 * @ticket 21760181 */182 function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() {183 $slug = 'taco';184 $name = 'Taco';185 $taxonomy = 'post_tag';186 $cache_key_slug = $slug;187 $cache_key_name = $name;188 189 $term_id = $this->factory->term->create( array( 'slug' => $slug, 'name' => $name, 'taxonomy' => $taxonomy ) );190 191 $last_changed = wp_cache_get( 'last_changed', 'terms' );192 193 $term = get_term_by( 'slug', $slug, $taxonomy );194 195 // Verify the term is cached by ID, slug and name196 $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );197 $this->assertSame( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) );198 $this->assertSame( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) );199 200 $suspend = wp_suspend_cache_invalidation();201 clean_term_cache( $term_id, $taxonomy );202 203 // Verify that the cached value still matches the correct value204 $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );205 $this->assertSame( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) );206 $this->assertSame( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) );207 208 // Verify that last changed has not been updated as part of an invalidation routine209 $this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'terms' ) );210 211 // Clean up.212 wp_suspend_cache_invalidation( $suspend );213 }214 96 }
Note: See TracChangeset
for help on using the changeset viewer.