|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Ingo Renner <ingo@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Testcase for the File cache backend 00027 * 00028 * This file is a backport from FLOW3 00029 * 00030 * @author Ingo Renner <ingo@typo3.org> 00031 * @author Christian Kuhn <lolli@schwarzbu.ch> 00032 * @package TYPO3 00033 * @subpackage tests 00034 * @version $Id: t3lib_cache_backend_filebackendTest.php 10121 2011-01-18 20:15:30Z ohader $ 00035 */ 00036 class t3lib_cache_backend_FileBackendTest extends tx_phpunit_testcase { 00037 /** 00038 * Backup of global variable EXEC_TIME 00039 * 00040 * @var array 00041 */ 00042 protected $backupGlobalVariables; 00043 00044 /** 00045 * If set, the tearDown() method will clean up the cache subdirectory used by this unit test. 00046 * 00047 * @var t3lib_cache_backend_FileBackend 00048 */ 00049 protected $backend; 00050 00051 /** 00052 * @var string Directory for testing data, relative to PATH_site 00053 */ 00054 protected $testingCacheDirectory; 00055 00056 /** 00057 * Sets up this testcase 00058 * 00059 * @return void 00060 */ 00061 public function setUp() { 00062 $this->backupGlobalVariables = array( 00063 'EXEC_TIME' => $GLOBALS['EXEC_TIME'], 00064 ); 00065 00066 $this->testingCacheDirectory = 'typo3temp/cache/testing/'; 00067 00068 $this->backend = t3lib_div::makeInstance( 00069 't3lib_cache_backend_FileBackend', 00070 array('cacheDirectory' => $this->testingCacheDirectory) 00071 ); 00072 } 00073 00074 /** 00075 * @test 00076 * @author Robert Lemke <robert@typo3.org> 00077 * @author Ingo Renner <ingo@typo3.org> 00078 */ 00079 public function defaultCacheDirectoryIsWritable() { 00080 $cacheDirectory = $this->backend->getCacheDirectory(); 00081 00082 $this->assertTrue(is_writable($cacheDirectory), 'The default cache directory "' . $cacheDirectory . '" is not writable.'); 00083 } 00084 00085 /** 00086 * @test 00087 * @author Robert Lemke <robert@typo3.org> 00088 */ 00089 public function setCacheDirectoryThrowsExceptionOnNonWritableDirectory() { 00090 if (TYPO3_OS == 'WIN') { 00091 $this->markTestSkipped('test not reliable in Windows environment'); 00092 } 00093 00094 // Create test directory and remove write permissions 00095 $directoryName = PATH_site . 'typo3temp/' . uniqid('test_'); 00096 t3lib_div::mkdir($directoryName); 00097 chmod($directoryName, 1551); 00098 00099 try { 00100 $this->backend->setCacheDirectory($directoryName); 00101 $this->fail('setCacheDirectory did not throw an exception on a non writable directory'); 00102 } catch (t3lib_cache_Exception $e) { 00103 // Remove created test directory 00104 t3lib_div::rmdir($directoryName); 00105 } 00106 } 00107 00108 /** 00109 * @test 00110 * @author Robert Lemke <robert@typo3.org> 00111 * @author Ingo Renner <ingo@typo3.org> 00112 */ 00113 public function getCacheDirectoryReturnsTheCurrentCacheDirectory() { 00114 $directory = $this->testingCacheDirectory; 00115 $fullPathToDirectory = PATH_site . $directory; 00116 00117 $this->backend->setCacheDirectory($directory); 00118 $this->assertEquals($fullPathToDirectory, $this->backend->getCacheDirectory(), 'getCacheDirectory() did not return the expected value.'); 00119 } 00120 00121 /** 00122 * @test 00123 * @author Robert Lemke <robert@typo3.org> 00124 * @author Ingo Renner <ingo@typo3.org> 00125 * @expectedException t3lib_cache_exception_InvalidData 00126 */ 00127 public function setThrowsExceptionIfDataIsNotAString() { 00128 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00129 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00130 00131 $this->backend->setCache($mockCache); 00132 $data = array('Some data'); 00133 $entryIdentifier = 'BackendFileTest'; 00134 00135 $this->backend->set($entryIdentifier, $data); 00136 } 00137 00138 /** 00139 * @test 00140 * @author Robert Lemke <robert@typo3.org> 00141 * @author Ingo Renner <ingo@typo3.org> 00142 */ 00143 public function setReallySavesToTheSpecifiedDirectory() { 00144 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00145 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00146 00147 $data = 'some data' . microtime(); 00148 $entryIdentifier = 'BackendFileTest'; 00149 $this->backend->setCache($mockCache); 00150 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00151 00152 $this->backend->set($entryIdentifier, $data, array(), 10); 00153 00154 $this->assertFileExists($pathAndFilename); 00155 $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, 0, strlen($data)); 00156 $this->assertEquals($data, $retrievedData); 00157 } 00158 00159 /** 00160 * @test 00161 * @author Robert Lemke <robert@typo3.org> 00162 * @author Ingo Renner <ingo@typo3.org> 00163 */ 00164 public function setOverwritesAnAlreadyExistingCacheEntryForTheSameIdentifier() { 00165 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00166 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00167 00168 $data1 = 'some data' . microtime(); 00169 $data2 = 'some data' . microtime(); 00170 $entryIdentifier = 'BackendFileRemoveBeforeSetTest'; 00171 00172 $this->backend->setCache($mockCache); 00173 $this->backend->set($entryIdentifier, $data1, array(), 500); 00174 // Setting a second entry with the same identifier, but different 00175 // data, this should _replace_ the existing one we set before 00176 $this->backend->set($entryIdentifier, $data2, array(), 200); 00177 00178 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00179 00180 $this->assertFileExists($pathAndFilename); 00181 $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, 0, strlen($data2)); 00182 $this->assertEquals($data2, $retrievedData); 00183 } 00184 00185 /** 00186 * @test 00187 * @author Robert Lemke <robert@typo3.org> 00188 * @author Ingo Renner <ingo@typo3.org> 00189 */ 00190 public function setAlsoSavesSpecifiedTags() { 00191 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00192 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00193 00194 $data = 'some data' . microtime(); 00195 $entryIdentifier = 'BackendFileTest'; 00196 00197 $this->backend->setCache($mockCache); 00198 $this->backend->set($entryIdentifier, $data, array('Tag1', 'Tag2')); 00199 00200 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00201 $this->assertFileExists($pathAndFilename); 00202 $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, (strlen($data) + t3lib_cache_backend_FileBackend::EXPIRYTIME_LENGTH), 9); 00203 $this->assertEquals('Tag1 Tag2', $retrievedData); 00204 } 00205 00206 /** 00207 * @test 00208 * @author Robert Lemke <robert@typo3.org> 00209 * @author Karsten Dambekalns <karsten@typo3.org> 00210 * @author Ingo Renner <ingo@typo3.org> 00211 */ 00212 public function setWithUnlimitedLifetimeWritesCorrectEntry() { 00213 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00214 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00215 00216 $data = 'some data' . microtime(); 00217 $entryIdentifier = 'BackendFileTest'; 00218 00219 $this->backend->setCache($mockCache); 00220 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00221 00222 $this->backend->set($entryIdentifier, $data, array(), 0); 00223 00224 $this->assertFileExists($pathAndFilename); 00225 00226 $dataSize = (integer)file_get_contents($pathAndFilename, NULL, NULL, filesize($pathAndFilename) - t3lib_cache_backend_FileBackend::DATASIZE_DIGITS, t3lib_cache_backend_FileBackend::DATASIZE_DIGITS); 00227 $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, 0, $dataSize); 00228 00229 $this->assertEquals($data, $retrievedData, 'The original and the retrieved data don\'t match.'); 00230 } 00231 00232 /** 00233 * @test 00234 * @author Robert Lemke <robert@typo3.org> 00235 */ 00236 public function getReturnsFalseForExpiredEntries() { 00237 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00238 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00239 00240 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('isCacheFileExpired'), array(), '', FALSE); 00241 $fullPathToCacheFile = PATH_site . 'typo3temp/cache/UnitTestCache/ExpiredEntry'; 00242 $backend->expects($this->once())->method('isCacheFileExpired')->with($fullPathToCacheFile)->will($this->returnValue(TRUE)); 00243 $backend->setCache($mockCache); 00244 00245 $this->assertFalse($backend->get('ExpiredEntry')); 00246 } 00247 00248 /** 00249 * @test 00250 * @author Robert Lemke <robert@typo3.org> 00251 * @author Ingo Renner <ingo@typo3.org> 00252 */ 00253 public function hasReturnsTrueIfAnEntryExists() { 00254 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00255 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00256 00257 $this->backend->setCache($mockCache); 00258 00259 $entryIdentifier = 'BackendFileTest'; 00260 $data = 'some data' . microtime(); 00261 $this->backend->set($entryIdentifier, $data); 00262 00263 $this->assertTrue($this->backend->has($entryIdentifier), 'has() did not return TRUE.'); 00264 $this->assertFalse($this->backend->has($entryIdentifier . 'Not'), 'has() did not return FALSE.'); 00265 } 00266 00267 /** 00268 * @test 00269 * @author Robert Lemke <robert@typo3.org> 00270 */ 00271 public function hasReturnsFalseForExpiredEntries() { 00272 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('isCacheFileExpired'), array(), '', FALSE); 00273 $backend->expects($this->exactly(2))->method('isCacheFileExpired')->will($this->onConsecutiveCalls(TRUE, FALSE)); 00274 00275 $this->assertFalse($backend->has('foo')); 00276 $this->assertTrue($backend->has('bar')); 00277 } 00278 00279 /** 00280 * @test 00281 * @author Robert Lemke <robert@typo3.org> 00282 * @author Ingo Renner <ingo@typo3.org> 00283 */ 00284 public function removeReallyRemovesACacheEntry() { 00285 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00286 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00287 00288 $data = 'some data' . microtime(); 00289 $entryIdentifier = 'BackendFileTest'; 00290 00291 $this->backend->setCache($mockCache); 00292 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00293 $this->backend->set($entryIdentifier, $data); 00294 00295 $this->assertFileExists($pathAndFilename); 00296 $this->backend->remove($entryIdentifier); 00297 $this->assertFileNotExists($pathAndFilename); 00298 } 00299 00300 /** 00301 * @author Christian Kuhn <lolli@schwarzbu.ch> 00302 */ 00303 public function invalidEntryIdentifiers() { 00304 return array( 00305 'trailing slash' => array('/myIdentifer'), 00306 'trailing dot and slash' => array('./myIdentifer'), 00307 'trailing two dots and slash' => array('../myIdentifier'), 00308 'trailing with multiple dots and slashes' => array('.././../myIdentifier'), 00309 'slash in middle part' => array('my/Identifier'), 00310 'dot and slash in middle part' => array('my./Identifier'), 00311 'two dots and slash in middle part' => array('my../Identifier'), 00312 'multiple dots and slashes in middle part' => array('my.././../Identifier'), 00313 'pending slash' => array('myIdentifier/'), 00314 'pending dot and slash' => array('myIdentifier./'), 00315 'pending dots and slash' => array('myIdentifier../'), 00316 'pending multiple dots and slashes' => array('myIdentifier.././../'), 00317 ); 00318 } 00319 00320 /** 00321 * @test 00322 * @dataProvider invalidEntryIdentifiers 00323 * @expectedException InvalidArgumentException 00324 * @author Christian Kuhn <lolli@schwarzbu.ch> 00325 */ 00326 public function setThrowsExceptionForInvalidIdentifier($identifier) { 00327 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00328 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00329 00330 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('dummy'), array(), '', TRUE); 00331 $backend->setCache($mockCache); 00332 00333 $backend->set($identifier, 'cache data', array()); 00334 } 00335 00336 /** 00337 * @test 00338 * @dataProvider invalidEntryIdentifiers 00339 * @expectedException InvalidArgumentException 00340 * @author Christian Kuhn <lolli@schwarzbu.ch> 00341 */ 00342 public function getThrowsExceptionForInvalidIdentifier($identifier) { 00343 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00344 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00345 00346 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('dummy'), array(), '', FALSE); 00347 $backend->setCache($mockCache); 00348 00349 $backend->get($identifier); 00350 } 00351 00352 /** 00353 * @test 00354 * @dataProvider invalidEntryIdentifiers 00355 * @expectedException InvalidArgumentException 00356 * @author Christian Kuhn <lolli@schwarzbu.ch> 00357 */ 00358 public function hasThrowsExceptionForInvalidIdentifier($identifier) { 00359 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('dummy'), array(), '', FALSE); 00360 00361 $backend->has($identifier); 00362 } 00363 00364 /** 00365 * @test 00366 * @dataProvider invalidEntryIdentifiers 00367 * @expectedException InvalidArgumentException 00368 * @author Christian Kuhn <lolli@schwarzbu.ch> 00369 */ 00370 public function removeThrowsExceptionForInvalidIdentifier($identifier) { 00371 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00372 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00373 00374 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('dummy'), array(), '', FALSE); 00375 $backend->setCache($mockCache); 00376 00377 $backend->remove($identifier); 00378 } 00379 00380 /** 00381 * @test 00382 * @dataProvider invalidEntryIdentifiers 00383 * @expectedException InvalidArgumentException 00384 * @author Christian Kuhn <lolli@schwarzbu.ch> 00385 */ 00386 public function requireOnceThrowsExceptionForInvalidIdentifier($identifier) { 00387 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00388 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00389 00390 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array('dummy'), array(), '', FALSE); 00391 $backend->setCache($mockCache); 00392 00393 $backend->requireOnce($identifier); 00394 } 00395 00396 /** 00397 * @test 00398 * @author Robert Lemke <robert@typo3.org> 00399 * @author Karsten Dambekalns <karsten@typo3.org> 00400 * @author Ingo Renner <ingo@typo3.org> 00401 */ 00402 public function collectGarbageReallyRemovesAnExpiredCacheEntry() { 00403 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00404 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00405 00406 $data = 'some data' . microtime(); 00407 $entryIdentifier = 'BackendFileRemovalTest'; 00408 00409 $this->backend->setCache($mockCache); 00410 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00411 $this->backend->set($entryIdentifier, $data, array(), 1); 00412 00413 $this->assertFileExists($pathAndFilename); 00414 00415 $GLOBALS['EXEC_TIME'] += 2; 00416 $this->backend->collectGarbage(); 00417 00418 $this->assertFileNotExists($pathAndFilename); 00419 } 00420 00421 /** 00422 * @test 00423 * @author Robert Lemke <robert@typo3.org> 00424 * @author Karsten Dambekalns <karsten@typo3.org> 00425 * @author Ingo Renner <ingo@typo3.org> 00426 */ 00427 public function collectGarbageReallyRemovesAllExpiredCacheEntries() { 00428 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00429 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00430 00431 $data = 'some data' . microtime(); 00432 $entryIdentifier = 'BackendFileRemovalTest'; 00433 00434 $this->backend->setCache($mockCache); 00435 $pathAndFilename = $this->backend->getCacheDirectory() . $entryIdentifier; 00436 00437 $this->backend->set($entryIdentifier . 'A', $data, array(), NULL); 00438 $this->backend->set($entryIdentifier . 'B', $data, array(), 10); 00439 $this->backend->set($entryIdentifier . 'C', $data, array(), 1); 00440 $this->backend->set($entryIdentifier . 'D', $data, array(), 1); 00441 00442 $this->assertFileExists($pathAndFilename . 'A'); 00443 $this->assertFileExists($pathAndFilename . 'B'); 00444 $this->assertFileExists($pathAndFilename . 'C'); 00445 $this->assertFileExists($pathAndFilename . 'D'); 00446 00447 $GLOBALS['EXEC_TIME'] += 2; 00448 $this->backend->collectGarbage(); 00449 00450 $this->assertFileExists($pathAndFilename . 'A'); 00451 $this->assertFileExists($pathAndFilename . 'B'); 00452 $this->assertFileNotExists($pathAndFilename . 'C'); 00453 $this->assertFileNotExists($pathAndFilename . 'D'); 00454 } 00455 00456 /** 00457 * @test 00458 * @author Robert Lemke <robert@typo3.org> 00459 * @author Ingo Renner <ingo@typo3.org> 00460 */ 00461 public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() { 00462 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00463 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00464 00465 $this->backend->setCache($mockCache); 00466 00467 $data = 'some data' . microtime(); 00468 $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); 00469 $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); 00470 $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); 00471 00472 $expectedEntry = 'BackendFileTest2'; 00473 00474 $actualEntries = $this->backend->findIdentifiersByTag('UnitTestTag%special'); 00475 00476 $this->assertTrue(is_array($actualEntries), 'actualEntries is not an array.'); 00477 $this->assertEquals($expectedEntry, array_pop($actualEntries)); 00478 } 00479 00480 /** 00481 * @test 00482 * @author Ingo Renner <ingo@typo3.org> 00483 */ 00484 public function findIdentifiersByTagDoesNotReturnExpiredEntries() { 00485 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00486 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00487 00488 $this->backend->setCache($mockCache); 00489 00490 $data = 'some data'; 00491 $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); 00492 $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'), -100); 00493 $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); 00494 00495 $this->assertSame(array(), $this->backend->findIdentifiersByTag('UnitTestTag%special')); 00496 $foundIdentifiers = $this->backend->findIdentifiersByTag('UnitTestTag%test'); 00497 sort($foundIdentifiers); 00498 $this->assertSame(array('BackendFileTest1', 'BackendFileTest3'), $foundIdentifiers); 00499 } 00500 00501 /** 00502 * @test 00503 * @author Robert Lemke <robert@typo3.org> 00504 * @author Ingo Renner <ingo@typo3.org> 00505 */ 00506 public function flushRemovesAllCacheEntries() { 00507 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00508 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00509 00510 $this->backend->setCache($mockCache); 00511 00512 $data = 'some data' . microtime(); 00513 $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test')); 00514 $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); 00515 $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); 00516 00517 $this->backend->flush(); 00518 00519 $pattern = $this->backend->getCacheDirectory() . '*'; 00520 $filesFound = is_array(glob($pattern)) ? glob($pattern) : array(); 00521 $this->assertTrue(count($filesFound) === 0, 'Still files in the cache directory'); 00522 } 00523 00524 /** 00525 * @test 00526 * @author Robert Lemke <robert@typo3.org> 00527 * @author Ingo Renner <ingo@typo3.org> 00528 */ 00529 public function flushByTagRemovesCacheEntriesWithSpecifiedTag() { 00530 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE); 00531 $mockCache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('UnitTestCache')); 00532 00533 $this->backend->setCache($mockCache); 00534 00535 $data = 'some data' . microtime(); 00536 $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); 00537 $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); 00538 $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); 00539 00540 $this->backend->flushByTag('UnitTestTag%special'); 00541 00542 $this->assertTrue($this->backend->has('BackendFileTest1'), 'BackendFileTest1'); 00543 $this->assertFalse($this->backend->has('BackendFileTest2'), 'BackendFileTest2'); 00544 $this->assertTrue($this->backend->has('BackendFileTest3'), 'BackendFileTest3'); 00545 } 00546 00547 /** 00548 * @author Robert Lemke <robert@typo3.org> 00549 * @author Ingo Renner <ingo@typo3.org> 00550 */ 00551 public function tearDown() { 00552 if (is_object($this->backend)) { 00553 $directory = $this->backend->getCacheDirectory(); 00554 if (is_dir($directory)) { 00555 t3lib_div::rmdir($directory, TRUE); 00556 } 00557 } 00558 foreach ($this->backupGlobalVariables as $key => $data) { 00559 $GLOBALS[$key] = $data; 00560 } 00561 } 00562 } 00563 00564 ?>
1.8.0