[TASK] Namespace classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Configuration / FrontendConfigurationManagerTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Configuration;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * All rights reserved
9 *
10 * This class is a backport of the corresponding class of FLOW3.
11 * All credits go to the v5 team.
12 *
13 * This script is part of the TYPO3 project. The TYPO3 project is
14 * free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * The GNU General Public License can be found at
20 * http://www.gnu.org/copyleft/gpl.html.
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
30
31 /**
32 * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
33 */
34 protected $tsfeBackup;
35
36 /**
37 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
38 */
39 protected $mockContentObject;
40
41 /**
42 * @var \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager
43 */
44 protected $frontendConfigurationManager;
45
46 /**
47 * @var array
48 */
49 protected $extConfBackup;
50
51 /**
52 * @var \TYPO3\CMS\Extbase\Service\TypoScriptService
53 */
54 protected $mockTypoScriptService;
55
56 /**
57 * Sets up this testcase
58 */
59 public function setUp() {
60 $this->tsfeBackup = $GLOBALS['TSFE'];
61 $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
62 $this->extConfBackup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'];
63 $this->frontendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('dummy'));
64 $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
65 $this->mockTypoScriptService = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
66 $this->frontendConfigurationManager->injectTypoScriptService($this->mockTypoScriptService);
67 }
68
69 /**
70 * Tears down this testcase
71 */
72 public function tearDown() {
73 $GLOBALS['TSFE']->tmpl->setup;
74 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = $this->extConfBackup;
75 }
76
77 /**
78 * @test
79 */
80 public function getTypoScriptSetupReturnsSetupFromTsfe() {
81 $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
82 $this->assertEquals(array('foo' => 'bar'), $this->frontendConfigurationManager->_call('getTypoScriptSetup'));
83 }
84
85 /**
86 * @test
87 */
88 public function getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound() {
89 $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
90 $expectedResult = array();
91 $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
92 $this->assertEquals($expectedResult, $actualResult);
93 }
94
95 /**
96 * @test
97 */
98 public function getPluginConfigurationReturnsExtensionConfiguration() {
99 $testSettings = array(
100 'settings.' => array(
101 'foo' => 'bar'
102 )
103 );
104 $testSettingsConverted = array(
105 'settings' => array(
106 'foo' => 'bar'
107 )
108 );
109 $testSetup = array(
110 'plugin.' => array(
111 'tx_someextensionname.' => $testSettings
112 )
113 );
114 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
115 $GLOBALS['TSFE']->tmpl->setup = $testSetup;
116 $expectedResult = array(
117 'settings' => array(
118 'foo' => 'bar'
119 )
120 );
121 $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
122 $this->assertEquals($expectedResult, $actualResult);
123 }
124
125 /**
126 * @test
127 */
128 public function getPluginConfigurationReturnsPluginConfiguration() {
129 $testSettings = array(
130 'settings.' => array(
131 'foo' => 'bar'
132 )
133 );
134 $testSettingsConverted = array(
135 'settings' => array(
136 'foo' => 'bar'
137 )
138 );
139 $testSetup = array(
140 'plugin.' => array(
141 'tx_someextensionname_somepluginname.' => $testSettings
142 )
143 );
144 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
145 $GLOBALS['TSFE']->tmpl->setup = $testSetup;
146 $expectedResult = array(
147 'settings' => array(
148 'foo' => 'bar'
149 )
150 );
151 $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
152 $this->assertEquals($expectedResult, $actualResult);
153 }
154
155 /**
156 * @test
157 */
158 public function getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration() {
159 $testExtensionSettings = array(
160 'settings.' => array(
161 'foo' => 'bar',
162 'some.' => array(
163 'nested' => 'value'
164 )
165 )
166 );
167 $testExtensionSettingsConverted = array(
168 'settings' => array(
169 'foo' => 'bar',
170 'some' => array(
171 'nested' => 'value'
172 )
173 )
174 );
175 $testPluginSettings = array(
176 'settings.' => array(
177 'some.' => array(
178 'nested' => 'valueOverridde',
179 'new' => 'value'
180 )
181 )
182 );
183 $testPluginSettingsConverted = array(
184 'settings' => array(
185 'some' => array(
186 'nested' => 'valueOverridde',
187 'new' => 'value'
188 )
189 )
190 );
191 $testSetup = array(
192 'plugin.' => array(
193 'tx_someextensionname.' => $testExtensionSettings,
194 'tx_someextensionname_somepluginname.' => $testPluginSettings
195 )
196 );
197 $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
198 $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
199 $GLOBALS['TSFE']->tmpl->setup = $testSetup;
200 $expectedResult = array(
201 'settings' => array(
202 'foo' => 'bar',
203 'some' => array(
204 'nested' => 'valueOverridde',
205 'new' => 'value'
206 )
207 )
208 );
209 $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
210 $this->assertEquals($expectedResult, $actualResult);
211 }
212
213 /**
214 * @test
215 */
216 public function getSwitchableControllerActionsReturnsEmptyArrayByDefault() {
217 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL;
218 $expectedResult = array();
219 $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
220 $this->assertEquals($expectedResult, $actualResult);
221 }
222
223 /**
224 * @test
225 */
226 public function getSwitchableControllerActionsReturnsConfigurationStoredInExtconf() {
227 $testSwitchableControllerActions = array(
228 'Controller1' => array(
229 'actions' => array(
230 'action1',
231 'action2'
232 ),
233 'nonCacheableActions' => array(
234 'action1'
235 )
236 ),
237 'Controller2' => array(
238 'actions' => array(
239 'action3',
240 'action4'
241 )
242 )
243 );
244 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['plugins']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
245 $expectedResult = $testSwitchableControllerActions;
246 $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
247 $this->assertEquals($expectedResult, $actualResult);
248 }
249
250 /**
251 * @test
252 */
253 public function overrideSwitchableControllerActionsFromFlexFormReturnsUnchangedFrameworkConfigurationIfNoFlexFormConfigurationIsFound() {
254 $frameworkConfiguration = array(
255 'pluginName' => 'Pi1',
256 'extensionName' => 'SomeExtension',
257 'controllerConfiguration' => array(
258 'Controller1' => array(
259 'controller' => 'Controller1',
260 'actions' => 'action1 , action2'
261 ),
262 'Controller2' => array(
263 'controller' => 'Controller2',
264 'actions' => 'action2 , action1,action3',
265 'nonCacheableActions' => 'action2, action3'
266 )
267 )
268 );
269 $flexFormConfiguration = array();
270 $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
271 $this->assertSame($frameworkConfiguration, $actualResult);
272 }
273
274 /**
275 * @test
276 */
277 public function overrideSwitchableControllerActionsFromFlexFormMergesNonCacheableActions() {
278 $frameworkConfiguration = array(
279 'pluginName' => 'Pi1',
280 'extensionName' => 'SomeExtension',
281 'controllerConfiguration' => array(
282 'Controller1' => array(
283 'actions' => array('action1 , action2')
284 ),
285 'Controller2' => array(
286 'actions' => array('action2', 'action1', 'action3'),
287 'nonCacheableActions' => array('action2', 'action3')
288 )
289 )
290 );
291 $flexFormConfiguration = array(
292 'switchableControllerActions' => 'Controller1 -> action2;Controller2->action3; Controller2->action1'
293 );
294 $expectedResult = array(
295 'pluginName' => 'Pi1',
296 'extensionName' => 'SomeExtension',
297 'controllerConfiguration' => array(
298 'Controller1' => array(
299 'actions' => array('action2')
300 ),
301 'Controller2' => array(
302 'actions' => array('action3', 'action1'),
303 'nonCacheableActions' => array(1 => 'action3')
304 )
305 )
306 );
307 $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
308 $this->assertEquals($expectedResult, $actualResult);
309 }
310
311 /**
312 * @test
313 * @expectedException \TYPO3\CMS\Extbase\Configuration\Exception\ParseError
314 */
315 public function overrideSwitchableControllerActionsThrowsExceptionIfFlexFormConfigurationIsInvalid() {
316 $frameworkConfiguration = array(
317 'pluginName' => 'Pi1',
318 'extensionName' => 'SomeExtension',
319 'controllerConfiguration' => array(
320 'Controller1' => array(
321 'actions' => array('action1 , action2')
322 ),
323 'Controller2' => array(
324 'actions' => array('action2', 'action1', 'action3'),
325 'nonCacheableActions' => array('action2', 'action3')
326 )
327 )
328 );
329 $flexFormConfiguration = array(
330 'switchableControllerActions' => 'Controller1->;Controller2->action3;Controller2->action1'
331 );
332 $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
333 }
334
335 /**
336 * @test
337 */
338 public function getContextSpecificFrameworkConfigurationCorrectlyCallsOverrideMethods() {
339 $frameworkConfiguration = array(
340 'some' => array(
341 'framework' => 'configuration'
342 )
343 );
344 $frontendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideStoragePidIfStartingPointIsSet', 'overrideConfigurationFromPlugin', 'overrideConfigurationFromFlexForm'));
345 $frontendConfigurationManager->expects($this->at(0))->method('overrideStoragePidIfStartingPointIsSet')->with($frameworkConfiguration)->will($this->returnValue(array('overridden' => 'storagePid')));
346 $frontendConfigurationManager->expects($this->at(1))->method('overrideConfigurationFromPlugin')->with(array('overridden' => 'storagePid'))->will($this->returnValue(array('overridden' => 'pluginConfiguration')));
347 $frontendConfigurationManager->expects($this->at(2))->method('overrideConfigurationFromFlexForm')->with(array('overridden' => 'pluginConfiguration'))->will($this->returnValue(array('overridden' => 'flexFormConfiguration')));
348 $expectedResult = array('overridden' => 'flexFormConfiguration');
349 $actualResult = $frontendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
350 $this->assertEquals($expectedResult, $actualResult);
351 }
352
353 }
354
355
356 ?>