WordPress.org

Make WordPress Core

Changeset 946 in tests


Ignore:
Timestamp:
08/02/12 18:32:54 (21 months ago)
Author:
ryan
Message:

WP_Object_Cache::switch_to_blog() tests. see #WP21434

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/cache.php

    r944 r946  
    2121    function &init_cache() { 
    2222        $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' ) ); 
    2324        return $cache; 
    2425    } 
     
    227228        $this->assertFalse( wp_cache_delete( $key, 'default') ); 
    228229    } 
     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    } 
    229275} 
Note: See TracChangeset for help on using the changeset viewer.