TYPO3 CMS  TYPO3_6-2
BackendConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
3 
21 
26 
31 
35  public function setUp() {
36  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array());
37  $this->backendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('getTypoScriptSetup'));
38  $this->mockTypoScriptService = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
39  $this->backendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
40  }
41 
47  $expectedResult = 123;
48  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
49  $this->assertEquals($expectedResult, $actualResult);
50  }
51 
57  $_POST['id'] = 321;
58  $expectedResult = 321;
59  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
60  $this->assertEquals($expectedResult, $actualResult);
61  }
62 
67  $GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(array()));
68  $GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(
69  array('pid' => 123)
70  ));
71  $expectedResult = 123;
72  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
73  $this->assertEquals($expectedResult, $actualResult);
74  }
75 
80  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(
81  array('uid' => 321)
82  ));
83  $expectedResult = 321;
84  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
85  $this->assertEquals($expectedResult, $actualResult);
86  }
87 
92  $GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(array()));
93  $GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(array()));
95  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
96  $this->assertEquals($expectedResult, $actualResult);
97  }
98 
103  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(array('foo' => 'bar')));
104  $expectedResult = array();
105  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
106  $this->assertEquals($expectedResult, $actualResult);
107  }
108 
113  $testSettings = array(
114  'settings.' => array(
115  'foo' => 'bar'
116  )
117  );
118  $testSettingsConverted = array(
119  'settings' => array(
120  'foo' => 'bar'
121  )
122  );
123  $testSetup = array(
124  'module.' => array(
125  'tx_someextensionname.' => $testSettings
126  )
127  );
128  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
129  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
130  $expectedResult = array(
131  'settings' => array(
132  'foo' => 'bar'
133  )
134  );
135  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
136  $this->assertEquals($expectedResult, $actualResult);
137  }
138 
143  $testSettings = array(
144  'settings.' => array(
145  'foo' => 'bar'
146  )
147  );
148  $testSettingsConverted = array(
149  'settings' => array(
150  'foo' => 'bar'
151  )
152  );
153  $testSetup = array(
154  'module.' => array(
155  'tx_someextensionname_somepluginname.' => $testSettings
156  )
157  );
158  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
159  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
160  $expectedResult = array(
161  'settings' => array(
162  'foo' => 'bar'
163  )
164  );
165  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
166  $this->assertEquals($expectedResult, $actualResult);
167  }
168 
173  $testExtensionSettings = array(
174  'settings.' => array(
175  'foo' => 'bar',
176  'some.' => array(
177  'nested' => 'value'
178  )
179  )
180  );
181  $testExtensionSettingsConverted = array(
182  'settings' => array(
183  'foo' => 'bar',
184  'some' => array(
185  'nested' => 'value'
186  )
187  )
188  );
189  $testPluginSettings = array(
190  'settings.' => array(
191  'some.' => array(
192  'nested' => 'valueOverridde',
193  'new' => 'value'
194  )
195  )
196  );
197  $testPluginSettingsConverted = array(
198  'settings' => array(
199  'some' => array(
200  'nested' => 'valueOverridde',
201  'new' => 'value'
202  )
203  )
204  );
205  $testSetup = array(
206  'module.' => array(
207  'tx_someextensionname.' => $testExtensionSettings,
208  'tx_someextensionname_somepluginname.' => $testPluginSettings
209  )
210  );
211  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
212  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
213  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
214  $expectedResult = array(
215  'settings' => array(
216  'foo' => 'bar',
217  'some' => array(
218  'nested' => 'valueOverridde',
219  'new' => 'value'
220  )
221  )
222  );
223  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
224  $this->assertEquals($expectedResult, $actualResult);
225  }
226 
231  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL;
232  $expectedResult = array();
233  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
234  $this->assertEquals($expectedResult, $actualResult);
235  }
236 
241  $testSwitchableControllerActions = array(
242  'Controller1' => array(
243  'actions' => array(
244  'action1',
245  'action2'
246  ),
247  'nonCacheableActions' => array(
248  'action1'
249  )
250  ),
251  'Controller2' => array(
252  'actions' => array(
253  'action3',
254  'action4'
255  )
256  )
257  );
258  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
259  $expectedResult = $testSwitchableControllerActions;
260  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
261  $this->assertEquals($expectedResult, $actualResult);
262  }
263 
268  $frameworkConfiguration = array(
269  'pluginName' => 'Pi1',
270  'extensionName' => 'SomeExtension',
271  'foo' => array(
272  'bar' => array(
273  'baz' => 'Foo'
274  )
275  ),
276  'mvc' => array(
277  'requestHandlers' => array(
278  'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler' => 'SomeRequestHandler'
279  )
280  )
281  );
282  $expectedResult = $frameworkConfiguration;
283  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
284  $this->assertEquals($expectedResult, $actualResult);
285  }
286 
291  $frameworkConfiguration = array(
292  'pluginName' => 'Pi1',
293  'extensionName' => 'SomeExtension',
294  'foo' => array(
295  'bar' => array(
296  'baz' => 'Foo'
297  )
298  )
299  );
300  $expectedResult = array(
301  'pluginName' => 'Pi1',
302  'extensionName' => 'SomeExtension',
303  'foo' => array(
304  'bar' => array(
305  'baz' => 'Foo'
306  )
307  ),
308  'mvc' => array(
309  'requestHandlers' => array(
310  'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler' => 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler',
311  'TYPO3\\CMS\\Extbase\\Mvc\\Web\\BackendRequestHandler' => 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\BackendRequestHandler'
312  )
313  )
314  );
315  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
316  $this->assertEquals($expectedResult, $actualResult);
317  }
318 
322  public function storagePidsAreExtendedIfRecursiveSearchIsConfigured() {
323  $storagePid = '1,2,3';
324  $recursive = 99;
326  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
327  $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
328  $queryGenerator->expects($this->any())
329  ->method('getTreeList')
330  ->will($this->onConsecutiveCalls('4', '', '5,6'));
331  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
332 
333  $expectedResult = '4,5,6';
334  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
335  $this->assertEquals($expectedResult, $actualResult);
336  }
337 
341  public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid() {
342  $storagePid = '1,2,-3';
343  $recursive = 99;
345  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
346  $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
347  $queryGenerator->expects($this->any())
348  ->method('getTreeList')
349  ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
350  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
351 
352  $expectedResult = '4,3,5,6';
353  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
354  $this->assertEquals($expectedResult, $actualResult);
355  }
356 
361  $storagePid = '1,2,3';
362 
363  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
364 
365  $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
366  $queryGenerator->expects($this->never())->method('getTreeList');
367  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
368 
369  $expectedResult = '1,2,3';
370  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
371  $this->assertEquals($expectedResult, $actualResult);
372  }
373 
378  $storagePid = '1,2,3';
379  $recursive = 0;
380 
381  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
382 
383  $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
384  $queryGenerator->expects($this->never())->method('getTreeList');
385  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
386 
387  $expectedResult = '1,2,3';
388  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
389  $this->assertEquals($expectedResult, $actualResult);
390  }
391 }
static _GETset($inputGet, $key='')
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]