|
4 | 4 | * Test: Nette\Caching\Storages\FileJournal basic test. |
5 | 5 | */ |
6 | 6 |
|
7 | | -use Nette\Caching\Storages\FileJournal, |
8 | | - Nette\Caching\Cache, |
9 | | - Tester\Assert; |
| 7 | +use Nette\Caching\Storages\FileJournal; |
10 | 8 |
|
11 | 9 |
|
12 | 10 | require __DIR__ . '/../bootstrap.php'; |
| 11 | +require __DIR__ . '/IJournalTestCase.inc'; |
13 | 12 |
|
14 | 13 |
|
15 | | -class FileJournalTest extends Tester\TestCase |
| 14 | +class FileJournalTest extends IJournalTestCase |
16 | 15 | { |
17 | | - /** @var FileJournal */ |
18 | | - private $journal; |
19 | 16 |
|
20 | | - |
21 | | - public function setup() |
| 17 | + public function createJournal() |
22 | 18 | { |
23 | 19 | FileJournal::$debug = TRUE; |
24 | | - $this->journal = new FileJournal(TEMP_DIR); |
25 | | - } |
26 | | - |
27 | | - |
28 | | - final public function testOneTag() |
29 | | - { |
30 | | - $this->journal->write('ok_test1', array( |
31 | | - Cache::TAGS => array('test:homepage'), |
32 | | - )); |
33 | | - |
34 | | - Assert::same(array( |
35 | | - 'ok_test1', |
36 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage')))); |
37 | | - } |
38 | | - |
39 | | - |
40 | | - final public function testTwoTagsCleanOne() |
41 | | - { |
42 | | - $this->journal->write('ok_test2', array( |
43 | | - Cache::TAGS => array('test:homepage', 'test:homepage2'), |
44 | | - )); |
45 | | - |
46 | | - Assert::same(array( |
47 | | - 'ok_test2', |
48 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage2')))); |
49 | | - } |
50 | | - |
51 | | - |
52 | | - final public function testTwoTagsCleanBoth() |
53 | | - { |
54 | | - $this->journal->write('ok_test2b', array( |
55 | | - Cache::TAGS => array('test:homepage', 'test:homepage2'), |
56 | | - )); |
57 | | - |
58 | | - Assert::same(array( |
59 | | - 'ok_test2b', |
60 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage', 'test:homepage2')))); |
61 | | - } |
62 | | - |
63 | | - |
64 | | - final public function testTwoSameTags() |
65 | | - { |
66 | | - $this->journal->write('ok_test2c', array( |
67 | | - Cache::TAGS => array('test:homepage', 'test:homepage'), |
68 | | - )); |
69 | | - |
70 | | - Assert::same(array( |
71 | | - 'ok_test2c', |
72 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage', 'test:homepage')))); |
73 | | - } |
74 | | - |
75 | | - |
76 | | - final public function testTagAndPriority() |
77 | | - { |
78 | | - $this->journal->write('ok_test2d', array( |
79 | | - Cache::TAGS => array('test:homepage'), |
80 | | - Cache::PRIORITY => 15, |
81 | | - )); |
82 | | - |
83 | | - Assert::same(array( |
84 | | - 'ok_test2d', |
85 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage'), Cache::PRIORITY => 20))); |
86 | | - } |
87 | | - |
88 | | - |
89 | | - final public function testPriorityOnly() |
90 | | - { |
91 | | - $this->journal->write('ok_test3', array( |
92 | | - Cache::PRIORITY => 10, |
93 | | - )); |
94 | | - |
95 | | - Assert::same(array( |
96 | | - 'ok_test3', |
97 | | - ), $this->journal->clean(array(Cache::PRIORITY => 10))); |
98 | | - } |
99 | | - |
100 | | - |
101 | | - final public function testPriorityAndTagCleanByTag() |
102 | | - { |
103 | | - $this->journal->write('ok_test4', array( |
104 | | - Cache::TAGS => array('test:homepage'), |
105 | | - Cache::PRIORITY => 10, |
106 | | - )); |
107 | | - |
108 | | - Assert::same(array( |
109 | | - 'ok_test4', |
110 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage')))); |
111 | | - } |
112 | | - |
113 | | - |
114 | | - final public function testPriorityAndTagCleanByPriority() |
115 | | - { |
116 | | - $this->journal->write('ok_test5', array( |
117 | | - Cache::TAGS => array('test:homepage'), |
118 | | - Cache::PRIORITY => 10, |
119 | | - )); |
120 | | - |
121 | | - Assert::same(array( |
122 | | - 'ok_test5', |
123 | | - ), $this->journal->clean(array(Cache::PRIORITY => 10))); |
124 | | - } |
125 | | - |
126 | | - |
127 | | - final public function testDifferentCleaning() |
128 | | - { |
129 | | - for ($i = 1; $i <= 10; $i++) { |
130 | | - $this->journal->write('ok_test6_' . $i, array( |
131 | | - Cache::TAGS => array('test:homepage', 'test:homepage/' . $i), |
132 | | - Cache::PRIORITY => $i, |
133 | | - )); |
134 | | - } |
135 | | - |
136 | | - Assert::same(array( |
137 | | - 'ok_test6_1', |
138 | | - 'ok_test6_2', |
139 | | - 'ok_test6_3', |
140 | | - 'ok_test6_4', |
141 | | - 'ok_test6_5', |
142 | | - ), $this->journal->clean(array(Cache::PRIORITY => 5))); |
143 | | - |
144 | | - Assert::same(array( |
145 | | - 'ok_test6_7', |
146 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage/7')))); |
147 | | - |
148 | | - Assert::same(array( |
149 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage/4')))); |
150 | | - |
151 | | - Assert::same(array( |
152 | | - ), $this->journal->clean(array(Cache::PRIORITY => 4))); |
153 | | - |
154 | | - Assert::same(array( |
155 | | - 'ok_test6_6', |
156 | | - 'ok_test6_8', |
157 | | - 'ok_test6_9', |
158 | | - 'ok_test6_10', |
159 | | - ), $this->journal->clean(array(Cache::TAGS => array('test:homepage')))); |
160 | | - } |
161 | | - |
162 | | - |
163 | | - final public function testSpecialChars() |
164 | | - { |
165 | | - $this->journal->write('ok_test7ščřžýáíé', array( |
166 | | - Cache::TAGS => array('čšřýýá', 'ýřžčýž') |
167 | | - )); |
168 | | - |
169 | | - Assert::same(array( |
170 | | - 'ok_test7ščřžýáíé', |
171 | | - ), $this->journal->clean(array(Cache::TAGS => array('čšřýýá')))); |
172 | | - } |
173 | | - |
174 | | - |
175 | | - final public function testDuplicatedSameTags() |
176 | | - { |
177 | | - $this->journal->write('ok_test_a', array( |
178 | | - Cache::TAGS => array('homepage') |
179 | | - )); |
180 | | - $this->journal->write('ok_test_a', array( |
181 | | - Cache::TAGS => array('homepage') |
182 | | - )); |
183 | | - Assert::same(array( |
184 | | - 'ok_test_a', |
185 | | - ), $this->journal->clean(array(Cache::TAGS => array('homepage')))); |
186 | | - } |
187 | | - |
188 | | - |
189 | | - final public function testDuplicatedSamePriority() |
190 | | - { |
191 | | - $this->journal->write('ok_test_b', array( |
192 | | - Cache::PRIORITY => 12 |
193 | | - )); |
194 | | - |
195 | | - $this->journal->write('ok_test_b', array( |
196 | | - Cache::PRIORITY => 12 |
197 | | - )); |
198 | | - |
199 | | - Assert::same(array( |
200 | | - 'ok_test_b', |
201 | | - ), $this->journal->clean(array(Cache::PRIORITY => 12))); |
202 | | - } |
203 | | - |
204 | | - |
205 | | - final public function testDuplicatedDifferentTags() |
206 | | - { |
207 | | - $this->journal->write('ok_test_ba', array( |
208 | | - Cache::TAGS => array('homepage') |
209 | | - )); |
210 | | - |
211 | | - $this->journal->write('ok_test_ba', array( |
212 | | - Cache::TAGS => array('homepage2') |
213 | | - )); |
214 | | - |
215 | | - Assert::same(array( |
216 | | - ), $this->journal->clean(array(Cache::TAGS => array('homepage')))); |
217 | | - |
218 | | - Assert::same(array( |
219 | | - 'ok_test_ba', |
220 | | - ), $this->journal->clean(array(Cache::TAGS => array('homepage2')))); |
221 | | - } |
222 | | - |
223 | | - |
224 | | - final public function testDuplicatedTwoDifferentTags() |
225 | | - { |
226 | | - $this->journal->write('ok_test_baa', array( |
227 | | - Cache::TAGS => array('homepage', 'aąa') |
228 | | - )); |
229 | | - |
230 | | - $this->journal->write('ok_test_baa', array( |
231 | | - Cache::TAGS => array('homepage2', 'aaa') |
232 | | - )); |
233 | | - |
234 | | - Assert::same(array( |
235 | | - ), $this->journal->clean(array(Cache::TAGS => array('homepage')))); |
236 | | - |
237 | | - Assert::same(array( |
238 | | - 'ok_test_baa', |
239 | | - ), $this->journal->clean(array(Cache::TAGS => array('homepage2')))); |
240 | | - } |
241 | | - |
242 | | - |
243 | | - final public function testDuplicatedDifferentPriorities() |
244 | | - { |
245 | | - $this->journal->write('ok_test_bb', array( |
246 | | - Cache::PRIORITY => 15 |
247 | | - )); |
248 | | - |
249 | | - $this->journal->write('ok_test_bb', array( |
250 | | - Cache::PRIORITY => 20 |
251 | | - )); |
252 | | - |
253 | | - Assert::same(array( |
254 | | - 'ok_test_bb', |
255 | | - ), $this->journal->clean(array(Cache::PRIORITY => 30))); |
256 | | - } |
257 | | - |
258 | | - |
259 | | - final public function testCleanAll() |
260 | | - { |
261 | | - $this->journal->write('ok_test_all_tags', array( |
262 | | - Cache::TAGS => array('test:all', 'test:all') |
263 | | - )); |
264 | | - |
265 | | - $this->journal->write('ok_test_all_priority', array( |
266 | | - Cache::PRIORITY => 5, |
267 | | - )); |
268 | | - |
269 | | - Assert::null($this->journal->clean(array(Cache::ALL => TRUE))); |
270 | | - Assert::same(array( |
271 | | - ), $this->journal->clean(array(Cache::TAGS => 'test:all'))); |
272 | | - } |
273 | | - |
274 | | - |
275 | | - final public function testRemoveItemWithMultipleTags() |
276 | | - { |
277 | | - $this->journal->write('a', array(Cache::TAGS => array('gamma'))); |
278 | | - $this->journal->write('b', array(Cache::TAGS => array('alpha', 'beta', 'gamma'))); |
279 | | - Assert::same(array( |
280 | | - 'b', |
281 | | - 'a', |
282 | | - ), $this->journal->clean(array(Cache::TAGS => array('alpha', 'beta', 'gamma')))); |
| 20 | + return new FileJournal(TEMP_DIR); |
283 | 21 | } |
284 | 22 |
|
285 | 23 | } |
|
0 commit comments