TYPO3 CMS  TYPO3_6-2
FrontendConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $mockContentObject;
26 
31 
36 
40  public function setUp() {
41  $GLOBALS['TSFE'] = new \stdClass();
42  $GLOBALS['TSFE']->tmpl = new \stdClass();
43  $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
44  $this->frontendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('dummy'));
45  $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
46  $this->mockTypoScriptService = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
47  $this->frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
48  }
49 
54  $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
55  $this->assertEquals(array('foo' => 'bar'), $this->frontendConfigurationManager->_call('getTypoScriptSetup'));
56  }
57 
62  $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
63  $expectedResult = array();
64  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
65  $this->assertEquals($expectedResult, $actualResult);
66  }
67 
72  $testSettings = array(
73  'settings.' => array(
74  'foo' => 'bar'
75  )
76  );
77  $testSettingsConverted = array(
78  'settings' => array(
79  'foo' => 'bar'
80  )
81  );
82  $testSetup = array(
83  'plugin.' => array(
84  'tx_someextensionname.' => $testSettings
85  )
86  );
87  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
88  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
89  $expectedResult = array(
90  'settings' => array(
91  'foo' => 'bar'
92  )
93  );
94  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
95  $this->assertEquals($expectedResult, $actualResult);
96  }
97 
102  $testSettings = array(
103  'settings.' => array(
104  'foo' => 'bar'
105  )
106  );
107  $testSettingsConverted = array(
108  'settings' => array(
109  'foo' => 'bar'
110  )
111  );
112  $testSetup = array(
113  'plugin.' => array(
114  'tx_someextensionname_somepluginname.' => $testSettings
115  )
116  );
117  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
118  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
119  $expectedResult = array(
120  'settings' => array(
121  'foo' => 'bar'
122  )
123  );
124  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
125  $this->assertEquals($expectedResult, $actualResult);
126  }
127 
132  $testExtensionSettings = array(
133  'settings.' => array(
134  'foo' => 'bar',
135  'some.' => array(
136  'nested' => 'value'
137  )
138  )
139  );
140  $testExtensionSettingsConverted = array(
141  'settings' => array(
142  'foo' => 'bar',
143  'some' => array(
144  'nested' => 'value'
145  )
146  )
147  );
148  $testPluginSettings = array(
149  'settings.' => array(
150  'some.' => array(
151  'nested' => 'valueOverridde',
152  'new' => 'value'
153  )
154  )
155  );
156  $testPluginSettingsConverted = array(
157  'settings' => array(
158  'some' => array(
159  'nested' => 'valueOverridde',
160  'new' => 'value'
161  )
162  )
163  );
164  $testSetup = array(
165  'plugin.' => array(
166  'tx_someextensionname.' => $testExtensionSettings,
167  'tx_someextensionname_somepluginname.' => $testPluginSettings
168  )
169  );
170  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
171  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
172  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
173  $expectedResult = array(
174  'settings' => array(
175  'foo' => 'bar',
176  'some' => array(
177  'nested' => 'valueOverridde',
178  'new' => 'value'
179  )
180  )
181  );
182  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
183  $this->assertEquals($expectedResult, $actualResult);
184  }
185 
190  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL;
191  $expectedResult = array();
192  $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
193  $this->assertEquals($expectedResult, $actualResult);
194  }
195 
200  $testSwitchableControllerActions = array(
201  'Controller1' => array(
202  'actions' => array(
203  'action1',
204  'action2'
205  ),
206  'nonCacheableActions' => array(
207  'action1'
208  )
209  ),
210  'Controller2' => array(
211  'actions' => array(
212  'action3',
213  'action4'
214  )
215  )
216  );
217  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['plugins']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
218  $expectedResult = $testSwitchableControllerActions;
219  $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
220  $this->assertEquals($expectedResult, $actualResult);
221  }
222 
227  $frameworkConfiguration = array(
228  'pluginName' => 'Pi1',
229  'extensionName' => 'SomeExtension',
230  'controllerConfiguration' => array(
231  'Controller1' => array(
232  'controller' => 'Controller1',
233  'actions' => 'action1 , action2'
234  ),
235  'Controller2' => array(
236  'controller' => 'Controller2',
237  'actions' => 'action2 , action1,action3',
238  'nonCacheableActions' => 'action2, action3'
239  )
240  )
241  );
242  $flexFormConfiguration = array();
243  $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
244  $this->assertSame($frameworkConfiguration, $actualResult);
245  }
246 
251  $frameworkConfiguration = array(
252  'pluginName' => 'Pi1',
253  'extensionName' => 'SomeExtension',
254  'controllerConfiguration' => array(
255  'Controller1' => array(
256  'actions' => array('action1 , action2')
257  ),
258  'Controller2' => array(
259  'actions' => array('action2', 'action1', 'action3'),
260  'nonCacheableActions' => array('action2', 'action3')
261  )
262  )
263  );
264  $flexFormConfiguration = array(
265  'switchableControllerActions' => 'Controller1 -> action2;Controller2->action3; Controller2->action1'
266  );
267  $expectedResult = array(
268  'pluginName' => 'Pi1',
269  'extensionName' => 'SomeExtension',
270  'controllerConfiguration' => array(
271  'Controller1' => array(
272  'actions' => array('action2')
273  ),
274  'Controller2' => array(
275  'actions' => array('action3', 'action1'),
276  'nonCacheableActions' => array(1 => 'action3')
277  )
278  )
279  );
280  $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
281  $this->assertEquals($expectedResult, $actualResult);
282  }
283 
289  $frameworkConfiguration = array(
290  'pluginName' => 'Pi1',
291  'extensionName' => 'SomeExtension',
292  'controllerConfiguration' => array(
293  'Controller1' => array(
294  'actions' => array('action1 , action2')
295  ),
296  'Controller2' => array(
297  'actions' => array('action2', 'action1', 'action3'),
298  'nonCacheableActions' => array('action2', 'action3')
299  )
300  )
301  );
302  $flexFormConfiguration = array(
303  'switchableControllerActions' => 'Controller1->;Controller2->action3;Controller2->action1'
304  );
305  $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
306  }
307 
311  public function getContextSpecificFrameworkConfigurationCorrectlyCallsOverrideMethods() {
312  $frameworkConfiguration = array(
313  'some' => array(
314  'framework' => 'configuration'
315  )
316  );
318  $frontendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideStoragePidIfStartingPointIsSet', 'overrideConfigurationFromPlugin', 'overrideConfigurationFromFlexForm'));
319  $frontendConfigurationManager->expects($this->at(0))->method('overrideStoragePidIfStartingPointIsSet')->with($frameworkConfiguration)->will($this->returnValue(array('overridden' => 'storagePid')));
320  $frontendConfigurationManager->expects($this->at(1))->method('overrideConfigurationFromPlugin')->with(array('overridden' => 'storagePid'))->will($this->returnValue(array('overridden' => 'pluginConfiguration')));
321  $frontendConfigurationManager->expects($this->at(2))->method('overrideConfigurationFromFlexForm')->with(array('overridden' => 'pluginConfiguration'))->will($this->returnValue(array('overridden' => 'flexFormConfiguration')));
322  $expectedResult = array('overridden' => 'flexFormConfiguration');
323  $actualResult = $frontendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
324  $this->assertEquals($expectedResult, $actualResult);
325  }
326 
330  public function storagePidsAreExtendedIfRecursiveSearchIsConfigured() {
331  $storagePid = '3,5,9';
332  $recursive = 99;
334  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
336  $cObjectMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
337  $cObjectMock->expects($this->any())
338  ->method('getTreeList')
339  ->will($this->onConsecutiveCalls('4', '', '898,12'));
340  $abstractConfigurationManager->setContentObject($cObjectMock);
341 
342  $expectedResult = '4,898,12';
343  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
344  $this->assertEquals($expectedResult, $actualResult);
345  }
346 
350  public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid() {
351  $storagePid = '-3,5,9';
352  $recursive = 99;
354  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
356  $cObjectMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
357  $cObjectMock->expects($this->any())
358  ->method('getTreeList')
359  ->will($this->onConsecutiveCalls('3,4', '', '898,12'));
360  $abstractConfigurationManager->setContentObject($cObjectMock);
361 
362  $expectedResult = '3,4,898,12';
363  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
364  $this->assertEquals($expectedResult, $actualResult);
365  }
366 
370  public function storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured() {
371  $storagePid = '1,2,3';
372 
374  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
376  $cObjectMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
377  $cObjectMock->expects($this->never())->method('getTreeList');
378  $abstractConfigurationManager->setContentObject($cObjectMock);
379 
380  $expectedResult = '1,2,3';
381  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
382  $this->assertEquals($expectedResult, $actualResult);
383  }
384 
388  public function storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels() {
389  $storagePid = '1,2,3';
390  $recursive = 0;
391 
392  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
393 
395  $cObjectMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
396  $cObjectMock->expects($this->never())->method('getTreeList');
397  $abstractConfigurationManager->setContentObject($cObjectMock);
398 
399  $expectedResult = '1,2,3';
400  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
401  $this->assertEquals($expectedResult, $actualResult);
402  }
403 
409  $configuration = array(
410  'persistence' => array(
411  'storagePid' => '0,1,2,3'
412  )
413  );
414 
415  $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
416  $this->assertSame(
417  array('persistence' => array('storagePid' => '0,1,2,3')),
418  $this->frontendConfigurationManager->_call('mergeConfigurationIntoFrameworkConfiguration', $frameworkConfiguration, $configuration, 'persistence')
419  );
420  }
421 
427  $this->mockContentObject->expects($this->any())->method('getTreeList')->will($this->returnValue('1,2,3'));
428  $this->mockContentObject->data = array('pages' => '0', 'recursive' => 1);
429 
430  $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
431  $this->assertSame(
432  array('persistence' => array('storagePid' => '0,1,2,3')),
433  $this->frontendConfigurationManager->_call('overrideStoragePidIfStartingPointIsSet', $frameworkConfiguration)
434  );
435  }
436 
440  public function overrideConfigurationFromFlexFormChecksForDataIsString() {
442  $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
443  $flexFormService->expects($this->once())->method('convertFlexFormContentToArray')->will($this->returnValue(array(
444  'persistence' => array(
445  'storagePid' => '0,1,2,3'
446  )
447  )));
448 
449  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
450  $this->mockContentObject->data = array('pi_flexform' => '<XML_ARRAY>');
451 
452  $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
453  $this->assertSame(
454  array('persistence' => array('storagePid' => '0,1,2,3')),
455  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
456  );
457  }
458 
462  public function overrideConfigurationFromFlexFormChecksForDataIsStringAndEmpty() {
464  $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
465  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
466 
467  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
468  $this->mockContentObject->data = array('pi_flexform' => '');
469 
470  $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
471  $this->assertSame(
472  array('persistence' => array('storagePid' => '98')),
473  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
474  );
475  }
476 
480  public function overrideConfigurationFromFlexFormChecksForDataIsArray() {
482  $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
483  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
484 
485  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
486  $this->mockContentObject->data = array('pi_flexform' => array('persistence' => array('storagePid' => '0,1,2,3')));
487 
488  $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
489  $this->assertSame(
490  array('persistence' => array('storagePid' => '0,1,2,3')),
491  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
492  );
493  }
494 
498  public function overrideConfigurationFromFlexFormChecksForDataIsArrayAndEmpty() {
500  $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
501  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
502 
503  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
504  $this->mockContentObject->data = array('pi_flexform' => array());
505 
506  $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
507  $this->assertSame(
508  array('persistence' => array('storagePid' => '98')),
509  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
510  );
511  }
512 
517  public function overrideConfigurationFromPluginOverridesCorrectly() {
519  $frontendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('getTypoScriptSetup'));
520  $frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
521  $frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
522 
523  $this->mockTypoScriptService->expects($this->once())->method('convertTypoScriptArrayToPlainArray')->will($this->returnValue(array(
524  'persistence' => array(
525  'storagePid' => '0,1,2,3'
526  ),
527  'settings' => array(
528  'foo' => 'bar'
529  ),
530  'view' => array(
531  'foo' => 'bar'
532  ),
533  )));
534  $frontendConfigurationManager->expects($this->any())->method('getTypoScriptSetup')->will($this->returnValue(array(
535  'plugin.' => array(
536  'tx_ext_pi1.' => array(
537  'persistence.' => array(
538  'storagePid' => '0,1,2,3'
539  ),
540  'settings.' => array(
541  'foo' => 'bar'
542  ),
543  'view.' => array(
544  'foo' => 'bar'
545  ),
546  )
547  )
548  )));
549 
550  $frameworkConfiguration = array(
551  'extensionName' => 'ext',
552  'pluginName' => 'pi1',
553  'persistence' => array(
554  'storagePid' => '1'
555  ),
556  'settings' => array(
557  'foo' => 'qux'
558  ),
559  'view' => array(
560  'foo' => 'qux'
561  ),
562  );
563  $this->assertSame(
564  array(
565  'extensionName' => 'ext',
566  'pluginName' => 'pi1',
567  'persistence' => array(
568  'storagePid' => '0,1,2,3',
569  ),
570  'settings' => array(
571  'foo' => 'bar'
572  ),
573  'view' => array(
574  'foo' => 'bar'
575  ),
576  ),
577  $frontendConfigurationManager->_call('overrideConfigurationFromPlugin', $frameworkConfiguration)
578  );
579  }
580 }
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'][]