Changeset 170 in tests for wp-testcase/test_includes_cache.php
- Timestamp:
- 03/10/2008 08:43:16 AM (18 years ago)
- File:
-
- 1 edited
-
wp-testcase/test_includes_cache.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_includes_cache.php
r105 r170 8 8 // create two cache objects with a shared cache dir 9 9 // this simulates a typical cache situation, two separate requests interacting 10 $this->cache1 =& $this->init_cache(); 11 $this->cache2 =& $this->init_cache(); 10 $this->cache =& $this->init_cache(); 12 11 } 13 12 … … 19 18 function &init_cache() { 20 19 $cache = new WP_Object_cache(); 21 $cache->cache_enabled = true;22 $cache->cache_dir = '/tmp/wp_cache_test/';23 20 return $cache; 24 21 } 25 22 26 23 function test_miss() { 27 $this->assertEquals(NULL, $this->cache 1->get(rand_str()));24 $this->assertEquals(NULL, $this->cache->get(rand_str())); 28 25 } 29 26 … … 32 29 $val = rand_str(); 33 30 34 $this->cache1->add($key, $val); 35 $this->cache1->save(); 36 $this->assertEquals($val, $this->cache2->get($key)); 37 $this->assertEquals($val, $this->cache1->get($key)); 31 $this->cache->add($key, $val); 32 $this->assertEquals($val, $this->cache->get($key)); 38 33 } 39 34 … … 42 37 $val = rand_str(); 43 38 44 $this->cache1->add($key, $val); 45 $this->cache1->save(); 39 $this->cache->add($key, $val); 46 40 // item is visible to both cache objects 47 $this->assertEquals($val, $this->cache1->get($key)); 48 $this->cache1->flush(); 49 // flush affects both cache objects 50 $this->assertEquals(NULL, $this->cache1->get($key)); 51 $this->assertEquals(NULL, $this->cache2->get($key)); 41 $this->assertEquals($val, $this->cache->get($key)); 42 $this->cache->flush(); 43 $this->assertEquals(NULL, $this->cache->get($key)); 52 44 } 53 45 54 function test_not_expired() {55 $key = rand_str();56 $val = rand_str();57 58 // expires in 1 second59 // nb: add() accepts an $expire parameter, but it doesn't work60 // so we have to set the expiration value for the whole cache61 // http://trac.wordpress.org/ticket/417962 $this->cache1->expiration_time = 3; # seconds63 $this->cache2->expiration_time = 3;64 $this->assertTrue($this->cache1->add($key, $val));65 $this->assertTrue($this->cache1->save());66 67 // not yet expired68 $this->assertEquals($val, $this->cache1->get($key));69 $this->assertEquals($val, $this->cache2->get($key));70 }71 72 function test_expired() {73 74 $key = rand_str();75 $val = rand_str();76 77 // expires in 1 second78 $this->cache1->expiration_time = 1; # second79 $this->cache2->expiration_time = 1;80 $this->assertTrue($this->cache1->add($key, $val));81 $this->assertTrue($this->cache1->save());82 83 // 3 seconds later, key should have expired84 sleep(3);85 $this->assertEquals(NULL, $this->cache2->get($key));86 // cache1's key is still cached in memory, which doesn't expire87 $this->assertEquals($val, $this->cache1->get($key));88 }89 90 function test_individual_expiry() {91 // FIXME: this is a current bug92 $this->markTestSkipped();93 94 $key = rand_str();95 $val = rand_str();96 97 // http://trac.wordpress.org/ticket/417998 // individual expiration parameters are ignored99 // this should expire after 1 second100 $this->assertTrue($this->cache1->add($key, $val, '', 1));101 $this->assertTrue($this->cache1->save());102 103 // not yet expired104 $this->assertEquals($val, $this->cache1->get($key));105 $this->assertEquals($val, $this->cache2->get($key));106 107 // 3 seconds later, key should have expired108 sleep(3);109 $this->assertEquals(NULL, $this->cache2->get($key));110 // cache1's key is still cached in memory, which doesn't expire111 $this->assertEquals($val, $this->cache1->get($key));112 }113 46 } 114 47
Note: See TracChangeset
for help on using the changeset viewer.