Changeset 42343 for trunk/tests/phpunit/tests/cache.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/cache.php
r40347 r42343 22 22 global $wp_object_cache; 23 23 $cache_class = get_class( $wp_object_cache ); 24 $cache = new $cache_class();24 $cache = new $cache_class(); 25 25 $cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); 26 26 return $cache; … … 28 28 29 29 function test_miss() { 30 $this->assertEquals( NULL, $this->cache->get( 'test_miss' ) );30 $this->assertEquals( null, $this->cache->get( 'test_miss' ) ); 31 31 } 32 32 … … 35 35 $val = 'val'; 36 36 37 $this->cache->add( $key, $val);38 $this->assertEquals( $val, $this->cache->get($key));37 $this->cache->add( $key, $val ); 38 $this->assertEquals( $val, $this->cache->get( $key ) ); 39 39 } 40 40 … … 44 44 45 45 // you can store zero in the cache 46 $this->cache->add( $key, $val);47 $this->assertEquals( $val, $this->cache->get($key));46 $this->cache->add( $key, $val ); 47 $this->assertEquals( $val, $this->cache->get( $key ) ); 48 48 } 49 49 … … 52 52 $val = null; 53 53 54 $this->assertTrue( $this->cache->add( $key, $val) );54 $this->assertTrue( $this->cache->add( $key, $val ) ); 55 55 // null is converted to empty string 56 $this->assertEquals( '', $this->cache->get( $key) );56 $this->assertEquals( '', $this->cache->get( $key ) ); 57 57 } 58 58 59 59 function test_add() { 60 $key = __FUNCTION__;60 $key = __FUNCTION__; 61 61 $val1 = 'val1'; 62 62 $val2 = 'val2'; 63 63 64 64 // add $key to the cache 65 $this->assertTrue( $this->cache->add($key, $val1));66 $this->assertEquals( $val1, $this->cache->get($key));65 $this->assertTrue( $this->cache->add( $key, $val1 ) ); 66 $this->assertEquals( $val1, $this->cache->get( $key ) ); 67 67 // $key is in the cache, so reject new calls to add() 68 $this->assertFalse( $this->cache->add($key, $val2));69 $this->assertEquals( $val1, $this->cache->get($key));68 $this->assertFalse( $this->cache->add( $key, $val2 ) ); 69 $this->assertEquals( $val1, $this->cache->get( $key ) ); 70 70 } 71 71 72 72 function test_replace() { 73 $key = __FUNCTION__;74 $val = 'val1';73 $key = __FUNCTION__; 74 $val = 'val1'; 75 75 $val2 = 'val2'; 76 76 77 77 // memcached rejects replace() if the key does not exist 78 $this->assertFalse( $this->cache->replace($key, $val));79 $this->assertFalse( $this->cache->get($key));80 $this->assertTrue( $this->cache->add($key, $val));81 $this->assertEquals( $val, $this->cache->get($key));82 $this->assertTrue( $this->cache->replace($key, $val2));83 $this->assertEquals( $val2, $this->cache->get($key));78 $this->assertFalse( $this->cache->replace( $key, $val ) ); 79 $this->assertFalse( $this->cache->get( $key ) ); 80 $this->assertTrue( $this->cache->add( $key, $val ) ); 81 $this->assertEquals( $val, $this->cache->get( $key ) ); 82 $this->assertTrue( $this->cache->replace( $key, $val2 ) ); 83 $this->assertEquals( $val2, $this->cache->get( $key ) ); 84 84 } 85 85 86 86 function test_set() { 87 $key = __FUNCTION__;87 $key = __FUNCTION__; 88 88 $val1 = 'val1'; 89 89 $val2 = 'val2'; 90 90 91 91 // memcached accepts set() if the key does not exist 92 $this->assertTrue( $this->cache->set($key, $val1));93 $this->assertEquals( $val1, $this->cache->get($key));92 $this->assertTrue( $this->cache->set( $key, $val1 ) ); 93 $this->assertEquals( $val1, $this->cache->get( $key ) ); 94 94 // Second set() with same key should be allowed 95 $this->assertTrue( $this->cache->set($key, $val2));96 $this->assertEquals( $val2, $this->cache->get($key));95 $this->assertTrue( $this->cache->set( $key, $val2 ) ); 96 $this->assertEquals( $val2, $this->cache->get( $key ) ); 97 97 } 98 98 … … 100 100 global $_wp_using_ext_object_cache; 101 101 102 if ( $_wp_using_ext_object_cache ) 102 if ( $_wp_using_ext_object_cache ) { 103 103 return; 104 } 104 105 105 106 $key = __FUNCTION__; 106 107 $val = 'val'; 107 108 108 $this->cache->add( $key, $val);109 $this->cache->add( $key, $val ); 109 110 // item is visible to both cache objects 110 $this->assertEquals( $val, $this->cache->get($key));111 $this->assertEquals( $val, $this->cache->get( $key ) ); 111 112 $this->cache->flush(); 112 113 // If there is no value get returns false. 113 $this->assertFalse( $this->cache->get($key));114 $this->assertFalse( $this->cache->get( $key ) ); 114 115 } 115 116 116 117 // Make sure objects are cloned going to and from the cache 117 118 function test_object_refs() { 118 $key = __FUNCTION__ . '_1';119 $object_a = new stdClass;119 $key = __FUNCTION__ . '_1'; 120 $object_a = new stdClass; 120 121 $object_a->foo = 'alpha'; 121 122 $this->cache->set( $key, $object_a ); 122 123 $object_a->foo = 'bravo'; 123 $object_b = $this->cache->get( $key );124 $object_b = $this->cache->get( $key ); 124 125 $this->assertEquals( 'alpha', $object_b->foo ); 125 126 $object_b->foo = 'charlie'; 126 127 $this->assertEquals( 'bravo', $object_a->foo ); 127 128 128 $key = __FUNCTION__ . '_2';129 $object_a = new stdClass;129 $key = __FUNCTION__ . '_2'; 130 $object_a = new stdClass; 130 131 $object_a->foo = 'alpha'; 131 132 $this->cache->add( $key, $object_a ); 132 133 $object_a->foo = 'bravo'; 133 $object_b = $this->cache->get( $key );134 $object_b = $this->cache->get( $key ); 134 135 $this->assertEquals( 'alpha', $object_b->foo ); 135 136 $object_b->foo = 'charlie'; … … 212 213 $this->assertFalse( $this->cache->get( $key ) ); 213 214 214 $this->assertFalse( $this->cache->delete( $key, 'default' ) );215 $this->assertFalse( $this->cache->delete( $key, 'default' ) ); 215 216 } 216 217 … … 231 232 // $this->assertTrue( wp_cache_delete( $key, 'default', true ) ); 232 233 233 $this->assertFalse( wp_cache_delete( $key, 'default' ) );234 $this->assertFalse( wp_cache_delete( $key, 'default' ) ); 234 235 } 235 236 236 237 function test_switch_to_blog() { 237 if ( ! method_exists( $this->cache, 'switch_to_blog' ) ) 238 if ( ! method_exists( $this->cache, 'switch_to_blog' ) ) { 238 239 return; 239 240 $key = __FUNCTION__; 241 $val = 'val1'; 240 } 241 242 $key = __FUNCTION__; 243 $val = 'val1'; 242 244 $val2 = 'val2'; 243 245 … … 287 289 if ( wp_using_ext_object_cache() ) { 288 290 // External caches will contain property values that contain non-matching resource IDs 289 $this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache 291 $this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache ); 290 292 } else { 291 293 $this->assertEquals( $wp_object_cache, $new_blank_cache_object );
Note: See TracChangeset
for help on using the changeset viewer.