Adding tests for securing private variable inclussion on templates.
[akelos.git] / test / unit / lib / AkCache.php
blob87ca992503d2af963ca746432a238604c5ee4869
1 <?php
3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
4 require_once(dirname(__FILE__).'/../../fixtures/config/config.php');
7 require_once(AK_LIB_DIR.DS.'AkCache.php');
9 class AkCache_TestCase extends AkUnitTest
12 var $_driverInstance = NULL;
13 var $Cache = NULL;
14 var $id = 'test case cache id';
15 var $group = 'test case group to cacth';
16 var $text_to_catch = 'this is the text to catch on the test case of the AkCache class';
18 function test_install_db_tables()
20 $this->resetFrameworkDatabaseTables();
23 function setUp()
25 $this->Cache =& new AkCache();
28 function tearDown()
30 unset($this->Cache);
33 function Testinit()
35 //No driver is loaded
36 $this->Cache->init(null,0);
37 $this->assertNull($this->Cache->_driverInstance,'Checking that no driver is loaded when cache is disabled');
39 //Pear Cache Lite driver is loaded
40 $this->Cache->init(null,1);
41 $this->assertIsA($this->Cache->_driverInstance,'cache_lite');
43 //AdodbCache database cache driver loaded
44 $this->Cache->init(null,2);
45 $this->assertIsA($this->Cache->_driverInstance,'akadodbcache');
48 function Test_get_and_save()
51 //No cache
52 $this->Cache->init(null,0);
53 $data = $this->Cache->get('id');
54 $this->assertFalse($data,'Cache not enabled so this must return false');
55 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache must not work because cache is disabled');
57 //Cache Lite cache
58 $this->Cache->init(1,1);
59 $data = $this->Cache->get($this->id, $this->group);
60 $this->assertFalse($data,'This id must not be in the cache (File based)');
61 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (File based)');
62 $this->Cache->init(1,1);
63 $data = $this->Cache->get($this->id, $this->group);
64 $this->assertEqual($data, $this->text_to_catch,'Getting cached data (File based)');
65 sleep(2);
66 $this->Cache->init(1,1);
67 $data = $this->Cache->get($this->id, $this->group);
68 $this->assertFalse($data,'The cache has expired and we recognize it (File based)');
72 // Database cache
73 $this->Cache->init(1,2);
74 $data = $this->Cache->get($this->id, $this->group);
75 $this->assertFalse($data,'This id must not be in the cache (Database based)');
76 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (Database based)');
77 $this->Cache->init(1,2);
78 $data = $this->Cache->get($this->id, $this->group);
79 $this->assertEqual($data, $this->text_to_catch,'Getting cached data (Database based)');
80 sleep(2);
81 $this->Cache->init(1,2);
82 $data = $this->Cache->get($this->id, $this->group);
83 $this->assertFalse($data,'The cache has expired and we recognize it (Database based)');
88 function Testremove()
91 $this->Cache->init(1,0);
92 $this->assertFalse(!$this->Cache->remove($this->id, $this->group),'Removing cached file (Cache disabled must return success)');
94 //Cache Lite cache
95 $this->Cache->init(1,1);
96 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (File based)');
97 $this->Cache->init(1,1);
98 $data = $this->Cache->get($this->id, $this->group);
99 $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
100 $this->assertFalse(!$this->Cache->remove($this->id, $this->group),'Removing cached file (File based)');
101 $data = $this->Cache->get($this->id, $this->group);
102 $this->assertFalse($data,'The cache must have been removed at this point but stills here (File based)');
105 //Database cache
106 $this->Cache->init(1,2);
107 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (Database based)');
108 $this->Cache->init(1,2);
109 $data = $this->Cache->get($this->id, $this->group);
110 $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (Database based)');
111 $this->Cache->remove($this->id, $this->group);
112 $data = $this->Cache->get($this->id, $this->group);
113 $this->assertFalse($data,'The cache must have been removed at this point but stills here (Database based)');
117 function Testclean()
120 //AkCache::clean($group = 'false', $mode = 'ingroup');
121 $this->Cache->init(1,1);
122 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache');
123 $this->Cache->init(1,1);
124 $data = $this->Cache->get($this->id, $this->group);
125 $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
127 $this->Cache->init(1,1);
128 $this->assertFalse(!$this->Cache->clean($this->group),'Removing all the items in cache');
130 $this->Cache->init(1,1);
131 $data = $this->Cache->get($this->id, $this->group);
132 $this->assertFalse($data,'The cache must have been removed at this point but stills here');
136 //AkCache::clean($group = 'false', $mode = 'ingroup');
137 $this->Cache->init(1,2);
138 $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache');
139 $this->Cache->init(1,2);
140 $data = $this->Cache->get($this->id, $this->group);
141 $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
143 $this->Cache->init(1,2);
144 $this->assertFalse(!$this->Cache->clean($this->group),'Removing all the items in cache');
146 $this->Cache->init(1,2);
147 $data = $this->Cache->get($this->id, $this->group);
148 $this->assertFalse($data,'The cache must have been removed at this point but stills here');
154 ak_test('AkCache_TestCase',true);