|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de> 00006 * All rights reserved 00007 * 00008 * This class is a backport of the corresponding class of FLOW3. 00009 * All credits go to the v5 team. 00010 * 00011 * This script is part of the TYPO3 project. The TYPO3 project is 00012 * free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * The GNU General Public License can be found at 00018 * http://www.gnu.org/copyleft/gpl.html. 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 class Tx_Extbase_Tests_Unit_Configuration_BackendConfigurationManagerTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00029 00030 /** 00031 * @var array 00032 */ 00033 protected $getBackup; 00034 00035 /** 00036 * @var array 00037 */ 00038 protected $postBackup; 00039 00040 /** 00041 * @var t3lib_DB 00042 */ 00043 protected $typo3DbBackup; 00044 00045 /** 00046 * @var array 00047 */ 00048 protected $extConfBackup; 00049 00050 /** 00051 * @var Tx_Extbase_Configuration_BackendConfigurationManager 00052 */ 00053 protected $backendConfigurationManager; 00054 00055 /** 00056 * Sets up this testcase 00057 */ 00058 public function setUp() { 00059 $this->getBackup = t3lib_div::_GET(); 00060 $this->postBackup = t3lib_div::_POST(); 00061 00062 $this->typo3DbBackup = $GLOBALS['TYPO3_DB']; 00063 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array()); 00064 00065 $this->extConfBackup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']; 00066 00067 $this->backendConfigurationManager = $this->getAccessibleMock('Tx_Extbase_Configuration_BackendConfigurationManager', array('getTypoScriptSetup')); 00068 } 00069 00070 /** 00071 * Tears down this testcase 00072 */ 00073 public function tearDown() { 00074 t3lib_div::_GETset($this->getBackup); 00075 $_POST = $this->postBackup; 00076 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = $this->extConfBackup; 00077 } 00078 00079 /** 00080 * @test 00081 */ 00082 public function getTypoScriptSetupCanBeTested() { 00083 $this->markTestIncomplete('This method can\'t be tested with the current TYPO3 version, because we can\'t mock objects returned from t3lib_div::makeInstance().'); 00084 } 00085 00086 /** 00087 * @test 00088 */ 00089 public function getCurrentPageIdReturnsPageIdFromGet() { 00090 t3lib_div::_GETset(array('id' => 123)); 00091 00092 $expectedResult = 123; 00093 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId'); 00094 00095 $this->assertEquals($expectedResult, $actualResult); 00096 } 00097 00098 /** 00099 * @test 00100 */ 00101 public function getCurrentPageIdReturnsPageIdFromPost() { 00102 t3lib_div::_GETset(array('id' => 123)); 00103 $_POST['id'] = 321; 00104 00105 $expectedResult = 321; 00106 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId'); 00107 00108 $this->assertEquals($expectedResult, $actualResult); 00109 } 00110 00111 /** 00112 * @test 00113 */ 00114 public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound() { 00115 $GLOBALS['TYPO3_DB']->expects($this->at(0)) 00116 ->method('exec_SELECTgetRows') 00117 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1') 00118 ->will($this->returnValue(array())); 00119 00120 $GLOBALS['TYPO3_DB']->expects($this->at(1)) 00121 ->method('exec_SELECTgetRows') 00122 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1') 00123 ->will( 00124 $this->returnValue( 00125 array( 00126 array('pid' => 123) 00127 ) 00128 ) 00129 ); 00130 00131 $expectedResult = 123; 00132 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId'); 00133 00134 $this->assertEquals($expectedResult, $actualResult); 00135 } 00136 00137 /** 00138 * @test 00139 */ 00140 public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet() { 00141 $GLOBALS['TYPO3_DB']->expects($this->once()) 00142 ->method('exec_SELECTgetRows') 00143 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1') 00144 ->will( 00145 $this->returnValue( 00146 array( 00147 array('uid' => 321) 00148 ) 00149 ) 00150 ); 00151 00152 $expectedResult = 321; 00153 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId'); 00154 00155 $this->assertEquals($expectedResult, $actualResult); 00156 } 00157 00158 /** 00159 * @test 00160 */ 00161 public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound() { 00162 $GLOBALS['TYPO3_DB']->expects($this->at(0)) 00163 ->method('exec_SELECTgetRows') 00164 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1') 00165 ->will($this->returnValue(array())); 00166 00167 $GLOBALS['TYPO3_DB']->expects($this->at(1)) 00168 ->method('exec_SELECTgetRows') 00169 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1') 00170 ->will($this->returnValue(array())); 00171 00172 $expectedResult = Tx_Extbase_Configuration_AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID; 00173 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId'); 00174 00175 $this->assertEquals($expectedResult, $actualResult); 00176 } 00177 00178 /** 00179 * @test 00180 */ 00181 public function getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound() { 00182 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(array('foo' => 'bar'))); 00183 $expectedResult = array(); 00184 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName'); 00185 $this->assertEquals($expectedResult, $actualResult); 00186 } 00187 00188 /** 00189 * @test 00190 */ 00191 public function getPluginConfigurationReturnsExtensionConfiguration() { 00192 $testSetup = array( 00193 'module.' => array( 00194 'tx_someextensionname.' => array( 00195 'settings.' => array( 00196 'foo' => 'bar' 00197 ) 00198 ), 00199 ), 00200 ); 00201 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup)); 00202 $expectedResult = array( 00203 'settings' => array( 00204 'foo' => 'bar' 00205 ) 00206 ); 00207 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName'); 00208 $this->assertEquals($expectedResult, $actualResult); 00209 } 00210 00211 /** 00212 * @test 00213 */ 00214 public function getPluginConfigurationReturnsPluginConfiguration() { 00215 $testSetup = array( 00216 'module.' => array( 00217 'tx_someextensionname_somepluginname.' => array( 00218 'settings.' => array( 00219 'foo' => 'bar' 00220 ) 00221 ), 00222 ), 00223 ); 00224 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup)); 00225 $expectedResult = array( 00226 'settings' => array( 00227 'foo' => 'bar' 00228 ) 00229 ); 00230 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName'); 00231 $this->assertEquals($expectedResult, $actualResult); 00232 } 00233 00234 /** 00235 * @test 00236 */ 00237 public function getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration() { 00238 $testSetup = array( 00239 'module.' => array( 00240 'tx_someextensionname.' => array( 00241 'settings.' => array( 00242 'foo' => 'bar', 00243 'some.' => array( 00244 'nested' => 'value' 00245 ), 00246 ), 00247 ), 00248 'tx_someextensionname_somepluginname.' => array( 00249 'settings.' => array( 00250 'some.' => array( 00251 'nested' => 'valueOverridde', 00252 'new' => 'value', 00253 ), 00254 ), 00255 ), 00256 ), 00257 ); 00258 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup)); 00259 $expectedResult = array( 00260 'settings' => array( 00261 'foo' => 'bar', 00262 'some' => array( 00263 'nested' => 'valueOverridde', 00264 'new' => 'value' 00265 ), 00266 ), 00267 ); 00268 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName'); 00269 $this->assertEquals($expectedResult, $actualResult); 00270 } 00271 00272 /** 00273 * @test 00274 */ 00275 public function getSwitchableControllerActionsReturnsEmptyArrayByDefault() { 00276 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL; 00277 $expectedResult = array(); 00278 $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName'); 00279 $this->assertEquals($expectedResult, $actualResult); 00280 } 00281 00282 /** 00283 * @test 00284 */ 00285 public function getSwitchableControllerActionsReturnsConfigurationStoredInExtconf() { 00286 $testSwitchableControllerActions = array( 00287 'Controller1' => array( 00288 'actions' => array( 00289 'action1', 'action2' 00290 ), 00291 'nonCacheableActions' => array( 00292 'action1' 00293 ), 00294 ), 00295 'Controller2' => array( 00296 'actions' => array( 00297 'action3', 'action4' 00298 ), 00299 ) 00300 ); 00301 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions; 00302 $expectedResult = $testSwitchableControllerActions; 00303 $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName'); 00304 $this->assertEquals($expectedResult, $actualResult); 00305 } 00306 00307 /** 00308 * @test 00309 */ 00310 public function getContextSpecificFrameworkConfigurationReturnsUnmodifiedFrameworkConfigurationIfRequestHandlersAreConfigured() { 00311 $frameworkConfiguration = array( 00312 'pluginName' => 'Pi1', 00313 'extensionName' => 'SomeExtension', 00314 'foo' => array( 00315 'bar' => array( 00316 'baz' => 'Foo', 00317 ), 00318 ), 00319 'mvc' => array( 00320 'requestHandlers' => array( 00321 'Tx_Extbase_MVC_Web_FrontendRequestHandler' => 'SomeRequestHandler' 00322 ) 00323 ) 00324 ); 00325 $expectedResult = $frameworkConfiguration; 00326 $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration); 00327 $this->assertEquals($expectedResult, $actualResult); 00328 } 00329 00330 /** 00331 * @test 00332 */ 00333 public function getContextSpecificFrameworkConfigurationSetsDefaultRequestHandlersIfRequestHandlersAreNotConfigured() { 00334 $frameworkConfiguration = array( 00335 'pluginName' => 'Pi1', 00336 'extensionName' => 'SomeExtension', 00337 'foo' => array( 00338 'bar' => array( 00339 'baz' => 'Foo', 00340 ), 00341 ), 00342 ); 00343 $expectedResult = array( 00344 'pluginName' => 'Pi1', 00345 'extensionName' => 'SomeExtension', 00346 'foo' => array( 00347 'bar' => array( 00348 'baz' => 'Foo', 00349 ), 00350 ), 00351 'mvc' => array( 00352 'requestHandlers' => array( 00353 'Tx_Extbase_MVC_Web_FrontendRequestHandler' => 'Tx_Extbase_MVC_Web_FrontendRequestHandler', 00354 'Tx_Extbase_MVC_Web_BackendRequestHandler' => 'Tx_Extbase_MVC_Web_BackendRequestHandler' 00355 ) 00356 ) 00357 ); 00358 $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration); 00359 $this->assertEquals($expectedResult, $actualResult); 00360 } 00361 } 00362 ?>
1.8.0