‪TYPO3CMS  9.5
BackendConfigurationManagerTest.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 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪BackendConfigurationManagerTest extends UnitTestCase
25 {
30 
34  protected ‪$mockTypoScriptService;
35 
39  protected function ‪setUp()
40  {
41  $this->backendConfigurationManager = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Configuration\BackendConfigurationManager::class, ['getTypoScriptSetup']);
42  $this->mockTypoScriptService = $this->getAccessibleMock(\‪TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
43  $this->backendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
44  }
45 
50  {
51  $_GET['id'] = 123;
52  $expectedResult = 123;
53  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
54  $this->assertEquals($expectedResult, $actualResult);
55  }
56 
61  {
62  $_GET['id'] = 123;
63  $_POST['id'] = 321;
64  $expectedResult = 321;
65  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
66  $this->assertEquals($expectedResult, $actualResult);
67  }
68 
73  {
74  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(['foo' => 'bar']));
75  $expectedResult = [];
76  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
77  $this->assertEquals($expectedResult, $actualResult);
78  }
79 
84  {
85  $testSettings = [
86  'settings.' => [
87  'foo' => 'bar'
88  ]
89  ];
90  $testSettingsConverted = [
91  'settings' => [
92  'foo' => 'bar'
93  ]
94  ];
95  $testSetup = [
96  'module.' => [
97  'tx_someextensionname.' => $testSettings
98  ]
99  ];
100  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
101  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
102  $expectedResult = [
103  'settings' => [
104  'foo' => 'bar'
105  ]
106  ];
107  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
108  $this->assertEquals($expectedResult, $actualResult);
109  }
110 
115  {
116  $testSettings = [
117  'settings.' => [
118  'foo' => 'bar'
119  ]
120  ];
121  $testSettingsConverted = [
122  'settings' => [
123  'foo' => 'bar'
124  ]
125  ];
126  $testSetup = [
127  'module.' => [
128  'tx_someextensionname_somepluginname.' => $testSettings
129  ]
130  ];
131  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
132  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
133  $expectedResult = [
134  'settings' => [
135  'foo' => 'bar'
136  ]
137  ];
138  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
139  $this->assertEquals($expectedResult, $actualResult);
140  }
141 
146  {
147  $testExtensionSettings = [
148  'settings.' => [
149  'foo' => 'bar',
150  'some.' => [
151  'nested' => 'value'
152  ]
153  ]
154  ];
155  $testExtensionSettingsConverted = [
156  'settings' => [
157  'foo' => 'bar',
158  'some' => [
159  'nested' => 'value'
160  ]
161  ]
162  ];
163  $testPluginSettings = [
164  'settings.' => [
165  'some.' => [
166  'nested' => 'valueOverridde',
167  'new' => 'value'
168  ]
169  ]
170  ];
171  $testPluginSettingsConverted = [
172  'settings' => [
173  'some' => [
174  'nested' => 'valueOverridde',
175  'new' => 'value'
176  ]
177  ]
178  ];
179  $testSetup = [
180  'module.' => [
181  'tx_someextensionname.' => $testExtensionSettings,
182  'tx_someextensionname_somepluginname.' => $testPluginSettings
183  ]
184  ];
185  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
186  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
187  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
188  $expectedResult = [
189  'settings' => [
190  'foo' => 'bar',
191  'some' => [
192  'nested' => 'valueOverridde',
193  'new' => 'value'
194  ]
195  ]
196  ];
197  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
198  $this->assertEquals($expectedResult, $actualResult);
199  }
200 
205  {
206  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = null;
207  $expectedResult = [];
208  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
209  $this->assertEquals($expectedResult, $actualResult);
210  }
211 
216  {
217  $testSwitchableControllerActions = [
218  'Controller1' => [
219  'actions' => [
220  'action1',
221  'action2'
222  ],
223  'nonCacheableActions' => [
224  'action1'
225  ]
226  ],
227  'Controller2' => [
228  'actions' => [
229  'action3',
230  'action4'
231  ]
232  ]
233  ];
234  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
235  $expectedResult = $testSwitchableControllerActions;
236  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
237  $this->assertEquals($expectedResult, $actualResult);
238  }
239 
244  {
245  $frameworkConfiguration = [
246  'pluginName' => 'Pi1',
247  'extensionName' => 'SomeExtension',
248  'foo' => [
249  'bar' => [
250  'baz' => 'Foo'
251  ]
252  ],
253  'mvc' => [
254  'requestHandlers' => [
255  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => 'SomeRequestHandler'
256  ]
257  ]
258  ];
259  $expectedResult = $frameworkConfiguration;
260  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
261  $this->assertEquals($expectedResult, $actualResult);
262  }
263 
268  {
269  $frameworkConfiguration = [
270  'pluginName' => 'Pi1',
271  'extensionName' => 'SomeExtension',
272  'foo' => [
273  'bar' => [
274  'baz' => 'Foo'
275  ]
276  ]
277  ];
278  $expectedResult = [
279  'pluginName' => 'Pi1',
280  'extensionName' => 'SomeExtension',
281  'foo' => [
282  'bar' => [
283  'baz' => 'Foo'
284  ]
285  ],
286  'mvc' => [
287  'requestHandlers' => [
288  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class,
289  \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class
290  ]
291  ]
292  ];
293  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
294  $this->assertEquals($expectedResult, $actualResult);
295  }
296 
301  {
302  $storagePid = '1,2,3';
303  $recursive = 99;
304 
306  $beUserAuthentication = $this->prophesize(\‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
307  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
308  ‪$GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
309 
310  $abstractConfigurationManager = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
311  $queryGenerator = $this->createMock(\‪TYPO3\CMS\Core\Database\QueryGenerator::class);
312  $queryGenerator->expects($this->any())
313  ->method('getTreeList')
314  ->will($this->onConsecutiveCalls('4', '', '5,6'));
315  GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
316 
317  $expectedResult = '4,5,6';
318  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
319  $this->assertEquals($expectedResult, $actualResult);
320  }
321 
326  {
327  $storagePid = '1,2,-3';
328  $recursive = 99;
329 
331  $beUserAuthentication = $this->prophesize(\‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
332  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
333  ‪$GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
334 
335  $abstractConfigurationManager = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getQueryGenerator']);
336  $queryGenerator = $this->createMock(\‪TYPO3\CMS\Core\Database\QueryGenerator::class);
337  $queryGenerator->expects($this->any())
338  ->method('getTreeList')
339  ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
340  GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
341 
342  $expectedResult = '4,3,5,6';
343  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
344  $this->assertEquals($expectedResult, $actualResult);
345  }
346 
351  {
352  $storagePid = '1,2,3';
353 
354  $abstractConfigurationManager = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
355 
356  $expectedResult = '1,2,3';
357  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
358  $this->assertEquals($expectedResult, $actualResult);
359  }
360 
365  {
366  $storagePid = '1,2,3';
367  $recursive = 0;
368 
369  $abstractConfigurationManager = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
370 
371  $expectedResult = '1,2,3';
372  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
373  $this->assertEquals($expectedResult, $actualResult);
374  }
375 }
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsPluginConfiguration
‪getPluginConfigurationReturnsPluginConfiguration()
Definition: BackendConfigurationManagerTest.php:112
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getContextSpecificFrameworkConfigurationReturnsUnmodifiedFrameworkConfigurationIfRequestHandlersAreConfigured
‪getContextSpecificFrameworkConfigurationReturnsUnmodifiedFrameworkConfigurationIfRequestHandlersAreConfigured()
Definition: BackendConfigurationManagerTest.php:241
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration
‪getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration()
Definition: BackendConfigurationManagerTest.php:143
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\setUp
‪setUp()
Definition: BackendConfigurationManagerTest.php:37
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest
Definition: BackendConfigurationManagerTest.php:25
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration
Definition: AbstractConfigurationManagerTest.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels
‪storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels()
Definition: BackendConfigurationManagerTest.php:362
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getSwitchableControllerActionsReturnsEmptyArrayByDefault
‪getSwitchableControllerActionsReturnsEmptyArrayByDefault()
Definition: BackendConfigurationManagerTest.php:202
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured
‪storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured()
Definition: BackendConfigurationManagerTest.php:348
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromGet
‪getCurrentPageIdReturnsPageIdFromGet()
Definition: BackendConfigurationManagerTest.php:47
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getContextSpecificFrameworkConfigurationSetsDefaultRequestHandlersIfRequestHandlersAreNotConfigured
‪getContextSpecificFrameworkConfigurationSetsDefaultRequestHandlersIfRequestHandlersAreNotConfigured()
Definition: BackendConfigurationManagerTest.php:265
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid
‪storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid()
Definition: BackendConfigurationManagerTest.php:323
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromPost
‪getCurrentPageIdReturnsPageIdFromPost()
Definition: BackendConfigurationManagerTest.php:58
‪TYPO3\CMS\Core\Database\QueryGenerator
Definition: QueryGenerator.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsExtensionConfiguration
‪getPluginConfigurationReturnsExtensionConfiguration()
Definition: BackendConfigurationManagerTest.php:81
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreExtendedIfRecursiveSearchIsConfigured
‪storagePidsAreExtendedIfRecursiveSearchIsConfigured()
Definition: BackendConfigurationManagerTest.php:298
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getSwitchableControllerActionsReturnsConfigurationStoredInExtconf
‪getSwitchableControllerActionsReturnsConfigurationStoredInExtconf()
Definition: BackendConfigurationManagerTest.php:213
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\$mockTypoScriptService
‪TYPO3 CMS Core TypoScript TypoScriptService PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $mockTypoScriptService
Definition: BackendConfigurationManagerTest.php:32
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound
‪getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound()
Definition: BackendConfigurationManagerTest.php:70
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\$backendConfigurationManager
‪TYPO3 CMS Extbase Configuration BackendConfigurationManager PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $backendConfigurationManager
Definition: BackendConfigurationManagerTest.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45