TYPO3 CMS  TYPO3_7-6
FrontendConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  protected $mockContentObject;
26 
31 
36 
40  protected function setUp()
41  {
42  $GLOBALS['TSFE'] = new \stdClass();
43  $GLOBALS['TSFE']->tmpl = new \stdClass();
44  $this->mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, ['getTreeList']);
45  $this->frontendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['dummy']);
46  $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
47  $this->mockTypoScriptService = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Service\TypoScriptService::class);
48  $this->frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
49  }
50 
55  {
56  $GLOBALS['TSFE']->tmpl->setup = ['foo' => 'bar'];
57  $this->assertEquals(['foo' => 'bar'], $this->frontendConfigurationManager->_call('getTypoScriptSetup'));
58  }
59 
64  {
65  $GLOBALS['TSFE']->tmpl->setup = ['foo' => 'bar'];
66  $expectedResult = [];
67  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
68  $this->assertEquals($expectedResult, $actualResult);
69  }
70 
75  {
76  $testSettings = [
77  'settings.' => [
78  'foo' => 'bar'
79  ]
80  ];
81  $testSettingsConverted = [
82  'settings' => [
83  'foo' => 'bar'
84  ]
85  ];
86  $testSetup = [
87  'plugin.' => [
88  'tx_someextensionname.' => $testSettings
89  ]
90  ];
91  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
92  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
93  $expectedResult = [
94  'settings' => [
95  'foo' => 'bar'
96  ]
97  ];
98  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
99  $this->assertEquals($expectedResult, $actualResult);
100  }
101 
106  {
107  $testSettings = [
108  'settings.' => [
109  'foo' => 'bar'
110  ]
111  ];
112  $testSettingsConverted = [
113  'settings' => [
114  'foo' => 'bar'
115  ]
116  ];
117  $testSetup = [
118  'plugin.' => [
119  'tx_someextensionname_somepluginname.' => $testSettings
120  ]
121  ];
122  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
123  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
124  $expectedResult = [
125  'settings' => [
126  'foo' => 'bar'
127  ]
128  ];
129  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
130  $this->assertEquals($expectedResult, $actualResult);
131  }
132 
137  {
138  $testExtensionSettings = [
139  'settings.' => [
140  'foo' => 'bar',
141  'some.' => [
142  'nested' => 'value'
143  ]
144  ]
145  ];
146  $testExtensionSettingsConverted = [
147  'settings' => [
148  'foo' => 'bar',
149  'some' => [
150  'nested' => 'value'
151  ]
152  ]
153  ];
154  $testPluginSettings = [
155  'settings.' => [
156  'some.' => [
157  'nested' => 'valueOverridde',
158  'new' => 'value'
159  ]
160  ]
161  ];
162  $testPluginSettingsConverted = [
163  'settings' => [
164  'some' => [
165  'nested' => 'valueOverridde',
166  'new' => 'value'
167  ]
168  ]
169  ];
170  $testSetup = [
171  'plugin.' => [
172  'tx_someextensionname.' => $testExtensionSettings,
173  'tx_someextensionname_somepluginname.' => $testPluginSettings
174  ]
175  ];
176  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
177  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
178  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
179  $expectedResult = [
180  'settings' => [
181  'foo' => 'bar',
182  'some' => [
183  'nested' => 'valueOverridde',
184  'new' => 'value'
185  ]
186  ]
187  ];
188  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
189  $this->assertEquals($expectedResult, $actualResult);
190  }
191 
196  {
197  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = null;
198  $expectedResult = [];
199  $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
200  $this->assertEquals($expectedResult, $actualResult);
201  }
202 
207  {
208  $testSwitchableControllerActions = [
209  'Controller1' => [
210  'actions' => [
211  'action1',
212  'action2'
213  ],
214  'nonCacheableActions' => [
215  'action1'
216  ]
217  ],
218  'Controller2' => [
219  'actions' => [
220  'action3',
221  'action4'
222  ]
223  ]
224  ];
225  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['plugins']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
226  $expectedResult = $testSwitchableControllerActions;
227  $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
228  $this->assertEquals($expectedResult, $actualResult);
229  }
230 
235  {
236  $frameworkConfiguration = [
237  'pluginName' => 'Pi1',
238  'extensionName' => 'SomeExtension',
239  'controllerConfiguration' => [
240  'Controller1' => [
241  'controller' => 'Controller1',
242  'actions' => 'action1 , action2'
243  ],
244  'Controller2' => [
245  'controller' => 'Controller2',
246  'actions' => 'action2 , action1,action3',
247  'nonCacheableActions' => 'action2, action3'
248  ]
249  ]
250  ];
251  $flexFormConfiguration = [];
252  $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
253  $this->assertSame($frameworkConfiguration, $actualResult);
254  }
255 
260  {
261  $frameworkConfiguration = [
262  'pluginName' => 'Pi1',
263  'extensionName' => 'SomeExtension',
264  'controllerConfiguration' => [
265  'Controller1' => [
266  'actions' => ['action1 , action2']
267  ],
268  'Controller2' => [
269  'actions' => ['action2', 'action1', 'action3'],
270  'nonCacheableActions' => ['action2', 'action3']
271  ]
272  ]
273  ];
274  $flexFormConfiguration = [
275  'switchableControllerActions' => 'Controller1 -> action2;Controller2->action3; Controller2->action1'
276  ];
277  $expectedResult = [
278  'pluginName' => 'Pi1',
279  'extensionName' => 'SomeExtension',
280  'controllerConfiguration' => [
281  'Controller1' => [
282  'actions' => ['action2']
283  ],
284  'Controller2' => [
285  'actions' => ['action3', 'action1'],
286  'nonCacheableActions' => [1 => 'action3']
287  ]
288  ]
289  ];
290  $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
291  $this->assertEquals($expectedResult, $actualResult);
292  }
293 
299  {
300  $frameworkConfiguration = [
301  'pluginName' => 'Pi1',
302  'extensionName' => 'SomeExtension',
303  'controllerConfiguration' => [
304  'Controller1' => [
305  'actions' => ['action1 , action2']
306  ],
307  'Controller2' => [
308  'actions' => ['action2', 'action1', 'action3'],
309  'nonCacheableActions' => ['action2', 'action3']
310  ]
311  ]
312  ];
313  $flexFormConfiguration = [
314  'switchableControllerActions' => 'Controller1->;Controller2->action3;Controller2->action1'
315  ];
316  $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
317  }
318 
322  public function getContextSpecificFrameworkConfigurationCorrectlyCallsOverrideMethods()
323  {
324  $frameworkConfiguration = [
325  'some' => [
326  'framework' => 'configuration'
327  ]
328  ];
330  $frontendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideStoragePidIfStartingPointIsSet', 'overrideConfigurationFromPlugin', 'overrideConfigurationFromFlexForm']);
331  $frontendConfigurationManager->expects($this->at(0))->method('overrideStoragePidIfStartingPointIsSet')->with($frameworkConfiguration)->will($this->returnValue(['overridden' => 'storagePid']));
332  $frontendConfigurationManager->expects($this->at(1))->method('overrideConfigurationFromPlugin')->with(['overridden' => 'storagePid'])->will($this->returnValue(['overridden' => 'pluginConfiguration']));
333  $frontendConfigurationManager->expects($this->at(2))->method('overrideConfigurationFromFlexForm')->with(['overridden' => 'pluginConfiguration'])->will($this->returnValue(['overridden' => 'flexFormConfiguration']));
334  $expectedResult = ['overridden' => 'flexFormConfiguration'];
335  $actualResult = $frontendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
336  $this->assertEquals($expectedResult, $actualResult);
337  }
338 
342  public function storagePidsAreExtendedIfRecursiveSearchIsConfigured()
343  {
344  $storagePid = '3,5,9';
345  $recursive = 99;
347  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
349  $cObjectMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
350  $cObjectMock->expects($this->any())
351  ->method('getTreeList')
352  ->will($this->onConsecutiveCalls('4', '', '898,12'));
353  $abstractConfigurationManager->setContentObject($cObjectMock);
354 
355  $expectedResult = '4,898,12';
356  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
357  $this->assertEquals($expectedResult, $actualResult);
358  }
359 
363  public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid()
364  {
365  $storagePid = '-3,5,9';
366  $recursive = 99;
368  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
370  $cObjectMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
371  $cObjectMock->expects($this->any())
372  ->method('getTreeList')
373  ->will($this->onConsecutiveCalls('3,4', '', '898,12'));
374  $abstractConfigurationManager->setContentObject($cObjectMock);
375 
376  $expectedResult = '3,4,898,12';
377  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
378  $this->assertEquals($expectedResult, $actualResult);
379  }
380 
384  public function storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured()
385  {
386  $storagePid = '1,2,3';
387 
389  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
391  $cObjectMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
392  $cObjectMock->expects($this->never())->method('getTreeList');
393  $abstractConfigurationManager->setContentObject($cObjectMock);
394 
395  $expectedResult = '1,2,3';
396  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
397  $this->assertEquals($expectedResult, $actualResult);
398  }
399 
403  public function storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels()
404  {
405  $storagePid = '1,2,3';
406  $recursive = 0;
407 
408  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
409 
411  $cObjectMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
412  $cObjectMock->expects($this->never())->method('getTreeList');
413  $abstractConfigurationManager->setContentObject($cObjectMock);
414 
415  $expectedResult = '1,2,3';
416  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
417  $this->assertEquals($expectedResult, $actualResult);
418  }
419 
424  {
425  $configuration = [
426  'persistence' => [
427  'storagePid' => '0,1,2,3'
428  ]
429  ];
430 
431  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
432  $this->assertSame(
433  ['persistence' => ['storagePid' => '0,1,2,3']],
434  $this->frontendConfigurationManager->_call('mergeConfigurationIntoFrameworkConfiguration', $frameworkConfiguration, $configuration, 'persistence')
435  );
436  }
437 
442  {
443  $this->mockContentObject->expects($this->any())->method('getTreeList')->will($this->returnValue('1,2,3'));
444  $this->mockContentObject->data = ['pages' => '0', 'recursive' => 1];
445 
446  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
447  $this->assertSame(
448  ['persistence' => ['storagePid' => '0,1,2,3']],
449  $this->frontendConfigurationManager->_call('overrideStoragePidIfStartingPointIsSet', $frameworkConfiguration)
450  );
451  }
452 
456  public function overrideConfigurationFromFlexFormChecksForDataIsString()
457  {
459  $flexFormService = $this->getMock(\TYPO3\CMS\Extbase\Service\FlexFormService::class, ['convertFlexFormContentToArray']);
460  $flexFormService->expects($this->once())->method('convertFlexFormContentToArray')->will($this->returnValue([
461  'persistence' => [
462  'storagePid' => '0,1,2,3'
463  ]
464  ]));
465 
466  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
467  $this->mockContentObject->data = ['pi_flexform' => '<XML_ARRAY>'];
468 
469  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
470  $this->assertSame(
471  ['persistence' => ['storagePid' => '0,1,2,3']],
472  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
473  );
474  }
475 
479  public function overrideConfigurationFromFlexFormChecksForDataIsStringAndEmpty()
480  {
482  $flexFormService = $this->getMock(\TYPO3\CMS\Extbase\Service\FlexFormService::class, ['convertFlexFormContentToArray']);
483  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
484 
485  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
486  $this->mockContentObject->data = ['pi_flexform' => ''];
487 
488  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
489  $this->assertSame(
490  ['persistence' => ['storagePid' => '98']],
491  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
492  );
493  }
494 
498  public function overrideConfigurationFromFlexFormChecksForDataIsArray()
499  {
501  $flexFormService = $this->getMock(\TYPO3\CMS\Extbase\Service\FlexFormService::class, ['convertFlexFormContentToArray']);
502  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
503 
504  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
505  $this->mockContentObject->data = ['pi_flexform' => ['persistence' => ['storagePid' => '0,1,2,3']]];
506 
507  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
508  $this->assertSame(
509  ['persistence' => ['storagePid' => '0,1,2,3']],
510  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
511  );
512  }
513 
517  public function overrideConfigurationFromFlexFormChecksForDataIsArrayAndEmpty()
518  {
520  $flexFormService = $this->getMock(\TYPO3\CMS\Extbase\Service\FlexFormService::class, ['convertFlexFormContentToArray']);
521  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
522 
523  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
524  $this->mockContentObject->data = ['pi_flexform' => []];
525 
526  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
527  $this->assertSame(
528  ['persistence' => ['storagePid' => '98']],
529  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
530  );
531  }
532 
536  public function overrideConfigurationFromPluginOverridesCorrectly()
537  {
539  $frontendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['getTypoScriptSetup']);
540  $frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
541  $frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
542 
543  $this->mockTypoScriptService->expects($this->once())->method('convertTypoScriptArrayToPlainArray')->will($this->returnValue([
544  'persistence' => [
545  'storagePid' => '0,1,2,3'
546  ],
547  'settings' => [
548  'foo' => 'bar'
549  ],
550  'view' => [
551  'foo' => 'bar'
552  ],
553  ]));
554  $frontendConfigurationManager->expects($this->any())->method('getTypoScriptSetup')->will($this->returnValue([
555  'plugin.' => [
556  'tx_ext_pi1.' => [
557  'persistence.' => [
558  'storagePid' => '0,1,2,3'
559  ],
560  'settings.' => [
561  'foo' => 'bar'
562  ],
563  'view.' => [
564  'foo' => 'bar'
565  ],
566  ]
567  ]
568  ]));
569 
570  $frameworkConfiguration = [
571  'extensionName' => 'ext',
572  'pluginName' => 'pi1',
573  'persistence' => [
574  'storagePid' => '1'
575  ],
576  'settings' => [
577  'foo' => 'qux'
578  ],
579  'view' => [
580  'foo' => 'qux'
581  ],
582  ];
583  $this->assertSame(
584  [
585  'extensionName' => 'ext',
586  'pluginName' => 'pi1',
587  'persistence' => [
588  'storagePid' => '0,1,2,3',
589  ],
590  'settings' => [
591  'foo' => 'bar'
592  ],
593  'view' => [
594  'foo' => 'bar'
595  ],
596  ],
597  $frontendConfigurationManager->_call('overrideConfigurationFromPlugin', $frameworkConfiguration)
598  );
599  }
600 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']