Changeset 946 in tests
- Timestamp:
- 08/02/2012 06:32:54 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/cache.php
r944 r946 21 21 function &init_cache() { 22 22 $cache = new WP_Object_Cache(); 23 $cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 23 24 return $cache; 24 25 } … … 227 228 $this->assertFalse( wp_cache_delete( $key, 'default') ); 228 229 } 230 231 function test_switch_to_blog() { 232 if ( ! method_exists( $this->cache, 'switch_to_blog' ) ) 233 return; 234 235 $key = rand_str(); 236 $val = rand_str(); 237 $val2 = rand_str(); 238 239 if ( ! is_multisite() ) { 240 // Single site ingnores switch_to_blog(). 241 $this->assertTrue( $this->cache->set( $key, $val ) ); 242 $this->assertEquals( $val, $this->cache->get( $key ) ); 243 $this->cache->switch_to_blog( 999 ); 244 $this->assertEquals( $val, $this->cache->get( $key ) ); 245 $this->assertTrue( $this->cache->set( $key, $val2 ) ); 246 $this->assertEquals( $val2, $this->cache->get( $key ) ); 247 $this->cache->switch_to_blog( get_current_blog_id() ); 248 $this->assertEquals( $val2, $this->cache->get( $key ) ); 249 } else { 250 // Multisite should have separate per-blog caches 251 $this->assertTrue( $this->cache->set( $key, $val ) ); 252 $this->assertEquals( $val, $this->cache->get( $key ) ); 253 $this->cache->switch_to_blog( 999 ); 254 $this->assertFalse( $this->cache->get( $key ) ); 255 $this->assertTrue( $this->cache->set( $key, $val2 ) ); 256 $this->assertEquals( $val2, $this->cache->get( $key ) ); 257 $this->cache->switch_to_blog( get_current_blog_id() ); 258 $this->assertEquals( $val, $this->cache->get( $key ) ); 259 $this->cache->switch_to_blog( 999 ); 260 $this->assertEquals( $val2, $this->cache->get( $key ) ); 261 $this->cache->switch_to_blog( get_current_blog_id() ); 262 $this->assertEquals( $val, $this->cache->get( $key ) ); 263 } 264 265 // Global group 266 $this->assertTrue( $this->cache->set( $key, $val, 'global-cache-test' ) ); 267 $this->assertEquals( $val, $this->cache->get( $key, 'global-cache-test' ) ); 268 $this->cache->switch_to_blog( 999 ); 269 $this->assertEquals( $val, $this->cache->get( $key, 'global-cache-test' ) ); 270 $this->assertTrue( $this->cache->set( $key, $val2, 'global-cache-test' ) ); 271 $this->assertEquals( $val2, $this->cache->get( $key, 'global-cache-test' ) ); 272 $this->cache->switch_to_blog( get_current_blog_id() ); 273 $this->assertEquals( $val2, $this->cache->get( $key, 'global-cache-test' ) ); 274 } 229 275 }
Note: See TracChangeset
for help on using the changeset viewer.