TYPO3 CMS  TYPO3_8-7
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  */
17 
21 class FrontendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
26  protected $mockContentObject;
27 
32 
37 
41  protected function setUp()
42  {
43  $GLOBALS['TSFE'] = new \stdClass();
44  $GLOBALS['TSFE']->tmpl = new \stdClass();
45  $this->mockContentObject = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class)
46  ->setMethods(['getTreeList'])
47  ->getMock();
48  $this->frontendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['dummy']);
49  $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
50  $this->mockTypoScriptService = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
51  $this->frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
52  }
53 
58  {
59  $GLOBALS['TSFE']->tmpl->setup = ['foo' => 'bar'];
60  $this->assertEquals(['foo' => 'bar'], $this->frontendConfigurationManager->_call('getTypoScriptSetup'));
61  }
62 
67  {
68  $GLOBALS['TSFE']->tmpl->setup = ['foo' => 'bar'];
69  $expectedResult = [];
70  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
71  $this->assertEquals($expectedResult, $actualResult);
72  }
73 
78  {
79  $testSettings = [
80  'settings.' => [
81  'foo' => 'bar'
82  ]
83  ];
84  $testSettingsConverted = [
85  'settings' => [
86  'foo' => 'bar'
87  ]
88  ];
89  $testSetup = [
90  'plugin.' => [
91  'tx_someextensionname.' => $testSettings
92  ]
93  ];
94  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
95  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
96  $expectedResult = [
97  'settings' => [
98  'foo' => 'bar'
99  ]
100  ];
101  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
102  $this->assertEquals($expectedResult, $actualResult);
103  }
104 
109  {
110  $testSettings = [
111  'settings.' => [
112  'foo' => 'bar'
113  ]
114  ];
115  $testSettingsConverted = [
116  'settings' => [
117  'foo' => 'bar'
118  ]
119  ];
120  $testSetup = [
121  'plugin.' => [
122  'tx_someextensionname_somepluginname.' => $testSettings
123  ]
124  ];
125  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
126  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
127  $expectedResult = [
128  'settings' => [
129  'foo' => 'bar'
130  ]
131  ];
132  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
133  $this->assertEquals($expectedResult, $actualResult);
134  }
135 
140  {
141  $testExtensionSettings = [
142  'settings.' => [
143  'foo' => 'bar',
144  'some.' => [
145  'nested' => 'value'
146  ]
147  ]
148  ];
149  $testExtensionSettingsConverted = [
150  'settings' => [
151  'foo' => 'bar',
152  'some' => [
153  'nested' => 'value'
154  ]
155  ]
156  ];
157  $testPluginSettings = [
158  'settings.' => [
159  'some.' => [
160  'nested' => 'valueOverridde',
161  'new' => 'value'
162  ]
163  ]
164  ];
165  $testPluginSettingsConverted = [
166  'settings' => [
167  'some' => [
168  'nested' => 'valueOverridde',
169  'new' => 'value'
170  ]
171  ]
172  ];
173  $testSetup = [
174  'plugin.' => [
175  'tx_someextensionname.' => $testExtensionSettings,
176  'tx_someextensionname_somepluginname.' => $testPluginSettings
177  ]
178  ];
179  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
180  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
181  $GLOBALS['TSFE']->tmpl->setup = $testSetup;
182  $expectedResult = [
183  'settings' => [
184  'foo' => 'bar',
185  'some' => [
186  'nested' => 'valueOverridde',
187  'new' => 'value'
188  ]
189  ]
190  ];
191  $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
192  $this->assertEquals($expectedResult, $actualResult);
193  }
194 
199  {
200  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = null;
201  $expectedResult = [];
202  $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
203  $this->assertEquals($expectedResult, $actualResult);
204  }
205 
210  {
211  $testSwitchableControllerActions = [
212  'Controller1' => [
213  'actions' => [
214  'action1',
215  'action2'
216  ],
217  'nonCacheableActions' => [
218  'action1'
219  ]
220  ],
221  'Controller2' => [
222  'actions' => [
223  'action3',
224  'action4'
225  ]
226  ]
227  ];
228  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['plugins']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
229  $expectedResult = $testSwitchableControllerActions;
230  $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
231  $this->assertEquals($expectedResult, $actualResult);
232  }
233 
238  {
239  $frameworkConfiguration = [
240  'pluginName' => 'Pi1',
241  'extensionName' => 'SomeExtension',
242  'controllerConfiguration' => [
243  'Controller1' => [
244  'controller' => 'Controller1',
245  'actions' => 'action1 , action2'
246  ],
247  'Controller2' => [
248  'controller' => 'Controller2',
249  'actions' => 'action2 , action1,action3',
250  'nonCacheableActions' => 'action2, action3'
251  ]
252  ]
253  ];
254  $flexFormConfiguration = [];
255  $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
256  $this->assertSame($frameworkConfiguration, $actualResult);
257  }
258 
263  {
264  $frameworkConfiguration = [
265  'pluginName' => 'Pi1',
266  'extensionName' => 'SomeExtension',
267  'controllerConfiguration' => [
268  'Controller1' => [
269  'actions' => ['action1 , action2']
270  ],
271  'Controller2' => [
272  'actions' => ['action2', 'action1', 'action3'],
273  'nonCacheableActions' => ['action2', 'action3']
274  ]
275  ]
276  ];
277  $flexFormConfiguration = [
278  'switchableControllerActions' => 'Controller1 -> action2;Controller2->action3; Controller2->action1'
279  ];
280  $expectedResult = [
281  'pluginName' => 'Pi1',
282  'extensionName' => 'SomeExtension',
283  'controllerConfiguration' => [
284  'Controller1' => [
285  'actions' => ['action2']
286  ],
287  'Controller2' => [
288  'actions' => ['action3', 'action1'],
289  'nonCacheableActions' => [1 => 'action3']
290  ]
291  ]
292  ];
293  $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
294  $this->assertEquals($expectedResult, $actualResult);
295  }
296 
301  {
302  $this->expectException(ParseErrorException::class);
303  $this->expectExceptionCode(1257146403);
304  $frameworkConfiguration = [
305  'pluginName' => 'Pi1',
306  'extensionName' => 'SomeExtension',
307  'controllerConfiguration' => [
308  'Controller1' => [
309  'actions' => ['action1 , action2']
310  ],
311  'Controller2' => [
312  'actions' => ['action2', 'action1', 'action3'],
313  'nonCacheableActions' => ['action2', 'action3']
314  ]
315  ]
316  ];
317  $flexFormConfiguration = [
318  'switchableControllerActions' => 'Controller1->;Controller2->action3;Controller2->action1'
319  ];
320  $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexForm', $frameworkConfiguration, $flexFormConfiguration);
321  }
322 
326  public function getContextSpecificFrameworkConfigurationCorrectlyCallsOverrideMethods()
327  {
328  $frameworkConfiguration = [
329  'some' => [
330  'framework' => 'configuration'
331  ]
332  ];
334  $frontendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideStoragePidIfStartingPointIsSet', 'overrideConfigurationFromPlugin', 'overrideConfigurationFromFlexForm']);
335  $frontendConfigurationManager->expects($this->at(0))->method('overrideStoragePidIfStartingPointIsSet')->with($frameworkConfiguration)->will($this->returnValue(['overridden' => 'storagePid']));
336  $frontendConfigurationManager->expects($this->at(1))->method('overrideConfigurationFromPlugin')->with(['overridden' => 'storagePid'])->will($this->returnValue(['overridden' => 'pluginConfiguration']));
337  $frontendConfigurationManager->expects($this->at(2))->method('overrideConfigurationFromFlexForm')->with(['overridden' => 'pluginConfiguration'])->will($this->returnValue(['overridden' => 'flexFormConfiguration']));
338  $expectedResult = ['overridden' => 'flexFormConfiguration'];
339  $actualResult = $frontendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
340  $this->assertEquals($expectedResult, $actualResult);
341  }
342 
346  public function storagePidsAreExtendedIfRecursiveSearchIsConfigured()
347  {
348  $storagePid = '3,5,9';
349  $recursive = 99;
351  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
353  $cObjectMock = $this->createMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
354  $cObjectMock->expects($this->any())
355  ->method('getTreeList')
356  ->will($this->onConsecutiveCalls('4', '', '898,12'));
357  $abstractConfigurationManager->setContentObject($cObjectMock);
358 
359  $expectedResult = '4,898,12';
360  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
361  $this->assertEquals($expectedResult, $actualResult);
362  }
363 
367  public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid()
368  {
369  $storagePid = '-3,5,9';
370  $recursive = 99;
372  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
374  $cObjectMock = $this->createMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
375  $cObjectMock->expects($this->any())
376  ->method('getTreeList')
377  ->will($this->onConsecutiveCalls('3,4', '', '898,12'));
378  $abstractConfigurationManager->setContentObject($cObjectMock);
379 
380  $expectedResult = '3,4,898,12';
381  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
382  $this->assertEquals($expectedResult, $actualResult);
383  }
384 
388  public function storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured()
389  {
390  $storagePid = '1,2,3';
391 
393  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
395  $cObjectMock = $this->createMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
396  $cObjectMock->expects($this->never())->method('getTreeList');
397  $abstractConfigurationManager->setContentObject($cObjectMock);
398 
399  $expectedResult = '1,2,3';
400  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
401  $this->assertEquals($expectedResult, $actualResult);
402  }
403 
407  public function storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels()
408  {
409  $storagePid = '1,2,3';
410  $recursive = 0;
411 
412  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
413 
415  $cObjectMock = $this->createMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
416  $cObjectMock->expects($this->never())->method('getTreeList');
417  $abstractConfigurationManager->setContentObject($cObjectMock);
418 
419  $expectedResult = '1,2,3';
420  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
421  $this->assertEquals($expectedResult, $actualResult);
422  }
423 
428  {
429  $configuration = [
430  'persistence' => [
431  'storagePid' => '0,1,2,3'
432  ]
433  ];
434 
435  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
436  $this->assertSame(
437  ['persistence' => ['storagePid' => '0,1,2,3']],
438  $this->frontendConfigurationManager->_call('mergeConfigurationIntoFrameworkConfiguration', $frameworkConfiguration, $configuration, 'persistence')
439  );
440  }
441 
446  {
447  $this->mockContentObject->expects($this->any())->method('getTreeList')->will($this->returnValue('1,2,3'));
448  $this->mockContentObject->data = ['pages' => '0', 'recursive' => 1];
449 
450  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
451  $this->assertSame(
452  ['persistence' => ['storagePid' => '0,1,2,3']],
453  $this->frontendConfigurationManager->_call('overrideStoragePidIfStartingPointIsSet', $frameworkConfiguration)
454  );
455  }
456 
461  {
462  $this->mockContentObject->expects($this->any())->method('getTreeList')->will($this->returnValue(''));
463  $this->mockContentObject->data = ['pages' => '0', 'recursive' => 1];
464 
465  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
466  $this->assertSame(
467  ['persistence' => ['storagePid' => '0']],
468  $this->frontendConfigurationManager->_call('overrideStoragePidIfStartingPointIsSet', $frameworkConfiguration)
469  );
470  }
471 
475  public function overrideConfigurationFromFlexFormChecksForDataIsString()
476  {
478  $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
479  ->setMethods(['convertFlexFormContentToArray'])
480  ->getMock();
481  $flexFormService->expects($this->once())->method('convertFlexFormContentToArray')->will($this->returnValue([
482  'persistence' => [
483  'storagePid' => '0,1,2,3'
484  ]
485  ]));
486 
487  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
488  $this->mockContentObject->data = ['pi_flexform' => '<XML_ARRAY>'];
489 
490  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
491  $this->assertSame(
492  ['persistence' => ['storagePid' => '0,1,2,3']],
493  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
494  );
495  }
496 
500  public function overrideConfigurationFromFlexFormChecksForDataIsStringAndEmpty()
501  {
503  $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
504  ->setMethods(['convertFlexFormContentToArray'])
505  ->getMock();
506  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
507 
508  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
509  $this->mockContentObject->data = ['pi_flexform' => ''];
510 
511  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
512  $this->assertSame(
513  ['persistence' => ['storagePid' => '98']],
514  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
515  );
516  }
517 
521  public function overrideConfigurationFromFlexFormChecksForDataIsArray()
522  {
524  $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
525  ->setMethods(['convertFlexFormContentToArray'])
526  ->getMock();
527  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
528 
529  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
530  $this->mockContentObject->data = ['pi_flexform' => ['persistence' => ['storagePid' => '0,1,2,3']]];
531 
532  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
533  $this->assertSame(
534  ['persistence' => ['storagePid' => '0,1,2,3']],
535  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
536  );
537  }
538 
542  public function overrideConfigurationFromFlexFormChecksForDataIsArrayAndEmpty()
543  {
545  $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
546  ->setMethods(['convertFlexFormContentToArray'])
547  ->getMock();
548  $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
549 
550  $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
551  $this->mockContentObject->data = ['pi_flexform' => []];
552 
553  $frameworkConfiguration = ['persistence' => ['storagePid' => '98']];
554  $this->assertSame(
555  ['persistence' => ['storagePid' => '98']],
556  $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
557  );
558  }
559 
563  public function overrideConfigurationFromPluginOverridesCorrectly()
564  {
566  $frontendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class, ['getTypoScriptSetup']);
567  $frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
568  $frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
569 
570  $this->mockTypoScriptService->expects($this->once())->method('convertTypoScriptArrayToPlainArray')->will($this->returnValue([
571  'persistence' => [
572  'storagePid' => '0,1,2,3'
573  ],
574  'settings' => [
575  'foo' => 'bar'
576  ],
577  'view' => [
578  'foo' => 'bar'
579  ],
580  ]));
581  $frontendConfigurationManager->expects($this->any())->method('getTypoScriptSetup')->will($this->returnValue([
582  'plugin.' => [
583  'tx_ext_pi1.' => [
584  'persistence.' => [
585  'storagePid' => '0,1,2,3'
586  ],
587  'settings.' => [
588  'foo' => 'bar'
589  ],
590  'view.' => [
591  'foo' => 'bar'
592  ],
593  ]
594  ]
595  ]));
596 
597  $frameworkConfiguration = [
598  'extensionName' => 'ext',
599  'pluginName' => 'pi1',
600  'persistence' => [
601  'storagePid' => '1'
602  ],
603  'settings' => [
604  'foo' => 'qux'
605  ],
606  'view' => [
607  'foo' => 'qux'
608  ],
609  ];
610  $this->assertSame(
611  [
612  'extensionName' => 'ext',
613  'pluginName' => 'pi1',
614  'persistence' => [
615  'storagePid' => '0,1,2,3',
616  ],
617  'settings' => [
618  'foo' => 'bar'
619  ],
620  'view' => [
621  'foo' => 'bar'
622  ],
623  ],
624  $frontendConfigurationManager->_call('overrideConfigurationFromPlugin', $frameworkConfiguration)
625  );
626  }
627 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']