Changeset 47122 for trunk/tests/phpunit/tests/cache.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/cache.php
r46586 r47122 9 9 function setUp() { 10 10 parent::setUp(); 11 // create two cache objects with a shared cache dir12 // this simulates a typical cache situation, two separate requests interacting11 // Create two cache objects with a shared cache directory. 12 // This simulates a typical cache situation, two separate requests interacting. 13 13 $this->cache =& $this->init_cache(); 14 14 } … … 43 43 $val = 0; 44 44 45 // you can store zero in the cache45 // You can store zero in the cache. 46 46 $this->cache->add( $key, $val ); 47 47 $this->assertEquals( $val, $this->cache->get( $key ) ); … … 53 53 54 54 $this->assertTrue( $this->cache->add( $key, $val ) ); 55 // null is converted to empty string55 // Null is converted to empty string. 56 56 $this->assertEquals( '', $this->cache->get( $key ) ); 57 57 } … … 62 62 $val2 = 'val2'; 63 63 64 // add $key to the cache64 // Add $key to the cache. 65 65 $this->assertTrue( $this->cache->add( $key, $val1 ) ); 66 66 $this->assertEquals( $val1, $this->cache->get( $key ) ); 67 // $key is in the cache, so reject new calls to add() 67 // $key is in the cache, so reject new calls to add(). 68 68 $this->assertFalse( $this->cache->add( $key, $val2 ) ); 69 69 $this->assertEquals( $val1, $this->cache->get( $key ) ); … … 75 75 $val2 = 'val2'; 76 76 77 // memcached rejects replace() if the key does not exist 77 // memcached rejects replace() if the key does not exist. 78 78 $this->assertFalse( $this->cache->replace( $key, $val ) ); 79 79 $this->assertFalse( $this->cache->get( $key ) ); … … 89 89 $val2 = 'val2'; 90 90 91 // memcached accepts set() if the key does not exist 91 // memcached accepts set() if the key does not exist. 92 92 $this->assertTrue( $this->cache->set( $key, $val1 ) ); 93 93 $this->assertEquals( $val1, $this->cache->get( $key ) ); 94 // Second set() with same key should be allowed 94 // Second set() with same key should be allowed. 95 95 $this->assertTrue( $this->cache->set( $key, $val2 ) ); 96 96 $this->assertEquals( $val2, $this->cache->get( $key ) ); … … 108 108 109 109 $this->cache->add( $key, $val ); 110 // item is visible to both cache objects110 // Item is visible to both cache objects. 111 111 $this->assertEquals( $val, $this->cache->get( $key ) ); 112 112 $this->cache->flush(); … … 115 115 } 116 116 117 // Make sure objects are cloned going to and from the cache 117 // Make sure objects are cloned going to and from the cache. 118 118 function test_object_refs() { 119 119 $key = __FUNCTION__ . '_1'; … … 205 205 $val = 'val'; 206 206 207 // Verify set 207 // Verify set. 208 208 $this->assertTrue( $this->cache->set( $key, $val ) ); 209 209 $this->assertEquals( $val, $this->cache->get( $key ) ); 210 210 211 // Verify successful delete 211 // Verify successful delete. 212 212 $this->assertTrue( $this->cache->delete( $key ) ); 213 213 $this->assertFalse( $this->cache->get( $key ) ); … … 220 220 $val = 'val'; 221 221 222 // Verify set 222 // Verify set. 223 223 $this->assertTrue( wp_cache_set( $key, $val ) ); 224 224 $this->assertEquals( $val, wp_cache_get( $key ) ); 225 225 226 // Verify successful delete 226 // Verify successful delete. 227 227 $this->assertTrue( wp_cache_delete( $key ) ); 228 228 $this->assertFalse( wp_cache_get( $key ) ); 229 229 230 230 // wp_cache_delete() does not have a $force method. 231 // Delete returns (bool) true when key is not set and $force is true 231 // Delete returns (bool) true when key is not set and $force is true. 232 232 // $this->assertTrue( wp_cache_delete( $key, 'default', true ) ); 233 233 … … 255 255 $this->assertEquals( $val2, $this->cache->get( $key ) ); 256 256 } else { 257 // Multisite should have separate per-blog caches 257 // Multisite should have separate per-blog caches. 258 258 $this->assertTrue( $this->cache->set( $key, $val ) ); 259 259 $this->assertEquals( $val, $this->cache->get( $key ) ); … … 270 270 } 271 271 272 // Global group 272 // Global group. 273 273 $this->assertTrue( $this->cache->set( $key, $val, 'global-cache-test' ) ); 274 274 $this->assertEquals( $val, $this->cache->get( $key, 'global-cache-test' ) ); … … 288 288 289 289 if ( wp_using_ext_object_cache() ) { 290 // External caches will contain property values that contain non-matching resource IDs 290 // External caches will contain property values that contain non-matching resource IDs. 291 291 $this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache ); 292 292 } else { … … 302 302 $fake_key = 'my-fake-key'; 303 303 304 // Save the first value to cache and verify 304 // Save the first value to cache and verify. 305 305 wp_cache_set( $key, $val1 ); 306 306 $this->assertEquals( $val1, wp_cache_get( $key ) ); 307 307 308 // Replace the value and verify 308 // Replace the value and verify. 309 309 wp_cache_replace( $key, $val2 ); 310 310 $this->assertEquals( $val2, wp_cache_get( $key ) ); 311 311 312 // Non-existant key should fail 312 // Non-existant key should fail. 313 313 $this->assertFalse( wp_cache_replace( $fake_key, $val1 ) ); 314 314 315 // Make sure $fake_key is not stored 315 // Make sure $fake_key is not stored. 316 316 $this->assertFalse( wp_cache_get( $fake_key ) ); 317 317 }
Note: See TracChangeset
for help on using the changeset viewer.