Changeset 5 in tests
- Timestamp:
- 09/20/2007 01:06:28 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_includes_cache.php
r1 r5 2 2 3 3 class TestObjectCache extends WPTestCase { 4 var $cache = NULL; 4 5 5 6 function setUp() { 6 $this->init_cache(); 7 // create two cache objects with a shared cache dir 8 // this simulates a typical cache situation, two separate requests interacting 9 $this->cache1 =& $this->init_cache(); 10 $this->cache2 =& $this->init_cache(); 7 11 } 8 12 … … 11 15 } 12 16 13 function init_cache() { 14 wp_cache_init(); 15 $GLOBALS['wp_object_cache']->cache_enabled = true; 16 $GLOBALS['wp_object_cache']->cache_dir = '/tmp/'; 17 function &init_cache() { 18 $cache = new WP_Object_cache(); 19 $cache->cache_enabled = true; 20 $cache->cache_dir = '/tmp/'; 21 return $cache; 17 22 } 18 23 19 24 function test_miss() { 20 $this->assertEquals(NULL, wp_cache_get(rand_str()));25 $this->assertEquals(NULL, $this->cache1->get(rand_str())); 21 26 } 22 27 … … 25 30 $val = rand_str(); 26 31 27 wp_cache_add($key, $val); 28 $this->assertEquals($val, wp_cache_get($key)); 32 $this->cache1->add($key, $val); 33 $this->cache1->save(); 34 $this->assertEquals($val, $this->cache2->get($key)); 35 $this->assertEquals($val, $this->cache1->get($key)); 29 36 } 30 37 … … 33 40 $val = rand_str(); 34 41 35 wp_cache_add($key, $val); 36 wp_cache_flush(); 37 $this->assertEquals(NULL, wp_cache_get($key)); 42 $this->cache1->add($key, $val); 43 $this->cache1->save(); 44 // item is visible to both cache objects 45 $this->assertEquals($val, $this->cache1->get($key)); 46 $this->cache1->flush(); 47 // flush affects both cache objects 48 $this->assertEquals(NULL, $this->cache1->get($key)); 49 $this->assertEquals(NULL, $this->cache2->get($key)); 38 50 } 39 51 40 52 function test_not_expired() { 41 # $this->markTestSkipped();42 53 // this fails - looks like the object cache doesn't expire 43 54 $key = rand_str(); … … 45 56 46 57 // expires in 1 second 47 wp_cache_add($key, $val, '', 1); 48 wp_cache_close(); 49 $this->init_cache(); 58 // nb: add() accepts an $expire parameter, but it doesn't work 59 // so we have to set the expiration value for the whole cache 60 // http://trac.wordpress.org/ticket/4179 61 $this->cache1->expiration_time = 3; # seconds 62 $this->cache2->expiration_time = 3; 63 $this->assertTrue($this->cache1->add($key, $val)); 64 $this->assertTrue($this->cache1->save()); 65 50 66 // not yet expired 51 $this->assertEquals($val, wp_cache_get($key)); 67 $this->assertEquals($val, $this->cache1->get($key)); 68 $this->assertEquals($val, $this->cache2->get($key)); 52 69 } 53 70 … … 58 75 59 76 // expires in 1 second 60 wp_cache_add($key, $val, '', 1); 61 wp_cache_close(); 62 $this->init_cache(); 77 $this->cache1->expiration_time = 1; # second 78 $this->cache2->expiration_time = 1; 79 $this->assertTrue($this->cache1->add($key, $val)); 80 $this->assertTrue($this->cache1->save()); 81 82 // 3 seconds later, key should have expired 63 83 sleep(3); 64 $this->assertEquals(NULL, wp_cache_get($key)); 84 $this->assertEquals(NULL, $this->cache2->get($key)); 85 // cache1's key is still cached in memory, which doesn't expire 86 $this->assertEquals($val, $this->cache1->get($key)); 65 87 } 66 88
Note: See TracChangeset
for help on using the changeset viewer.