‪TYPO3CMS  10.4
AbstractConfigurationManagerTest.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 
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪AbstractConfigurationManagerTest extends UnitTestCase
30 {
35 
39  protected ‪$mockTypoScriptService;
40 
44  protected ‪$testTypoScriptSetup = [
45  'foo.' => [
46  'bar' => 'baz'
47  ],
48  'config.' => [
49  'tx_extbase.' => [
50  'settings.' => [
51  'setting1' => 'value1',
52  'setting2' => 'value2'
53  ],
54  'view.' => [
55  'viewSub.' => [
56  'key1' => 'value1',
57  'key2' => 'value2'
58  ]
59  ]
60  ]
61  ]
62  ];
63 
68  'foo' => [
69  'bar' => 'baz'
70  ],
71  'config' => [
72  'tx_extbase' => [
73  'settings' => [
74  'setting1' => 'value1',
75  'setting2' => 'value2'
76  ],
77  'view' => [
78  'viewSub' => [
79  'key1' => 'value1',
80  'key2' => 'value2'
81  ]
82  ]
83  ]
84  ]
85  ];
86 
90  protected ‪$testPluginConfiguration = [
91  'settings' => [
92  'setting1' => 'overriddenValue1',
93  'setting3' => 'additionalValue'
94  ],
95  'view' => [
96  'viewSub' => [
97  'key1' => 'overridden',
98  'key3' => 'new key'
99  ]
100  ],
101  'persistence' => [
102  'storagePid' => '123'
103  ]
104  ];
105 
109  protected function ‪setUp(): void
110  {
111  parent::setUp();
112  $this->abstractConfigurationManager = $this->getAccessibleMock(
113  AbstractConfigurationManager::class,
114  [
115  'getContextSpecificFrameworkConfiguration',
116  'getTypoScriptSetup',
117  'getPluginConfiguration',
118  'getControllerConfiguration',
119  'getRecursiveStoragePids'
120  ],
121  [],
122  '',
123  false
124  );
125  $this->mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
126  $this->abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
127  }
128 
132  public function ‪setConfigurationResetsConfigurationCache(): void
133  {
134  $this->abstractConfigurationManager->_set('configurationCache', ['foo' => 'bar']);
135  $this->abstractConfigurationManager->setConfiguration([]);
136  self::assertEquals([], $this->abstractConfigurationManager->_get('configurationCache'));
137  }
138 
142  public function ‪setConfigurationSetsExtensionAndPluginName(): void
143  {
144  $configuration = [
145  'extensionName' => 'SomeExtensionName',
146  'pluginName' => 'SomePluginName'
147  ];
148  $this->abstractConfigurationManager->setConfiguration($configuration);
149  self::assertEquals('SomeExtensionName', $this->abstractConfigurationManager->_get('extensionName'));
150  self::assertEquals('SomePluginName', $this->abstractConfigurationManager->_get('pluginName'));
151  }
152 
157  {
158  $configuration = [
159  'foo' => 'bar',
160  'settings.' => ['foo' => 'bar'],
161  'view.' => ['subkey.' => ['subsubkey' => 'subsubvalue']]
162  ];
163  $expectedResult = [
164  'foo' => 'bar',
165  'settings' => ['foo' => 'bar'],
166  'view' => ['subkey' => ['subsubkey' => 'subsubvalue']]
167  ];
168  $this->mockTypoScriptService->expects(self::atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($expectedResult);
169  $this->abstractConfigurationManager->setConfiguration($configuration);
170  self::assertEquals($expectedResult, $this->abstractConfigurationManager->_get('configuration'));
171  }
172 
177  {
178  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
179  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
180  $this->abstractConfigurationManager->_set('configurationCache', [
181  'currentextensionname_currentpluginname' => ['foo' => 'bar'],
182  'someotherextension_somepluginname' => ['baz' => 'shouldnotbereturned']
183  ]);
184  $expectedResult = ['foo' => 'bar'];
185  $actualResult = $this->abstractConfigurationManager->getConfiguration();
186  self::assertEquals($expectedResult, $actualResult);
187  }
188 
193  {
194  $this->abstractConfigurationManager->_set('configurationCache', [
195  'someextensionname_somepluginname' => ['foo' => 'bar'],
196  'someotherextension_somepluginname' => ['baz' => 'shouldnotbereturned']
197  ]);
198  $expectedResult = ['foo' => 'bar'];
199  $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
200  self::assertEquals($expectedResult, $actualResult);
201  }
202 
207  {
208  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
209  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
210  $this->abstractConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($this->testTypoScriptSetup);
211  $this->mockTypoScriptService->expects(self::atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->willReturn($this->testTypoScriptSetupConverted['config']['tx_extbase']);
212  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
213  'CurrentExtensionName',
214  'CurrentPluginName'
215  )->willReturn($this->testPluginConfiguration);
216  $expectedResult = [
217  'settings' => [
218  'setting1' => 'overriddenValue1',
219  'setting2' => 'value2',
220  'setting3' => 'additionalValue'
221  ],
222  'view' => [
223  'viewSub' => [
224  'key1' => 'overridden',
225  'key2' => 'value2',
226  'key3' => 'new key'
227  ]
228  ],
229  'persistence' => [
230  'storagePid' => '123'
231  ],
232  'controllerConfiguration' => []
233  ];
234  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->with($expectedResult)->willReturn($expectedResult);
235  $actualResult = $this->abstractConfigurationManager->getConfiguration();
236  self::assertEquals($expectedResult, $actualResult);
237  }
238 
243  ): void {
244  $this->abstractConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($this->testTypoScriptSetup);
245  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
246  'SomeExtensionName',
247  'SomePluginName'
248  )->willReturn($this->testPluginConfiguration);
249  $this->mockTypoScriptService->expects(self::atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->willReturn($this->testTypoScriptSetupConverted['config']['tx_extbase']);
250  $expectedResult = [
251  'settings' => [
252  'setting1' => 'overriddenValue1',
253  'setting2' => 'value2',
254  'setting3' => 'additionalValue'
255  ],
256  'view' => [
257  'viewSub' => [
258  'key1' => 'overridden',
259  'key2' => 'value2',
260  'key3' => 'new key'
261  ]
262  ],
263  'persistence' => [
264  'storagePid' => '123'
265  ],
266  'controllerConfiguration' => []
267  ];
268  $this->abstractConfigurationManager->expects(self::never())->method('getContextSpecificFrameworkConfiguration');
269  $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
270  self::assertEquals($expectedResult, $actualResult);
271  }
272 
277  ): void {
278  $this->abstractConfigurationManager->expects(self::never())->method('getContextSpecificFrameworkConfiguration');
279  $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
280  }
281 
286  ): void {
287  $this->abstractConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($this->testTypoScriptSetup);
288  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with()->willReturn($this->testPluginConfiguration);
289  $contextSpecificFrameworkConfiguration = [
290  'context' => [
291  'specific' => 'framework',
292  'conf' => 'iguration'
293  ]
294  ];
295  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturn($contextSpecificFrameworkConfiguration);
296  $actualResult = $this->abstractConfigurationManager->getConfiguration();
297  self::assertEquals($contextSpecificFrameworkConfiguration, $actualResult);
298  }
299 
304  ): void {
305  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
306  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
307  $this->abstractConfigurationManager->expects(self::once())->method('getTypoScriptSetup')->willReturn($this->testTypoScriptSetup);
308  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
309  'CurrentExtensionName',
310  'CurrentPluginName'
311  )->willReturn($this->testPluginConfiguration);
312  $contextSpecificFrameworkConfiguration = [
313  'context' => [
314  'specific' => 'framework',
315  'conf' => 'iguration'
316  ]
317  ];
318  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturn($contextSpecificFrameworkConfiguration);
319  $actualResult = $this->abstractConfigurationManager->getConfiguration(
320  'CurrentExtensionName',
321  'CurrentPluginName'
322  );
323  self::assertEquals($contextSpecificFrameworkConfiguration, $actualResult);
324  }
325 
330  {
331  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
332  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
333  $this->abstractConfigurationManager->expects(self::any())->method('getPluginConfiguration')->willReturn(['foo' => 'bar']);
334  $this->abstractConfigurationManager->getConfiguration();
335  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
336  $expectedResult = [
337  'currentextensionname_currentpluginname',
338  'someotherextensionname_someothercurrentpluginname'
339  ];
340  $actualResult = array_keys($this->abstractConfigurationManager->_get('configurationCache'));
341  self::assertEquals($expectedResult, $actualResult);
342  }
343 
348  ): void {
349  $pluginConfiguration = [
350  'persistence' => [
351  'storagePid' => 1,
352  'recursive' => 99
353  ]
354  ];
355  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->willReturn($pluginConfiguration);
356  $this->abstractConfigurationManager->expects(self::once())->method('getRecursiveStoragePids')->with([-1]);
357  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
358  }
359 
364  ): void {
365  $pluginConfiguration = [
366  'persistence' => [
367  'storagePid' => '1,25',
368  'recursive' => 99
369  ]
370  ];
371  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->willReturn($pluginConfiguration);
372  $this->abstractConfigurationManager->expects(self::once())->method('getRecursiveStoragePids')->with([-1, -25]);
373  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
374  }
375 
380  {
381  self::assertNull($this->abstractConfigurationManager->getContentObject());
382  }
383 
387  public function ‪getContentObjectTheCurrentContentObject(): void
388  {
390  $mockContentObject = $this->createMock(ContentObjectRenderer::class);
391  $this->abstractConfigurationManager->setContentObject($mockContentObject);
392  self::assertSame($this->abstractConfigurationManager->getContentObject(), $mockContentObject);
393  }
394 }
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForMultipleStoragePid
‪getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForMultipleStoragePid()
Definition: AbstractConfigurationManagerTest.php:358
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest
Definition: AbstractConfigurationManagerTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration
Definition: AbstractConfigurationManagerTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForSingleStoragePid
‪getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForSingleStoragePid()
Definition: AbstractConfigurationManagerTest.php:342
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationStoresResultInConfigurationCache
‪getConfigurationStoresResultInConfigurationCache()
Definition: AbstractConfigurationManagerTest.php:324
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationOverridesConfigurationWithContextSpecificFrameworkConfigurationIfSpecifiedPluginIsTheCurrentPlugin
‪getConfigurationOverridesConfigurationWithContextSpecificFrameworkConfigurationIfSpecifiedPluginIsTheCurrentPlugin()
Definition: AbstractConfigurationManagerTest.php:298
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getContentObjectReturnsNullIfNoContentObjectHasBeenSet
‪getContentObjectReturnsNullIfNoContentObjectHasBeenSet()
Definition: AbstractConfigurationManagerTest.php:374
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getContentObjectTheCurrentContentObject
‪getContentObjectTheCurrentContentObject()
Definition: AbstractConfigurationManagerTest.php:382
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\$mockTypoScriptService
‪TypoScriptService PHPUnit Framework MockObject MockObject AccessibleObjectInterface $mockTypoScriptService
Definition: AbstractConfigurationManagerTest.php:37
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\$testPluginConfiguration
‪array $testPluginConfiguration
Definition: AbstractConfigurationManagerTest.php:85
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationOverridesConfigurationWithContextSpecificFrameworkConfigurationIfNoPluginWasSpecified
‪getConfigurationOverridesConfigurationWithContextSpecificFrameworkConfigurationIfNoPluginWasSpecified()
Definition: AbstractConfigurationManagerTest.php:280
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:34
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\setConfigurationConvertsTypoScriptArrayToPlainArray
‪setConfigurationConvertsTypoScriptArrayToPlainArray()
Definition: AbstractConfigurationManagerTest.php:151
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\setUp
‪setUp()
Definition: AbstractConfigurationManagerTest.php:104
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationReturnsCachedResultOfCurrentPlugin
‪getConfigurationReturnsCachedResultOfCurrentPlugin()
Definition: AbstractConfigurationManagerTest.php:171
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\setConfigurationSetsExtensionAndPluginName
‪setConfigurationSetsExtensionAndPluginName()
Definition: AbstractConfigurationManagerTest.php:137
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\setConfigurationResetsConfigurationCache
‪setConfigurationResetsConfigurationCache()
Definition: AbstractConfigurationManagerTest.php:127
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\$abstractConfigurationManager
‪AbstractConfigurationManager PHPUnit Framework MockObject MockObject AccessibleObjectInterface $abstractConfigurationManager
Definition: AbstractConfigurationManagerTest.php:33
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationDoesNotOverrideConfigurationWithContextSpecificFrameworkConfigurationIfDifferentPluginIsSpecified
‪getConfigurationDoesNotOverrideConfigurationWithContextSpecificFrameworkConfigurationIfDifferentPluginIsSpecified()
Definition: AbstractConfigurationManagerTest.php:271
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\$testTypoScriptSetupConverted
‪array $testTypoScriptSetupConverted
Definition: AbstractConfigurationManagerTest.php:63
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationReturnsCachedResultForGivenExtension
‪getConfigurationReturnsCachedResultForGivenExtension()
Definition: AbstractConfigurationManagerTest.php:187
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationRecursivelyMergesCurrentPluginConfigurationWithFrameworkConfiguration
‪getConfigurationRecursivelyMergesCurrentPluginConfigurationWithFrameworkConfiguration()
Definition: AbstractConfigurationManagerTest.php:201
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\$testTypoScriptSetup
‪array $testTypoScriptSetup
Definition: AbstractConfigurationManagerTest.php:41
‪TYPO3\CMS\Extbase\Tests\Unit\Configuration\AbstractConfigurationManagerTest\getConfigurationRecursivelyMergesPluginConfigurationOfSpecifiedPluginWithFrameworkConfiguration
‪getConfigurationRecursivelyMergesPluginConfigurationOfSpecifiedPluginWithFrameworkConfiguration()
Definition: AbstractConfigurationManagerTest.php:237