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