summaryrefslogtreecommitdiff
path: root/tests/UnitTests/framework/Data/CacheTestCase.php
diff options
context:
space:
mode:
authorxue <>2005-11-10 12:47:19 +0000
committerxue <>2005-11-10 12:47:19 +0000
commit55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 (patch)
treea0599d5e36fdbb3f1e169ae56bab7d529597e3eb /tests/UnitTests/framework/Data/CacheTestCase.php
Initial import of prado framework
Diffstat (limited to 'tests/UnitTests/framework/Data/CacheTestCase.php')
-rw-r--r--tests/UnitTests/framework/Data/CacheTestCase.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/UnitTests/framework/Data/CacheTestCase.php b/tests/UnitTests/framework/Data/CacheTestCase.php
new file mode 100644
index 00000000..68a7b067
--- /dev/null
+++ b/tests/UnitTests/framework/Data/CacheTestCase.php
@@ -0,0 +1,98 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+
+class CacheTestCase extends UnitTestCase
+{
+ private $_cache;
+
+ public function getCache()
+ {
+ return $this->_cache;
+ }
+
+ public function setCache($cache)
+ {
+ $this->_cache=$cache;
+ }
+
+ public function basicOperations()
+ {
+ $object=new TComponent;
+ $number=12345;
+ $string='12345\'"';
+ $array=array('123'=>123,'abc'=>'def');
+
+ // test set (first time)
+ $this->assertFalse($this->_cache->get('object'));
+ $this->assertTrue($this->_cache->set('object',$object));
+ $this->assertTrue($this->_cache->get('object') instanceof TComponent);
+ $this->assertFalse($this->_cache->get('number'));
+ $this->assertTrue($this->_cache->set('number',$number));
+ $this->assertTrue($this->_cache->get('number')===$number);
+ $this->assertFalse($this->_cache->get('string'));
+ $this->assertTrue($this->_cache->set('string',$string));
+ $this->assertTrue($this->_cache->get('string')===$string);
+ $this->assertFalse($this->_cache->get('array'));
+ $this->assertTrue($this->_cache->set('array',$array));
+ $this->assertTrue($this->_cache->get('array')===$array);
+
+ // test set (second time)
+ $this->assertTrue($this->_cache->set('object',$array));
+ $this->assertTrue($this->_cache->get('object')===$array);
+
+ // test delete
+ $this->assertTrue($this->_cache->delete('object'));
+ $this->assertFalse($this->_cache->get('object'));
+ $this->assertTrue($this->_cache->delete('number'));
+ $this->assertFalse($this->_cache->get('number'));
+ $this->assertTrue($this->_cache->delete('string'));
+ $this->assertFalse($this->_cache->get('string'));
+ $this->assertTrue($this->_cache->delete('array'));
+ $this->assertFalse($this->_cache->get('array'));
+
+ // test add (first time)
+ $this->assertFalse($this->_cache->get('object'));
+ $this->assertTrue($this->_cache->add('object',$object));
+ $this->assertTrue($this->_cache->get('object') instanceof TComponent);
+ $this->assertFalse($this->_cache->get('number'));
+ $this->assertTrue($this->_cache->add('number',$number));
+ $this->assertTrue($this->_cache->get('number')===$number);
+ $this->assertFalse($this->_cache->get('string'));
+ $this->assertTrue($this->_cache->add('string',$string));
+ $this->assertTrue($this->_cache->get('string')===$string);
+ $this->assertFalse($this->_cache->get('array'));
+ $this->assertTrue($this->_cache->add('array',$array));
+ $this->assertTrue($this->_cache->get('array')===$array);
+
+ // test add (second time)
+ $this->assertFalse($this->_cache->add('object',$array));
+ $this->assertTrue($this->_cache->get('object') instanceof TComponent);
+
+ // test replace
+ $this->assertTrue($this->_cache->replace('object',$array));
+ $this->assertTrue($this->_cache->get('object')===$array);
+ $this->assertFalse($this->_cache->replace('object2',$array));
+ $this->assertFalse($this->_cache->get('object2'));
+
+ // test flush
+ $this->assertTrue($this->_cache->set('number',$number));
+ $this->assertTrue($this->_cache->get('number')===$number);
+ $this->assertTrue($this->_cache->flush());
+ $this->assertFalse($this->_cache->get('number'));
+
+ // test expiring
+ // set a value with 5sec valid time
+ $this->_cache->set('expiring',123,3);
+ $this->assertTrue($this->_cache->get('expiring')===123);
+ $this->_cache->set('nonexpiring',456);
+ $this->assertTrue($this->_cache->get('nonexpiring')===456);
+
+ // wait 6sec to see if the value still exists
+ sleep(4);
+ $this->assertFalse($this->_cache->get('expiring'));
+ $this->assertTrue($this->_cache->get('nonexpiring')===456);
+ }
+}
+
+?> \ No newline at end of file