‪TYPO3CMS  10.4
BackendConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Prophecy\ObjectProphecy;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪BackendConfigurationManagerTest extends UnitTestCase
30 {
35 
39  protected ‪$mockTypoScriptService;
40 
44  protected function ‪setUp(): void
45  {
46  parent::setUp();
47  $this->backendConfigurationManager = $this->getAccessibleMock(
48  BackendConfigurationManager::class,
49  ['getTypoScriptSetup'],
50  [],
51  '',
52  false
53  );
54  $this->mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
55  $this->backendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
56  }
57 
62  {
63  $_GET['id'] = 123;
64  $expectedResult = 123;
65  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
66  self::assertEquals($expectedResult, $actualResult);
67  }
68 
73  {
74  $_GET['id'] = 123;
75  $_POST['id'] = 321;
76  $expectedResult = 321;
77  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
78  self::assertEquals($expectedResult, $actualResult);
79  }
80 
85  {
86  $this->backendConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn(['foo' => 'bar']);
87  $expectedResult = [];
88  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
89  self::assertEquals($expectedResult, $actualResult);
90  }
91 
96  {
97  $testSettings = [
98  'settings.' => [
99  'foo' => 'bar'
100  ]
101  ];
102  $testSettingsConverted = [
103  'settings' => [
104  'foo' => 'bar'
105  ]
106  ];
107  $testSetup = [
108  'module.' => [
109  'tx_someextensionname.' => $testSettings
110  ]
111  ];
112  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->willReturn($testSettingsConverted);
113  $this->backendConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($testSetup);
114  $expectedResult = [
115  'settings' => [
116  'foo' => 'bar'
117  ]
118  ];
119  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
120  self::assertEquals($expectedResult, $actualResult);
121  }
122 
127  {
128  $testSettings = [
129  'settings.' => [
130  'foo' => 'bar'
131  ]
132  ];
133  $testSettingsConverted = [
134  'settings' => [
135  'foo' => 'bar'
136  ]
137  ];
138  $testSetup = [
139  'module.' => [
140  'tx_someextensionname_somepluginname.' => $testSettings
141  ]
142  ];
143  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->willReturn($testSettingsConverted);
144  $this->backendConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($testSetup);
145  $expectedResult = [
146  'settings' => [
147  'foo' => 'bar'
148  ]
149  ];
150  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
151  self::assertEquals($expectedResult, $actualResult);
152  }
153 
158  {
159  $testExtensionSettings = [
160  'settings.' => [
161  'foo' => 'bar',
162  'some.' => [
163  'nested' => 'value'
164  ]
165  ]
166  ];
167  $testExtensionSettingsConverted = [
168  'settings' => [
169  'foo' => 'bar',
170  'some' => [
171  'nested' => 'value'
172  ]
173  ]
174  ];
175  $testPluginSettings = [
176  'settings.' => [
177  'some.' => [
178  'nested' => 'valueOverride',
179  'new' => 'value'
180  ]
181  ]
182  ];
183  $testPluginSettingsConverted = [
184  'settings' => [
185  'some' => [
186  'nested' => 'valueOverride',
187  'new' => 'value'
188  ]
189  ]
190  ];
191  $testSetup = [
192  'module.' => [
193  'tx_someextensionname.' => $testExtensionSettings,
194  'tx_someextensionname_somepluginname.' => $testPluginSettings
195  ]
196  ];
197  $this->mockTypoScriptService->expects(self::exactly(2))->method('convertTypoScriptArrayToPlainArray')
198  ->withConsecutive([$testExtensionSettings], [$testPluginSettings])
199  ->willReturnOnConsecutiveCalls($testExtensionSettingsConverted, $testPluginSettingsConverted);
200  $this->backendConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($testSetup);
201  $expectedResult = [
202  'settings' => [
203  'foo' => 'bar',
204  'some' => [
205  'nested' => 'valueOverride',
206  'new' => 'value'
207  ]
208  ]
209  ];
210  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
211  self::assertEquals($expectedResult, $actualResult);
212  }
213 
218  {
219  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = null;
220  $expectedResult = [];
221  $actualResult = $this->backendConfigurationManager->_call('getControllerConfiguration', 'SomeExtensionName', 'SomePluginName');
222  self::assertEquals($expectedResult, $actualResult);
223  }
224 
229  {
230  $controllerConfiguration = [
231  'Controller1' => [
232  'actions' => [
233  'action1',
234  'action2'
235  ],
236  'nonCacheableActions' => [
237  'action1'
238  ]
239  ],
240  'Controller2' => [
241  'actions' => [
242  'action3',
243  'action4'
244  ]
245  ]
246  ];
247  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $controllerConfiguration;
248  $expectedResult = $controllerConfiguration;
249  $actualResult = $this->backendConfigurationManager->_call('getControllerConfiguration', 'SomeExtensionName', 'SomePluginName');
250  self::assertEquals($expectedResult, $actualResult);
251  }
252 
257  {
258  $storagePids = [1, 2, 3];
259  $recursive = 99;
260 
262  $beUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
263  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
264  ‪$GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
265 
266  $abstractConfigurationManager = $this->getAccessibleMock(
267  BackendConfigurationManager::class,
268  ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getControllerConfiguration'],
269  [],
270  '',
271  false
272  );
273  $queryGenerator = $this->createMock(QueryGenerator::class);
274  $queryGenerator->expects(self::any())
275  ->method('getTreeList')
276  ->will(self::onConsecutiveCalls('4', '', '5,6'));
277  GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
278 
279  $expectedResult = [4, 5, 6];
280  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePids, $recursive);
281  self::assertEquals($expectedResult, $actualResult);
282  }
283 
288  {
289  $storagePids = [1, 2, -3];
290  $recursive = 99;
291 
293  $beUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
294  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
295  ‪$GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
296 
297  $abstractConfigurationManager = $this->getAccessibleMock(
298  BackendConfigurationManager::class,
299  ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getControllerConfiguration', 'getQueryGenerator'],
300  [],
301  '',
302  false
303  );
304  $queryGenerator = $this->createMock(QueryGenerator::class);
305  $queryGenerator->expects(self::any())
306  ->method('getTreeList')
307  ->will(self::onConsecutiveCalls('4', '', '3,5,6'));
308  GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
309 
310  $expectedResult = [4, 3, 5, 6];
311  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePids, $recursive);
312  self::assertEquals($expectedResult, $actualResult);
313  }
314 
319  {
320  $storagePids = [1, 2, 3];
321 
322  $abstractConfigurationManager = $this->getAccessibleMock(
323  BackendConfigurationManager::class,
324  ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getControllerConfiguration'],
325  [],
326  '',
327  false
328  );
329 
330  $expectedResult = [1, 2, 3];
331  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePids);
332  self::assertEquals($expectedResult, $actualResult);
333  }
334 
339  {
340  $storagePids = [1, 2, 3];
341  $recursive = 0;
342 
343  $abstractConfigurationManager = $this->getAccessibleMock(
344  BackendConfigurationManager::class,
345  ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getControllerConfiguration'],
346  [],
347  '',
348  false
349  );
350 
351  $expectedResult = [1, 2, 3];
352  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePids, $recursive);
353  self::assertEquals($expectedResult, $actualResult);
354  }
355 }
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsPluginConfiguration
‪getPluginConfigurationReturnsPluginConfiguration()
Definition: BackendConfigurationManagerTest.php:124
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration
‪getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration()
Definition: BackendConfigurationManagerTest.php:155
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\setUp
‪setUp()
Definition: BackendConfigurationManagerTest.php:42
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest
Definition: BackendConfigurationManagerTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration
Definition: AbstractConfigurationManagerTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels
‪storagePidsAreNotExtendedIfRecursiveSearchIsConfiguredForZeroLevels()
Definition: BackendConfigurationManagerTest.php:336
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured
‪storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured()
Definition: BackendConfigurationManagerTest.php:316
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromGet
‪getCurrentPageIdReturnsPageIdFromGet()
Definition: BackendConfigurationManagerTest.php:59
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid
‪storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid()
Definition: BackendConfigurationManagerTest.php:285
‪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:37
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromPost
‪getCurrentPageIdReturnsPageIdFromPost()
Definition: BackendConfigurationManagerTest.php:70
‪TYPO3\CMS\Core\Database\QueryGenerator
Definition: QueryGenerator.php:32
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsExtensionConfiguration
‪getPluginConfigurationReturnsExtensionConfiguration()
Definition: BackendConfigurationManagerTest.php:93
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreExtendedIfRecursiveSearchIsConfigured
‪storagePidsAreExtendedIfRecursiveSearchIsConfigured()
Definition: BackendConfigurationManagerTest.php:254
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getControllerConfigurationReturnsConfigurationStoredInExtconf
‪getControllerConfigurationReturnsConfigurationStoredInExtconf()
Definition: BackendConfigurationManagerTest.php:226
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪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:33
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getControllerConfigurationReturnsEmptyArrayByDefault
‪getControllerConfigurationReturnsEmptyArrayByDefault()
Definition: BackendConfigurationManagerTest.php:215
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound
‪getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound()
Definition: BackendConfigurationManagerTest.php:82
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46