[+BUGFIX] Extbase (Configuration): slightly tweaked FrontendConfigurationManager...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Configuration / BackendConfigurationManagerTest.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_Tests_Unit_Configuration_BackendConfigurationManagerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
29
30 /**
31 * @var array
32 */
33 protected $getBackup;
34
35 /**
36 * @var array
37 */
38 protected $postBackup;
39
40 /**
41 * @var t3lib_DB
42 */
43 protected $typo3DbBackup;
44
45 /**
46 * @var array
47 */
48 protected $extConfBackup;
49
50 /**
51 * @var Tx_Extbase_Configuration_BackendConfigurationManager
52 */
53 protected $backendConfigurationManager;
54
55 /**
56 * Sets up this testcase
57 */
58 public function setUp() {
59 $this->getBackup = t3lib_div::_GET();
60 $this->postBackup = t3lib_div::_POST();
61
62 $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
63 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array());
64
65 $this->extConfBackup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'];
66
67 $this->backendConfigurationManager = $this->getAccessibleMock('Tx_Extbase_Configuration_BackendConfigurationManager', array('getTypoScriptSetup'));
68 }
69
70 /**
71 * Tears down this testcase
72 */
73 public function tearDown() {
74 t3lib_div::_GETset($this->getBackup);
75 $_POST = $this->postBackup;
76 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = $this->extConfBackup;
77 }
78
79 /**
80 * @test
81 */
82 public function getTypoScriptSetupCanBeTested() {
83 $this->markTestIncomplete('This method can\'t be tested with the current TYPO3 version, because we can\'t mock objects returned from t3lib_div::makeInstance().');
84 }
85
86 /**
87 * @test
88 */
89 public function getCurrentPageIdReturnsPageIdFromGet() {
90 t3lib_div::_GETset(array('id' => 123));
91
92 $expectedResult = 123;
93 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
94
95 $this->assertEquals($expectedResult, $actualResult);
96 }
97
98 /**
99 * @test
100 */
101 public function getCurrentPageIdReturnsPageIdFromPost() {
102 t3lib_div::_GETset(array('id' => 123));
103 $_POST['id'] = 321;
104
105 $expectedResult = 321;
106 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
107
108 $this->assertEquals($expectedResult, $actualResult);
109 }
110
111 /**
112 * @test
113 */
114 public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSet() {
115 $GLOBALS['TYPO3_DB']->expects($this->once())
116 ->method('exec_SELECTgetRows')
117 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
118 ->will(
119 $this->returnValue(
120 array(
121 array('pid' => 123)
122 )
123 )
124 );
125
126 $expectedResult = 123;
127 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
128
129 $this->assertEquals($expectedResult, $actualResult);
130 }
131
132 /**
133 * @test
134 */
135 public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSetAndNoRootTemplateWasFound() {
136 $GLOBALS['TYPO3_DB']->expects($this->at(0))
137 ->method('exec_SELECTgetRows')
138 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
139 ->will($this->returnValue(array()));
140
141 $GLOBALS['TYPO3_DB']->expects($this->at(1))
142 ->method('exec_SELECTgetRows')
143 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')
144 ->will(
145 $this->returnValue(
146 array(
147 array('uid' => 321)
148 )
149 )
150 );
151
152 $expectedResult = 321;
153 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
154
155 $this->assertEquals($expectedResult, $actualResult);
156 }
157
158 /**
159 * @test
160 */
161 public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound() {
162 $GLOBALS['TYPO3_DB']->expects($this->at(0))
163 ->method('exec_SELECTgetRows')
164 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
165 ->will($this->returnValue(array()));
166
167 $GLOBALS['TYPO3_DB']->expects($this->at(1))
168 ->method('exec_SELECTgetRows')
169 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')
170 ->will($this->returnValue(array()));
171
172 $expectedResult = Tx_Extbase_Configuration_AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID;
173 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
174
175 $this->assertEquals($expectedResult, $actualResult);
176 }
177
178 /**
179 * @test
180 */
181 public function getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound() {
182 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(array('foo' => 'bar')));
183 $expectedResult = array();
184 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
185 $this->assertEquals($expectedResult, $actualResult);
186 }
187
188 /**
189 * @test
190 */
191 public function getPluginConfigurationReturnsExtensionConfiguration() {
192 $testSetup = array(
193 'module.' => array(
194 'tx_someextensionname.' => array(
195 'settings.' => array(
196 'foo' => 'bar'
197 )
198 ),
199 ),
200 );
201 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
202 $expectedResult = array(
203 'settings' => array(
204 'foo' => 'bar'
205 )
206 );
207 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
208 $this->assertEquals($expectedResult, $actualResult);
209 }
210
211 /**
212 * @test
213 */
214 public function getPluginConfigurationReturnsPluginConfiguration() {
215 $testSetup = array(
216 'module.' => array(
217 'tx_someextensionname_somepluginname.' => array(
218 'settings.' => array(
219 'foo' => 'bar'
220 )
221 ),
222 ),
223 );
224 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
225 $expectedResult = array(
226 'settings' => array(
227 'foo' => 'bar'
228 )
229 );
230 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
231 $this->assertEquals($expectedResult, $actualResult);
232 }
233
234 /**
235 * @test
236 */
237 public function getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration() {
238 $testSetup = array(
239 'module.' => array(
240 'tx_someextensionname.' => array(
241 'settings.' => array(
242 'foo' => 'bar',
243 'some.' => array(
244 'nested' => 'value'
245 ),
246 ),
247 ),
248 'tx_someextensionname_somepluginname.' => array(
249 'settings.' => array(
250 'some.' => array(
251 'nested' => 'valueOverridde',
252 'new' => 'value',
253 ),
254 ),
255 ),
256 ),
257 );
258 $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
259 $expectedResult = array(
260 'settings' => array(
261 'foo' => 'bar',
262 'some' => array(
263 'nested' => 'valueOverridde',
264 'new' => 'value'
265 ),
266 ),
267 );
268 $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
269 $this->assertEquals($expectedResult, $actualResult);
270 }
271
272 /**
273 * @test
274 */
275 public function getSwitchableControllerActionsReturnsEmptyArrayByDefault() {
276 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL;
277 $expectedResult = array();
278 $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
279 $this->assertEquals($expectedResult, $actualResult);
280 }
281
282 /**
283 * @test
284 */
285 public function getSwitchableControllerActionsReturnsConfigurationStoredInExtconf() {
286 $testSwitchableControllerActions = array(
287 'Controller1' => array(
288 'actions' => array(
289 'action1', 'action2'
290 ),
291 'nonCacheableActions' => array(
292 'action1'
293 ),
294 ),
295 'Controller2' => array(
296 'actions' => array(
297 'action3', 'action4'
298 ),
299 )
300 );
301 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
302 $expectedResult = $testSwitchableControllerActions;
303 $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
304 $this->assertEquals($expectedResult, $actualResult);
305 }
306
307 /**
308 * @test
309 */
310 public function getContextSpecificFrameworkConfigurationReturnsUnmodifiedFrameworkConfiguration() {
311 $frameworkConfiguration = array(
312 'pluginName' => 'Pi1',
313 'extensionName' => 'SomeExtension',
314 'foo' => array(
315 'bar' => array(
316 'baz' => 'Foo',
317 ),
318 )
319 );
320 $expectedResult = $frameworkConfiguration;
321 $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
322 $this->assertEquals($expectedResult, $actualResult);
323 }
324 }
325 ?>