TYPO3 CMS  TYPO3_7-6
FileBackendTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
27 {
33  protected function setUp()
34  {
35  if (!class_exists('org\\bovigo\\vfs\\vfsStreamWrapper')) {
36  $this->markTestSkipped('File backend tests are not available with this phpunit version.');
37  }
38 
39  vfsStreamWrapper::register();
40  vfsStreamWrapper::setRoot(new vfsStreamDirectory('Foo'));
41  }
42 
48  {
49  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
50 
51  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
52  $backend->setCacheDirectory('http://localhost/');
53 
54  $backend->setCache($mockCache);
55  }
56 
61  {
62  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
63  $backend->_set('cacheIdentifier', 'test');
64  $backend->setCacheDirectory('/tmp/foo');
65  $this->assertEquals('/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
66  }
67 
72  {
73  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
74  $backend->_set('cacheIdentifier', 'test');
75  $backend->setCacheDirectory('/tmp/foo/');
76  $this->assertEquals('/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
77  }
78 
83  {
84  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
85  $backend->_set('cacheIdentifier', 'test');
86  $backend->setCacheDirectory('tmp/foo');
87  // get PATH_site without trailing slash
88  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
89  $this->assertEquals($path . '/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
90  }
91 
96  {
97  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
98  $backend->_set('cacheIdentifier', 'test');
99  $backend->setCacheDirectory('tmp/foo/');
100  // get PATH_site without trailing slash
101  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
102  $this->assertEquals($path . '/tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
103  }
104 
109  {
110  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
111  $backend->_set('cacheIdentifier', 'test');
112  $backend->setCacheDirectory('../tmp/foo');
113  // get PATH_site without trailing slash
114  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
115  $this->assertEquals($path . '/../tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
116  }
117 
122  {
123  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
124  $backend->_set('cacheIdentifier', 'test');
125  $backend->setCacheDirectory('../tmp/foo/');
126  // get PATH_site without trailing slash
127  $path = GeneralUtility::fixWindowsFilePath(realpath(PATH_site));
128  $this->assertEquals($path . '/../tmp/foo/test/', $backend->_get('temporaryCacheDirectory'));
129  }
130 
135  {
136  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
137  $backend->_set('cacheIdentifier', 'test');
138  $backend->setCacheDirectory('/tmp/../foo');
139  $this->assertEquals('/tmp/../foo/test/', $backend->_get('temporaryCacheDirectory'));
140  }
141 
146  {
147  $backend = $this->getAccessibleMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
148  $backend->_set('cacheIdentifier', 'test');
149  $backend->setCacheDirectory('/tmp/../foo/');
150  $this->assertEquals('/tmp/../foo/test/', $backend->_get('temporaryCacheDirectory'));
151  }
152 
157  {
158  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
159  $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('SomeCache'));
160 
161  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
162  $backend->setCacheDirectory('vfs://Foo/');
163  $backend->setCache($mockCache);
164 
165  $this->assertEquals('vfs://Foo/Cache/Data/SomeCache/', $backend->getCacheDirectory());
166  }
167 
172  {
173  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, [], [], '', false);
174  $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('SomeCache'));
175 
176  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
177  $backend->setCacheDirectory('vfs://Foo/');
178  $backend->setCache($mockCache);
179 
180  $this->assertEquals('vfs://Foo/Cache/Code/SomeCache/', $backend->getCacheDirectory());
181  }
182 
188  {
189  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
190 
191  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
192  $backend->setCacheDirectory('vfs://Foo/');
193  $backend->setCache($mockCache);
194 
195  $backend->set('some identifier', ['not a string']);
196  }
197 
202  {
203  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
204  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
205 
206  $data = 'some data' . microtime();
207  $entryIdentifier = 'BackendFileTest';
208  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
209 
210  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
211  $backend->setCacheDirectory('vfs://Foo/');
212  $backend->setCache($mockCache);
213 
214  $backend->set($entryIdentifier, $data);
215 
216  $this->assertFileExists($pathAndFilename);
217  $retrievedData = file_get_contents($pathAndFilename, null, null, 0, strlen($data));
218  $this->assertEquals($data, $retrievedData);
219  }
220 
225  {
226  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
227  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
228 
229  $data1 = 'some data' . microtime();
230  $data2 = 'some data' . microtime();
231  $entryIdentifier = 'BackendFileRemoveBeforeSetTest';
232 
233  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
234  $backend->setCacheDirectory('vfs://Foo/');
235  $backend->setCache($mockCache);
236 
237  $backend->set($entryIdentifier, $data1, [], 500);
238  $backend->set($entryIdentifier, $data2, [], 200);
239 
240  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
241  $this->assertFileExists($pathAndFilename);
242  $retrievedData = file_get_contents($pathAndFilename, null, null, 0, strlen($data2));
243  $this->assertEquals($data2, $retrievedData);
244  }
245 
249  public function setAlsoSavesSpecifiedTags()
250  {
251  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
252  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
253 
254  $data = 'some data' . microtime();
255  $entryIdentifier = 'BackendFileRemoveBeforeSetTest';
256 
257  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
258  $backend->setCacheDirectory('vfs://Foo/');
259  $backend->setCache($mockCache);
260 
261  $backend->set($entryIdentifier, $data, ['Tag1', 'Tag2']);
262 
263  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
264  $this->assertFileExists($pathAndFilename);
265  $retrievedData = file_get_contents($pathAndFilename, null, null, (strlen($data) + \TYPO3\CMS\Core\Cache\Backend\FileBackend::EXPIRYTIME_LENGTH), 9);
266  $this->assertEquals('Tag1 Tag2', $retrievedData);
267  }
268 
273  {
274  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
275  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
276 
277  $data = 'some data' . microtime();
278  $entryIdentifier = 'BackendFileTest';
279 
280  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
281  $backend->setCacheDirectory('vfs://Foo/');
282  $backend->setCache($mockCache);
283 
284  $backend->set($entryIdentifier, $data, ['Tag1', 'Tag2']);
285 
286  $backend->freeze();
287 
288  unset($backend);
289 
290  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
291  $backend->setCacheDirectory('vfs://Foo/');
292  $backend->setCache($mockCache);
293 
294  $this->assertTrue($backend->isFrozen());
295  $this->assertEquals($data, $backend->get($entryIdentifier));
296  }
297 
302  {
303  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
304  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
305 
306  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['setTag'], [], '', false);
307  $backend->setCacheDirectory('vfs://Foo/');
308  $backend->setCache($mockCache);
309 
310  $entryIdentifier = 'BackendFileTest';
311 
312  $data = 'some data' . microtime();
313  $backend->set($entryIdentifier, $data, [], 500);
314 
315  $data = 'some other data' . microtime();
316  $backend->set($entryIdentifier, $data, [], 100);
317 
318  $loadedData = $backend->get($entryIdentifier);
319  $this->assertEquals($data, $loadedData);
320  }
321 
326  {
327  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
328  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
329 
330  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['isCacheFileExpired'], [], '', false);
331  $backend->expects($this->once())->method('isCacheFileExpired')->with('vfs://Foo/Cache/Data/UnitTestCache/ExpiredEntry')->will($this->returnValue(true));
332  $backend->setCacheDirectory('vfs://Foo/');
333  $backend->setCache($mockCache);
334 
335  $this->assertFalse($backend->get('ExpiredEntry'));
336  }
337 
342  {
343  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
344  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
345 
346  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['isCacheFileExpired'], [], '', false);
347  $backend->setCacheDirectory('vfs://Foo/');
348  $backend->setCache($mockCache);
349 
350  $backend->expects($this->once())->method('isCacheFileExpired');
351 
352  $backend->set('foo', 'some data');
353  $backend->freeze();
354  $this->assertEquals('some data', $backend->get('foo'));
355  $this->assertFalse($backend->get('bar'));
356  }
357 
362  {
363  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
364  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
365 
366  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
367  $backend->setCacheDirectory('vfs://Foo/');
368  $backend->setCache($mockCache);
369 
370  $entryIdentifier = 'BackendFileTest';
371 
372  $data = 'some data' . microtime();
373  $backend->set($entryIdentifier, $data);
374 
375  $this->assertTrue($backend->has($entryIdentifier), 'has() did not return TRUE.');
376  $this->assertFalse($backend->has($entryIdentifier . 'Not'), 'has() did not return FALSE.');
377  }
378 
383  {
384  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['isCacheFileExpired'], [], '', false);
385  $backend->expects($this->exactly(2))->method('isCacheFileExpired')->will($this->onConsecutiveCalls(true, false));
386 
387  $this->assertFalse($backend->has('foo'));
388  $this->assertTrue($backend->has('bar'));
389  }
390 
395  {
396  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
397  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
398 
399  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['isCacheFileExpired'], [], '', false);
400  $backend->setCacheDirectory('vfs://Foo/');
401  $backend->setCache($mockCache);
402 
403  $backend->expects($this->once())->method('isCacheFileExpired'); // Indirectly called by freeze() -> get()
404 
405  $backend->set('foo', 'some data');
406  $backend->freeze();
407  $this->assertTrue($backend->has('foo'));
408  $this->assertFalse($backend->has('bar'));
409  }
410 
415  {
416  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
417  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
418 
419  $data = 'some data' . microtime();
420  $entryIdentifier = 'BackendFileTest';
421  $pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
422 
423  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
424  $backend->setCacheDirectory('vfs://Foo/');
425  $backend->setCache($mockCache);
426 
427  $backend->set($entryIdentifier, $data);
428  $this->assertFileExists($pathAndFilename);
429 
430  $backend->remove($entryIdentifier);
431  $this->assertFileNotExists($pathAndFilename);
432  }
433 
436  public function invalidEntryIdentifiers()
437  {
438  return [
439  'trailing slash' => ['/myIdentifer'],
440  'trailing dot and slash' => ['./myIdentifer'],
441  'trailing two dots and slash' => ['../myIdentifier'],
442  'trailing with multiple dots and slashes' => ['.././../myIdentifier'],
443  'slash in middle part' => ['my/Identifier'],
444  'dot and slash in middle part' => ['my./Identifier'],
445  'two dots and slash in middle part' => ['my../Identifier'],
446  'multiple dots and slashes in middle part' => ['my.././../Identifier'],
447  'pending slash' => ['myIdentifier/'],
448  'pending dot and slash' => ['myIdentifier./'],
449  'pending dots and slash' => ['myIdentifier../'],
450  'pending multiple dots and slashes' => ['myIdentifier.././../'],
451  ];
452  }
453 
459  public function setThrowsExceptionForInvalidIdentifier($identifier)
460  {
461  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
462  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
463 
464  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], ['test'], '', true);
465  $backend->setCacheDirectory('vfs://Foo/');
466  $backend->setCache($mockCache);
467 
468  $backend->set($identifier, 'cache data', []);
469  }
470 
476  public function getThrowsExceptionForInvalidIdentifier($identifier)
477  {
478  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
479  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
480 
481  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
482  $backend->setCacheDirectory('vfs://Foo/');
483  $backend->setCache($mockCache);
484 
485  $backend->get($identifier);
486  }
487 
493  public function hasThrowsExceptionForInvalidIdentifier($identifier)
494  {
495  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
496 
497  $backend->has($identifier);
498  }
499 
505  public function removeThrowsExceptionForInvalidIdentifier($identifier)
506  {
507  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
508  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
509 
510  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
511  $backend->setCacheDirectory('vfs://Foo/');
512  $backend->setCache($mockCache);
513 
514  $backend->remove($identifier);
515  }
516 
523  {
524  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
525  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
526 
527  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
528  $backend->setCacheDirectory('vfs://Foo/');
529  $backend->setCache($mockCache);
530 
531  $backend->requireOnce($identifier);
532  }
533 
538  {
539  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
540  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
541 
542  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
543  $backend->setCacheDirectory('vfs://Foo/');
544  $backend->setCache($mockCache);
545 
546  $entryIdentifier = 'SomePhpEntry';
547 
548  $data = '<?php return "foo"; ?>';
549  $backend->set($entryIdentifier, $data);
550 
551  $loadedData = $backend->requireOnce($entryIdentifier);
552  $this->assertEquals('foo', $loadedData);
553  }
554 
559  {
560  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
561  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
562 
563  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['isCacheFileExpired'], [], '', false);
564  $backend->setCacheDirectory('vfs://Foo/');
565  $backend->setCache($mockCache);
566 
567  $backend->expects($this->once())->method('isCacheFileExpired'); // Indirectly called by freeze() -> get()
568 
569  $data = '<?php return "foo"; ?>';
570  $backend->set('FooEntry', $data);
571 
572  $backend->freeze();
573 
574  $loadedData = $backend->requireOnce('FooEntry');
575  $this->assertEquals('foo', $loadedData);
576  }
577 
582  {
583  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
584  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
585 
586  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
587  $backend->setCacheDirectory('vfs://Foo/');
588  $backend->setCache($mockCache);
589 
590  $data = 'some data' . microtime();
591  $backend->set('BackendFileTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
592  $backend->set('BackendFileTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
593  $backend->set('BackendFileTest3', $data, ['UnitTestTag%test']);
594 
595  $expectedEntry = 'BackendFileTest2';
596 
597  $actualEntries = $backend->findIdentifiersByTag('UnitTestTag%special');
598  $this->assertInternalType('array', $actualEntries);
599  $this->assertEquals($expectedEntry, array_pop($actualEntries));
600  }
601 
606  {
607  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
608  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
609 
610  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
611  $backend->setCacheDirectory('vfs://Foo/');
612  $backend->setCache($mockCache);
613 
614  $data = 'some data';
615  $backend->set('BackendFileTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
616  $backend->set('BackendFileTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special'], -100);
617  $backend->set('BackendFileTest3', $data, ['UnitTestTag%test']);
618 
619  $this->assertSame([], $backend->findIdentifiersByTag('UnitTestTag%special'));
620  $this->assertSame(['BackendFileTest1', 'BackendFileTest3'], $backend->findIdentifiersByTag('UnitTestTag%test'));
621  }
622 
626  public function flushRemovesAllCacheEntries()
627  {
628  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
629  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
630 
631  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
632  $backend->setCacheDirectory('vfs://Foo/');
633  $backend->setCache($mockCache);
634 
635  $data = 'some data';
636  $backend->set('BackendFileTest1', $data);
637  $backend->set('BackendFileTest2', $data);
638 
639  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
640  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
641 
642  $backend->flush();
643 
644  $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
645  $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
646  }
647 
652  {
653  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
654  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
655 
656  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
657  $backend->setCacheDirectory('vfs://Foo/');
658  $backend->setCache($mockCache);
659 
660  $backend->flush();
661  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/');
662  }
663 
668  {
669  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['findIdentifiersByTag', 'remove'], [], '', false);
670 
671  $backend->expects($this->once())->method('findIdentifiersByTag')->with('UnitTestTag%special')->will($this->returnValue(['foo', 'bar', 'baz']));
672  $backend->expects($this->at(1))->method('remove')->with('foo');
673  $backend->expects($this->at(2))->method('remove')->with('bar');
674  $backend->expects($this->at(3))->method('remove')->with('baz');
675 
676  $backend->flushByTag('UnitTestTag%special');
677  }
678 
683  {
684  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
685  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
686 
687  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['isCacheFileExpired'], [], '', false);
688  $backend->expects($this->exactly(2))->method('isCacheFileExpired')->will($this->onConsecutiveCalls(true, false));
689  $backend->setCacheDirectory('vfs://Foo/');
690  $backend->setCache($mockCache);
691 
692  $data = 'some data';
693  $backend->set('BackendFileTest1', $data);
694  $backend->set('BackendFileTest2', $data);
695 
696  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
697  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
698 
699  $backend->collectGarbage();
700  $this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
701  $this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
702  }
703 
707  public function flushUnfreezesTheCache()
708  {
709  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], [], '', false);
710  $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
711 
712  $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class, ['dummy'], [], '', false);
713  $backend->setCacheDirectory('vfs://Foo/');
714  $backend->setCache($mockCache);
715 
716  $backend->freeze();
717 
718  $this->assertTrue($backend->isFrozen());
719  $backend->flush();
720  $this->assertFalse($backend->isFrozen());
721  }
722 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)