2 namespace TYPO3\CMS\Extbase\Tests\Unit\Configuration
;
4 /***************************************************************
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 class BackendConfigurationManagerTest
extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
{
33 * @var \TYPO3\CMS\Core\Database\DatabaseConnection
35 protected $typo3DbBackup;
38 * @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
40 protected $backendConfigurationManager;
43 * @var \TYPO3\CMS\Extbase\Service\TypoScriptService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
45 protected $mockTypoScriptService;
48 * Sets up this testcase
50 public function setUp() {
51 $this->typo3DbBackup
= $GLOBALS['TYPO3_DB'];
52 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array());
53 $this->backendConfigurationManager
= $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('getTypoScriptSetup'));
54 $this->mockTypoScriptService
= $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
55 $this->backendConfigurationManager
->_set('typoScriptService', $this->mockTypoScriptService
);
59 * Tears down this testcase
61 public function tearDown() {
62 $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup
;
68 public function getCurrentPageIdReturnsPageIdFromGet() {
69 \TYPO3\CMS\Core\Utility\GeneralUtility
::_GETset(array('id' => 123));
70 $expectedResult = 123;
71 $actualResult = $this->backendConfigurationManager
->_call('getCurrentPageId');
72 $this->assertEquals($expectedResult, $actualResult);
78 public function getCurrentPageIdReturnsZeroIfIdIsNotSet() {
80 $actualResult = $this->backendConfigurationManager
->_call('getCurrentPageId');
81 $this->assertEquals($expectedResult, $actualResult);
87 public function getPluginConfigurationReturnsPluginConfiguration() {
88 $testSettings = array(
93 $testSettingsConverted = array(
100 'tx_someextensionname_somepluginname.' => $testSettings
103 $this->mockTypoScriptService
->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
104 $this->backendConfigurationManager
->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
105 $expectedResult = array(
110 $actualResult = $this->backendConfigurationManager
->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
111 $this->assertEquals($expectedResult, $actualResult);
117 public function getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration() {
118 $testExtensionSettings = array(
119 'settings.' => array(
126 $testExtensionSettingsConverted = array(
134 $testPluginSettings = array(
135 'settings.' => array(
137 'nested' => 'valueOverridde',
142 $testPluginSettingsConverted = array(
145 'nested' => 'valueOverridde',
152 'tx_someextensionname.' => $testExtensionSettings,
153 'tx_someextensionname_somepluginname.' => $testPluginSettings
156 $this->mockTypoScriptService
->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
157 $this->mockTypoScriptService
->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
158 $this->backendConfigurationManager
->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
159 $expectedResult = array(
163 'nested' => 'valueOverridde',
168 $actualResult = $this->backendConfigurationManager
->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
169 $this->assertEquals($expectedResult, $actualResult);
175 public function getSwitchableControllerActionsReturnsEmptyArrayByDefault() {
176 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL;
177 $expectedResult = array();
178 $actualResult = $this->backendConfigurationManager
->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
179 $this->assertEquals($expectedResult, $actualResult);
185 public function getSwitchableControllerActionsReturnsConfigurationStoredInExtconf() {
186 $testSwitchableControllerActions = array(
187 'Controller1' => array(
192 'nonCacheableActions' => array(
196 'Controller2' => array(
203 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
204 $expectedResult = $testSwitchableControllerActions;
205 $actualResult = $this->backendConfigurationManager
->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
206 $this->assertEquals($expectedResult, $actualResult);
212 public function getContextSpecificFrameworkConfigurationReturnsUnmodifiedFrameworkConfigurationIfRequestHandlersAreConfigured() {
213 $frameworkConfiguration = array(
214 'pluginName' => 'Pi1',
215 'extensionName' => 'SomeExtension',
222 'requestHandlers' => array(
223 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler' => 'SomeRequestHandler'
227 $expectedResult = $frameworkConfiguration;
228 $actualResult = $this->backendConfigurationManager
->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
229 $this->assertEquals($expectedResult, $actualResult);
235 public function getContextSpecificFrameworkConfigurationSetsDefaultRequestHandlersIfRequestHandlersAreNotConfigured() {
236 $frameworkConfiguration = array(
237 'pluginName' => 'Pi1',
238 'extensionName' => 'SomeExtension',
245 $expectedResult = array(
246 'pluginName' => 'Pi1',
247 'extensionName' => 'SomeExtension',
254 'requestHandlers' => array(
255 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler' => 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler',
256 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\BackendRequestHandler' => 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\BackendRequestHandler'
260 $actualResult = $this->backendConfigurationManager
->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
261 $this->assertEquals($expectedResult, $actualResult);
267 public function storagePidsAreExtendedIfRecursiveSearchIsConfigured() {
268 $storagePid = '1,2,3';
270 /** @var $abstractConfigurationManager \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager */
271 $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
272 $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
273 $queryGenerator->expects($this->any())
274 ->method('getTreeList')
275 ->will($this->onConsecutiveCalls('4', '', '5,6'));
276 $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
278 $expectedResult = '4,5,6';
279 $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
280 $this->assertEquals($expectedResult, $actualResult);
286 public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid() {
287 $storagePid = '1,2,-3';
289 /** @var $abstractConfigurationManager \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager */
290 $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
291 $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
292 $queryGenerator->expects($this->any())
293 ->method('getTreeList')
294 ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
295 $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
297 $expectedResult = '4,3,5,6';
298 $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
299 $this->assertEquals($expectedResult, $actualResult);
305 public function storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured() {
306 $storagePid = '1,2,3';
308 $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
310 $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
311 $queryGenerator->expects($this->never())->method('getTreeList');
312 $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
314 $expectedResult = '1,2,3';
315 $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
316 $this->assertEquals($expectedResult, $actualResult);
322 public function storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels() {
323 $storagePid = '1,2,3';
326 $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
328 $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
329 $queryGenerator->expects($this->never())->method('getTreeList');
330 $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
332 $expectedResult = '1,2,3';
333 $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
334 $this->assertEquals($expectedResult, $actualResult);