|
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 /** 00027 * Testcase for the Cache Manager 00028 * 00029 * This file is a backport from FLOW3 00030 * 00031 * @author Ingo Renner <ingo@typo3.org> 00032 * @package TYPO3 00033 * @subpackage tests 00034 * @version $Id: t3lib_cache_managerTest.php 10121 2011-01-18 20:15:30Z ohader $ 00035 */ 00036 class t3lib_cache_ManagerTest extends tx_phpunit_testcase { 00037 00038 /** 00039 * @test 00040 * @author Robert Lemke <robert@typo3.org> 00041 * @author Ingo Renner <ingo@typo3.org> 00042 */ 00043 public function initializeCreatesAndRegistersAllCachesDefinedInTheCachesConfiguration() { 00044 $mockCacheFactory = $this->getMock('t3lib_cache_Factory', array(), array(), '', FALSE); 00045 $mockCacheFactory->expects($this->at(1))->method('create')->with('cache1', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_FileBackend', array()); 00046 $mockCacheFactory->expects($this->at(2))->method('create')->with('cache2', 't3lib_cache_frontend_StringFrontend', 't3lib_cache_backend_NullBackend', array('foo' => 'bar')); 00047 00048 $cacheConfigurations = array( 00049 'cache1' => array( 00050 'frontend' => 't3lib_cache_frontend_VariableFrontend', 00051 'backend' => 't3lib_cache_backend_FileBackend', 00052 'backendOptions' => array(), 00053 ), 00054 'cache2' => array( 00055 'frontend' => 't3lib_cache_frontend_StringFrontend', 00056 'backend' => 't3lib_cache_backend_NullBackend', 00057 'backendOptions' => array('foo' => 'bar') 00058 ), 00059 ); 00060 00061 $manager = new t3lib_cache_Manager(); 00062 $manager->setCacheConfigurations($cacheConfigurations); 00063 $manager->setCacheFactory($mockCacheFactory); 00064 $manager->initialize(); 00065 } 00066 00067 /** 00068 * @test 00069 * @author Robert Lemke <robert@typo3.org> 00070 * @author Ingo Renner <ingo@typo3.org> 00071 * @expectedException t3lib_cache_exception_DuplicateIdentifier 00072 */ 00073 public function managerThrowsExceptionOnCacheRegistrationWithAlreadyExistingIdentifier() { 00074 $manager = new t3lib_cache_Manager(); 00075 $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); 00076 00077 $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00078 $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test')); 00079 00080 $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00081 $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test')); 00082 00083 $manager->registerCache($cache1); 00084 $manager->registerCache($cache2); 00085 } 00086 00087 /** 00088 * @test 00089 * @author Robert Lemke <robert@typo3.org> 00090 * @author Ingo Renner <ingo@typo3.org> 00091 */ 00092 public function managerReturnsThePreviouslyRegisteredCache() { 00093 $manager = new t3lib_cache_Manager(); 00094 $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); 00095 00096 $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00097 $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); 00098 00099 $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00100 $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache2')); 00101 00102 $manager->registerCache($cache1); 00103 $manager->registerCache($cache2); 00104 00105 $this->assertSame($cache2, $manager->getCache('cache2'), 'The cache returned by getCache() was not the same I registered.'); 00106 } 00107 00108 /** 00109 * @test 00110 * @author Robert Lemke <robert@typo3.org> 00111 * @author Ingo Renner <ingo@typo3.org> 00112 * @expectedException t3lib_cache_exception_NoSuchCache 00113 */ 00114 public function getCacheThrowsExceptionForNonExistingIdentifier() { 00115 $manager = new t3lib_cache_Manager(); 00116 $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); 00117 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00118 $cache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('someidentifier')); 00119 00120 $manager->registerCache($cache); 00121 $manager->getCache('someidentifier'); 00122 00123 $manager->getCache('doesnotexist'); 00124 } 00125 00126 /** 00127 * @test 00128 * @author Robert Lemke <robert@typo3.org> 00129 * @author Ingo Renner <ingo@typo3.org> 00130 */ 00131 public function hasCacheReturnsCorrectResult() { 00132 $manager = new t3lib_cache_Manager(); 00133 $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); 00134 $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00135 $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); 00136 $manager->registerCache($cache1); 00137 00138 $this->assertTrue($manager->hasCache('cache1'), 'hasCache() did not return TRUE.'); 00139 $this->assertFalse($manager->hasCache('cache2'), 'hasCache() did not return FALSE.'); 00140 } 00141 00142 /** 00143 * @test 00144 * @author Robert Lemke <robert@typo3.org> 00145 * @author Ingo Renner <ingo@typo3.org> 00146 */ 00147 public function flushCachesByTagCallsTheFlushByTagMethodOfAllRegisteredCaches() { 00148 $manager = new t3lib_cache_Manager(); 00149 00150 $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); 00151 00152 $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00153 $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); 00154 $cache1->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag')); 00155 $manager->registerCache($cache1); 00156 00157 $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00158 $cache2->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag')); 00159 $manager->registerCache($cache2); 00160 00161 $manager->flushCachesByTag('theTag'); 00162 } 00163 00164 /** 00165 * @test 00166 * @author Robert Lemke <robert@typo3.org> 00167 * @author Ingo Renner <ingo@typo3.org> 00168 */ 00169 public function flushCachesCallsTheFlushMethodOfAllRegisteredCaches() { 00170 $manager = new t3lib_cache_Manager(); 00171 $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); 00172 00173 $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00174 $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); 00175 $cache1->expects($this->once())->method('flush'); 00176 $manager->registerCache($cache1); 00177 00178 $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); 00179 $cache2->expects($this->once())->method('flush'); 00180 $manager->registerCache($cache2); 00181 00182 $manager->flushCaches(); 00183 } 00184 00185 } 00186 00187 ?>
1.8.0