Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/cases/libs/cache/xcache.test.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * XcacheEngineTest file | |
4 * | |
5 * PHP versions 4 and 5 | |
6 * | |
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | |
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
9 * | |
10 * Licensed under The Open Group Test Suite License | |
11 * Redistributions of files must retain the above copyright notice. | |
12 * | |
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests | |
15 * @package cake | |
16 * @subpackage cake.tests.cases.libs.cache | |
17 * @since CakePHP(tm) v 1.2.0.5434 | |
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License | |
19 */ | |
20 if (!class_exists('Cache')) { | |
21 require LIBS . 'cache.php'; | |
22 } | |
23 | |
24 /** | |
25 * XcacheEngineTest class | |
26 * | |
27 * @package cake | |
28 * @subpackage cake.tests.cases.libs.cache | |
29 */ | |
30 class XcacheEngineTest extends UnitTestCase { | |
31 | |
32 /** | |
33 * skip method | |
34 * | |
35 * @access public | |
36 * @return void | |
37 */ | |
38 function skip() { | |
39 $skip = true; | |
40 if (function_exists('xcache_set')) { | |
41 $skip = false; | |
42 } | |
43 $this->skipIf($skip, '%s Xcache is not installed or configured properly'); | |
44 } | |
45 | |
46 /** | |
47 * setUp method | |
48 * | |
49 * @access public | |
50 * @return void | |
51 */ | |
52 function setUp() { | |
53 $this->_cacheDisable = Configure::read('Cache.disable'); | |
54 Configure::write('Cache.disable', false); | |
55 Cache::config('xcache', array('engine' => 'Xcache', 'prefix' => 'cake_')); | |
56 } | |
57 | |
58 /** | |
59 * tearDown method | |
60 * | |
61 * @access public | |
62 * @return void | |
63 */ | |
64 function tearDown() { | |
65 Configure::write('Cache.disable', $this->_cacheDisable); | |
66 Cache::config('default'); | |
67 } | |
68 | |
69 /** | |
70 * testSettings method | |
71 * | |
72 * @access public | |
73 * @return void | |
74 */ | |
75 function testSettings() { | |
76 $settings = Cache::settings(); | |
77 $expecting = array( | |
78 'prefix' => 'cake_', | |
79 'duration'=> 3600, | |
80 'probability' => 100, | |
81 'engine' => 'Xcache', | |
82 ); | |
83 $this->assertTrue(isset($settings['PHP_AUTH_USER'])); | |
84 $this->assertTrue(isset($settings['PHP_AUTH_PW'])); | |
85 | |
86 unset($settings['PHP_AUTH_USER'], $settings['PHP_AUTH_PW']); | |
87 $this->assertEqual($settings, $expecting); | |
88 } | |
89 | |
90 /** | |
91 * testReadAndWriteCache method | |
92 * | |
93 * @access public | |
94 * @return void | |
95 */ | |
96 function testReadAndWriteCache() { | |
97 Cache::set(array('duration' => 1)); | |
98 | |
99 $result = Cache::read('test'); | |
100 $expecting = ''; | |
101 $this->assertEqual($result, $expecting); | |
102 | |
103 $data = 'this is a test of the emergency broadcasting system'; | |
104 $result = Cache::write('test', $data); | |
105 $this->assertTrue($result); | |
106 | |
107 $result = Cache::read('test'); | |
108 $expecting = $data; | |
109 $this->assertEqual($result, $expecting); | |
110 | |
111 Cache::delete('test'); | |
112 } | |
113 | |
114 /** | |
115 * testExpiry method | |
116 * | |
117 * @access public | |
118 * @return void | |
119 */ | |
120 function testExpiry() { | |
121 Cache::set(array('duration' => 1)); | |
122 $result = Cache::read('test'); | |
123 $this->assertFalse($result); | |
124 | |
125 $data = 'this is a test of the emergency broadcasting system'; | |
126 $result = Cache::write('other_test', $data); | |
127 $this->assertTrue($result); | |
128 | |
129 sleep(2); | |
130 $result = Cache::read('other_test'); | |
131 $this->assertFalse($result); | |
132 | |
133 Cache::set(array('duration' => "+1 second")); | |
134 | |
135 $data = 'this is a test of the emergency broadcasting system'; | |
136 $result = Cache::write('other_test', $data); | |
137 $this->assertTrue($result); | |
138 | |
139 sleep(2); | |
140 $result = Cache::read('other_test'); | |
141 $this->assertFalse($result); | |
142 } | |
143 | |
144 /** | |
145 * testDeleteCache method | |
146 * | |
147 * @access public | |
148 * @return void | |
149 */ | |
150 function testDeleteCache() { | |
151 $data = 'this is a test of the emergency broadcasting system'; | |
152 $result = Cache::write('delete_test', $data); | |
153 $this->assertTrue($result); | |
154 | |
155 $result = Cache::delete('delete_test'); | |
156 $this->assertTrue($result); | |
157 } | |
158 | |
159 /** | |
160 * testClearCache method | |
161 * | |
162 * @access public | |
163 * @return void | |
164 */ | |
165 function testClearCache() { | |
166 $data = 'this is a test of the emergency broadcasting system'; | |
167 $result = Cache::write('clear_test_1', $data); | |
168 $this->assertTrue($result); | |
169 | |
170 $result = Cache::write('clear_test_2', $data); | |
171 $this->assertTrue($result); | |
172 | |
173 $result = Cache::clear(); | |
174 $this->assertTrue($result); | |
175 } | |
176 | |
177 /** | |
178 * testDecrement method | |
179 * | |
180 * @access public | |
181 * @return void | |
182 */ | |
183 function testDecrement() { | |
184 $result = Cache::write('test_decrement', 5); | |
185 $this->assertTrue($result); | |
186 | |
187 $result = Cache::decrement('test_decrement'); | |
188 $this->assertEqual(4, $result); | |
189 | |
190 $result = Cache::read('test_decrement'); | |
191 $this->assertEqual(4, $result); | |
192 | |
193 $result = Cache::decrement('test_decrement', 2); | |
194 $this->assertEqual(2, $result); | |
195 | |
196 $result = Cache::read('test_decrement'); | |
197 $this->assertEqual(2, $result); | |
198 } | |
199 | |
200 /** | |
201 * testIncrement method | |
202 * | |
203 * @access public | |
204 * @return void | |
205 */ | |
206 function testIncrement() { | |
207 $result = Cache::write('test_increment', 5); | |
208 $this->assertTrue($result); | |
209 | |
210 $result = Cache::increment('test_increment'); | |
211 $this->assertEqual(6, $result); | |
212 | |
213 $result = Cache::read('test_increment'); | |
214 $this->assertEqual(6, $result); | |
215 | |
216 $result = Cache::increment('test_increment', 2); | |
217 $this->assertEqual(8, $result); | |
218 | |
219 $result = Cache::read('test_increment'); | |
220 $this->assertEqual(8, $result); | |
221 } | |
222 } |