TYPO3 CMS  TYPO3_6-2
FileBackendTest.php
Go to the documentation of this file.
1 <?php
3 
17 use \org\bovigo\vfs\vfsStreamDirectory;
18 use \org\bovigo\vfs\vfsStreamWrapper;
20 
30 
36  public function setUp() {
37  if (!class_exists('org\\bovigo\\vfs\\vfsStreamWrapper')) {
38  $this->markTestSkipped('File backend tests are not available with this phpunit version.');
39  }
40 
41  vfsStreamWrapper::register();
42  vfsStreamWrapper::setRoot(new vfsStreamDirectory('Foo'));
43  }
44 
50  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
51 
52  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
53  $backend->setCacheDirectory('http://localhost/');
54 
55  $backend->setCache($mockCache);
56  }
57 
62  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
63  $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('SomeCache'));
64 
65  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
66  $backend->setCacheDirectory('vfs://Foo/');
67  $backend->setCache($mockCache);
68 
69  $this->assertEquals('vfs://Foo/Cache/Data/SomeCache/', $backend->getCacheDirectory());
70  }
71 
76  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\PhpFrontend', array(), array(), '', FALSE);
77  $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('SomeCache'));
78 
79  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
80  $backend->setCacheDirectory('vfs://Foo/');
81  $backend->setCache($mockCache);
82 
83  $this->assertEquals('vfs://Foo/Cache/Code/SomeCache/', $backend->getCacheDirectory());
84  }
85 
91  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
92 
93  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
94  $backend->setCacheDirectory('vfs://Foo/');
95  $backend->setCache($mockCache);
96 
97  $backend->set('some identifier', array('not a string'));
98  }
99 
104  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
105  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
106 
107  $data = 'some data' . microtime();
108  $entryIdentifier = 'BackendFileTest';
109  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
110 
111  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
112  $backend->setCacheDirectory('vfs://Foo/');
113  $backend->setCache($mockCache);
114 
115  $backend->set($entryIdentifier, $data);
116 
117  $this->assertFileExists($pathAndFilename);
118  $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, 0, strlen($data));
119  $this->assertEquals($data, $retrievedData);
120  }
121 
126  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
127  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
128 
129  $data1 = 'some data' . microtime();
130  $data2 = 'some data' . microtime();
131  $entryIdentifier = 'BackendFileRemoveBeforeSetTest';
132 
133  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
134  $backend->setCacheDirectory('vfs://Foo/');
135  $backend->setCache($mockCache);
136 
137  $backend->set($entryIdentifier, $data1, array(), 500);
138  $backend->set($entryIdentifier, $data2, array(), 200);
139 
140  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
141  $this->assertFileExists($pathAndFilename);
142  $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, 0, strlen($data2));
143  $this->assertEquals($data2, $retrievedData);
144  }
145 
149  public function setAlsoSavesSpecifiedTags() {
150  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
151  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
152 
153  $data = 'some data' . microtime();
154  $entryIdentifier = 'BackendFileRemoveBeforeSetTest';
155 
156  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
157  $backend->setCacheDirectory('vfs://Foo/');
158  $backend->setCache($mockCache);
159 
160  $backend->set($entryIdentifier, $data, array('Tag1', 'Tag2'));
161 
162  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
163  $this->assertFileExists($pathAndFilename);
164  $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, (strlen($data) + \TYPO3\CMS\Core\Cache\Backend\FileBackend::EXPIRYTIME_LENGTH), 9);
165  $this->assertEquals('Tag1 Tag2', $retrievedData);
166  }
167 
172  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
173  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
174 
175  $data = 'some data' . microtime();
176  $entryIdentifier = 'BackendFileTest';
177 
178  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
179  $backend->setCacheDirectory('vfs://Foo/');
180  $backend->setCache($mockCache);
181 
182  $backend->set($entryIdentifier, $data, array('Tag1', 'Tag2'));
183 
184  $backend->freeze();
185 
186  unset($backend);
187 
188  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
189  $backend->setCacheDirectory('vfs://Foo/');
190  $backend->setCache($mockCache);
191 
192  $this->assertTrue($backend->isFrozen());
193  $this->assertEquals($data, $backend->get($entryIdentifier));
194  }
195 
200  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
201  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
202 
203  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('setTag'), array(), '', FALSE);
204  $backend->setCacheDirectory('vfs://Foo/');
205  $backend->setCache($mockCache);
206 
207  $entryIdentifier = 'BackendFileTest';
208 
209  $data = 'some data' . microtime();
210  $backend->set($entryIdentifier, $data, array(), 500);
211 
212  $data = 'some other data' . microtime();
213  $backend->set($entryIdentifier, $data, array(), 100);
214 
215  $loadedData = $backend->get($entryIdentifier);
216  $this->assertEquals($data, $loadedData);
217  }
218 
223  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
224  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
225 
226  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('isCacheFileExpired'), array(), '', FALSE);
227  $backend->expects($this->once())->method('isCacheFileExpired')->with('vfs://Foo/Cache/Data/UnitTestCache/ExpiredEntry')->will($this->returnValue(TRUE));
228  $backend->setCacheDirectory('vfs://Foo/');
229  $backend->setCache($mockCache);
230 
231  $this->assertFalse($backend->get('ExpiredEntry'));
232  }
233 
238  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
239  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
240 
241  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('isCacheFileExpired'), array(), '', FALSE);
242  $backend->setCacheDirectory('vfs://Foo/');
243  $backend->setCache($mockCache);
244 
245  $backend->expects($this->once())->method('isCacheFileExpired');
246 
247  $backend->set('foo', 'some data');
248  $backend->freeze();
249  $this->assertEquals('some data', $backend->get('foo'));
250  $this->assertFalse($backend->get('bar'));
251  }
252 
256  public function hasReturnsTrueIfAnEntryExists() {
257  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
258  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
259 
260  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
261  $backend->setCacheDirectory('vfs://Foo/');
262  $backend->setCache($mockCache);
263 
264  $entryIdentifier = 'BackendFileTest';
265 
266  $data = 'some data' . microtime();
267  $backend->set($entryIdentifier, $data);
268 
269  $this->assertTrue($backend->has($entryIdentifier), 'has() did not return TRUE.');
270  $this->assertFalse($backend->has($entryIdentifier . 'Not'), 'has() did not return FALSE.');
271  }
272 
277  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('isCacheFileExpired'), array(), '', FALSE);
278  $backend->expects($this->exactly(2))->method('isCacheFileExpired')->will($this->onConsecutiveCalls(TRUE, FALSE));
279 
280  $this->assertFalse($backend->has('foo'));
281  $this->assertTrue($backend->has('bar'));
282  }
283 
288  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
289  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
290 
291  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('isCacheFileExpired'), array(), '', FALSE);
292  $backend->setCacheDirectory('vfs://Foo/');
293  $backend->setCache($mockCache);
294 
295  $backend->expects($this->once())->method('isCacheFileExpired'); // Indirectly called by freeze() -> get()
296 
297  $backend->set('foo', 'some data');
298  $backend->freeze();
299  $this->assertTrue($backend->has('foo'));
300  $this->assertFalse($backend->has('bar'));
301  }
302 
306  public function removeReallyRemovesACacheEntry() {
307  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
308  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
309 
310  $data = 'some data' . microtime();
311  $entryIdentifier = 'BackendFileTest';
312  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
313 
314  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
315  $backend->setCacheDirectory('vfs://Foo/');
316  $backend->setCache($mockCache);
317 
318  $backend->set($entryIdentifier, $data);
319  $this->assertFileExists($pathAndFilename);
320 
321  $backend->remove($entryIdentifier);
322  $this->assertFileNotExists($pathAndFilename);
323  }
324 
327  public function invalidEntryIdentifiers() {
328  return array(
329  'trailing slash' => array('/myIdentifer'),
330  'trailing dot and slash' => array('./myIdentifer'),
331  'trailing two dots and slash' => array('../myIdentifier'),
332  'trailing with multiple dots and slashes' => array('.././../myIdentifier'),
333  'slash in middle part' => array('my/Identifier'),
334  'dot and slash in middle part' => array('my./Identifier'),
335  'two dots and slash in middle part' => array('my../Identifier'),
336  'multiple dots and slashes in middle part' => array('my.././../Identifier'),
337  'pending slash' => array('myIdentifier/'),
338  'pending dot and slash' => array('myIdentifier./'),
339  'pending dots and slash' => array('myIdentifier../'),
340  'pending multiple dots and slashes' => array('myIdentifier.././../'),
341  );
342  }
343 
349  public function setThrowsExceptionForInvalidIdentifier($identifier) {
350  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
351  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
352 
353  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array('test'), '', TRUE);
354  $backend->setCacheDirectory('vfs://Foo/');
355  $backend->setCache($mockCache);
356 
357  $backend->set($identifier, 'cache data', array());
358  }
359 
365  public function getThrowsExceptionForInvalidIdentifier($identifier) {
366  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
367  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
368 
369  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
370  $backend->setCacheDirectory('vfs://Foo/');
371  $backend->setCache($mockCache);
372 
373  $backend->get($identifier);
374  }
375 
380  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
381  $backend->_set('cacheIdentifier', 'test');
382  $backend->setCacheDirectory('/tmp/foo');
383  $this->assertEquals('/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
384  }
385 
390  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
391  $backend->_set('cacheIdentifier', 'test');
392  $backend->setCacheDirectory('/tmp/foo/');
393  $this->assertEquals('/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
394  }
395 
400  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
401  $backend->_set('cacheIdentifier', 'test');
402  $backend->setCacheDirectory('tmp/foo');
403  // get PATH_site without trailing slash
404  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
405  $this->assertEquals($path . '/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
406  }
407 
412  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
413  $backend->_set('cacheIdentifier', 'test');
414  $backend->setCacheDirectory('tmp/foo/');
415  // get PATH_site without trailing slash
416  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
417  $this->assertEquals($path . '/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
418  }
419 
424  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
425  $backend->_set('cacheIdentifier', 'test');
426  $backend->setCacheDirectory('../tmp/foo');
427  // get PATH_site without trailing slash
428  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
429  $this->assertEquals($path . '/../tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
430  }
431 
436  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
437  $backend->_set('cacheIdentifier', 'test');
438  $backend->setCacheDirectory('../tmp/foo/');
439  // get PATH_site without trailing slash
440  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
441  $this->assertEquals($path . '/../tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
442  }
443 
448  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
449  $backend->_set('cacheIdentifier', 'test');
450  $backend->setCacheDirectory('/tmp/../foo');
451  $this->assertEquals('/tmp/../foo/test/', $backend->_get('temporaryCacheDirectory'));
452  }
453 
458  $backend = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', false);
459  $backend->_set('cacheIdentifier', 'test');
460  $backend->setCacheDirectory('/tmp/../foo/');
461  $this->assertEquals('/tmp/../foo/test/', $backend->_get('temporaryCacheDirectory'));
462  }
463 
464 
470  public function hasThrowsExceptionForInvalidIdentifier($identifier) {
471  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
472 
473  $backend->has($identifier);
474  }
475 
481  public function removeThrowsExceptionForInvalidIdentifier($identifier) {
482  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
483  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
484 
485  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
486  $backend->setCacheDirectory('vfs://Foo/');
487  $backend->setCache($mockCache);
488 
489  $backend->remove($identifier);
490  }
491 
497  public function requireOnceThrowsExceptionForInvalidIdentifier($identifier) {
498  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
499  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
500 
501  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
502  $backend->setCacheDirectory('vfs://Foo/');
503  $backend->setCache($mockCache);
504 
505  $backend->requireOnce($identifier);
506  }
507 
512  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
513  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
514 
515  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
516  $backend->setCacheDirectory('vfs://Foo/');
517  $backend->setCache($mockCache);
518 
519  $entryIdentifier = 'SomePhpEntry';
520 
521  $data = '<?php return "foo"; ?>';
522  $backend->set($entryIdentifier, $data);
523 
524  $loadedData = $backend->requireOnce($entryIdentifier);
525  $this->assertEquals('foo', $loadedData);
526  }
527 
532  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
533  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
534 
535  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('isCacheFileExpired'), array(), '', FALSE);
536  $backend->setCacheDirectory('vfs://Foo/');
537  $backend->setCache($mockCache);
538 
539  $backend->expects($this->once())->method('isCacheFileExpired'); // Indirectly called by freeze() -> get()
540 
541  $data = '<?php return "foo"; ?>';
542  $backend->set('FooEntry', $data);
543 
544  $backend->freeze();
545 
546  $loadedData = $backend->requireOnce('FooEntry');
547  $this->assertEquals('foo', $loadedData);
548  }
549 
554  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
555  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
556 
557  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
558  $backend->setCacheDirectory('vfs://Foo/');
559  $backend->setCache($mockCache);
560 
561  $data = 'some data' . microtime();
562  $backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
563  $backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
564  $backend->set('BackendFileTest3', $data, array('UnitTestTag%test'));
565 
566  $expectedEntry = 'BackendFileTest2';
567 
568  $actualEntries = $backend->findIdentifiersByTag('UnitTestTag%special');
569  $this->assertInternalType('array', $actualEntries);
570  $this->assertEquals($expectedEntry, array_pop($actualEntries));
571  }
572 
577  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
578  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
579 
580  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
581  $backend->setCacheDirectory('vfs://Foo/');
582  $backend->setCache($mockCache);
583 
584  $data = 'some data';
585  $backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
586  $backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'), -100);
587  $backend->set('BackendFileTest3', $data, array('UnitTestTag%test'));
588 
589  $this->assertSame(array(), $backend->findIdentifiersByTag('UnitTestTag%special'));
590  $this->assertSame(array('BackendFileTest1', 'BackendFileTest3'), $backend->findIdentifiersByTag('UnitTestTag%test'));
591  }
592 
596  public function flushRemovesAllCacheEntries() {
597  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
598  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
599 
600  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
601  $backend->setCacheDirectory('vfs://Foo/');
602  $backend->setCache($mockCache);
603 
604  $data = 'some data';
605  $backend->set('BackendFileTest1', $data);
606  $backend->set('BackendFileTest2', $data);
607 
608  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
609  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
610 
611  $backend->flush();
612 
613  $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
614  $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
615  }
616 
621  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
622  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
623 
624  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
625  $backend->setCacheDirectory('vfs://Foo/');
626  $backend->setCache($mockCache);
627 
628  $backend->flush();
629  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/');
630  }
631 
636  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('findIdentifiersByTag', 'remove'), array(), '', FALSE);
637 
638  $backend->expects($this->once())->method('findIdentifiersByTag')->with('UnitTestTag%special')->will($this->returnValue(array('foo', 'bar', 'baz')));
639  $backend->expects($this->at(1))->method('remove')->with('foo');
640  $backend->expects($this->at(2))->method('remove')->with('bar');
641  $backend->expects($this->at(3))->method('remove')->with('baz');
642 
643  $backend->flushByTag('UnitTestTag%special');
644  }
645 
650  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
651  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
652 
653  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('isCacheFileExpired'), array(), '', FALSE);
654  $backend->expects($this->exactly(2))->method('isCacheFileExpired')->will($this->onConsecutiveCalls(TRUE, FALSE));
655  $backend->setCacheDirectory('vfs://Foo/');
656  $backend->setCache($mockCache);
657 
658  $data = 'some data';
659  $backend->set('BackendFileTest1', $data);
660  $backend->set('BackendFileTest2', $data);
661 
662  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
663  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
664 
665  $backend->collectGarbage();
666  $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
667  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
668  }
669 
673  public function flushUnfreezesTheCache() {
674  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), array(), '', FALSE);
675  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
676 
677  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', array('dummy'), array(), '', FALSE);
678  $backend->setCacheDirectory('vfs://Foo/');
679  $backend->setCache($mockCache);
680 
681  $backend->freeze();
682 
683  $this->assertTrue($backend->isFrozen());
684  $backend->flush();
685  $this->assertFalse($backend->isFrozen());
686  }
687 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)