‪TYPO3CMS  11.5
BackendConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
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 
61  public function ‪getCurrentPageIdReturnsPageIdFromGet(): void
62  {
63  $_GET['id'] = 123;
64  $expectedResult = 123;
65  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
66  self::assertEquals($expectedResult, $actualResult);
67  }
68 
72  public function ‪getCurrentPageIdReturnsPageIdFromPost(): void
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->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->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 
260  $abstractConfigurationManager = $this->getAccessibleMock(
261  BackendConfigurationManager::class,
262  ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getControllerConfiguration'],
263  [],
264  '',
265  false
266  );
267 
268  $expectedResult = [1, 2, 3];
269  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePids);
270  self::assertEquals($expectedResult, $actualResult);
271  }
272 
277  {
278  $storagePids = [1, 2, 3];
279  $recursive = 0;
280 
281  $abstractConfigurationManager = $this->getAccessibleMock(
282  BackendConfigurationManager::class,
283  ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getControllerConfiguration'],
284  [],
285  '',
286  false
287  );
288 
289  $expectedResult = [1, 2, 3];
290  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePids, $recursive);
291  self::assertEquals($expectedResult, $actualResult);
292  }
293 }
‪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:274
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:37
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured
‪storagePidsAreNotExtendedIfRecursiveSearchIsNotConfigured()
Definition: BackendConfigurationManagerTest.php:254
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromGet
‪getCurrentPageIdReturnsPageIdFromGet()
Definition: BackendConfigurationManagerTest.php:59
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getCurrentPageIdReturnsPageIdFromPost
‪getCurrentPageIdReturnsPageIdFromPost()
Definition: BackendConfigurationManagerTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getPluginConfigurationReturnsExtensionConfiguration
‪getPluginConfigurationReturnsExtensionConfiguration()
Definition: BackendConfigurationManagerTest.php:93
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\getControllerConfigurationReturnsConfigurationStoredInExtconf
‪getControllerConfigurationReturnsConfigurationStoredInExtconf()
Definition: BackendConfigurationManagerTest.php:226
‪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\$backendConfigurationManager
‪BackendConfigurationManager MockObject AccessibleObjectInterface $backendConfigurationManager
Definition: BackendConfigurationManagerTest.php:33
‪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:25
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\BackendConfigurationManagerTest\$mockTypoScriptService
‪TypoScriptService MockObject AccessibleObjectInterface $mockTypoScriptService
Definition: BackendConfigurationManagerTest.php:37