‪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 
20 use PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 class ‪AbstractConfigurationManagerTest extends UnitTestCase
27 {
32 
36  protected ‪$mockTypoScriptService;
37 
41  protected ‪$testPluginConfiguration = [
42  'settings' => [
43  'setting1' => 'overriddenValue1',
44  'setting3' => 'additionalValue'
45  ],
46  'view' => [
47  'viewSub' => [
48  'key1' => 'overridden',
49  'key3' => 'new key'
50  ]
51  ],
52  'persistence' => [
53  'storagePid' => '123'
54  ]
55  ];
56 
61  'MyExtension\\Controller\\Controller1' => [
62  'alias' => 'Controller1',
63  'actions' => ['action1', 'action2', 'action3']
64  ],
65  'MyExtension\\Controller\\Controller2' => [
66  'alias' => 'Controller2',
67  'actions' => ['action4', 'action5', 'action6'],
68  'nonCacheableActions' => ['action4', 'action6']
69  ]
70  ];
71 
75  protected function ‪setUp(): void
76  {
77  parent::setUp();
78  $this->abstractConfigurationManager = $this->getAccessibleMock(
79  AbstractConfigurationManager::class,
80  [
81  'getContextSpecificFrameworkConfiguration',
82  'getTypoScriptSetup',
83  'getPluginConfiguration',
84  'getControllerConfiguration',
85  'getRecursiveStoragePids'
86  ],
87  [],
88  '',
89  false
90  );
91  $this->mockTypoScriptService = $this->getAccessibleMock(TypoScriptService::class);
92  $this->abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
93  }
94 
99  {
100  $configuration = [
101  'extensionName' => 'CurrentExtensionName',
102  'pluginName' => 'CurrentPluginName',
103  'switchableControllerActions' => [
104  'Controller1' => ['action2', 'action1', 'action3']
105  ]
106  ];
107  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
108  $this->abstractConfigurationManager->setConfiguration($configuration);
109  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
110  'CurrentExtensionName',
111  'CurrentPluginName'
112  )->willReturn($this->testPluginConfiguration);
113  $this->abstractConfigurationManager->expects(self::once())->method('getControllerConfiguration')->with(
114  'CurrentExtensionName',
115  'CurrentPluginName'
116  )->willReturn($this->testSwitchableControllerActions);
117  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturnCallback(function (
118  $a
119  ) {
120  return $a;
121  });
122  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
123  $expectedResult = [
124  'MyExtension\\Controller\\Controller1' => [
125  'className' => 'MyExtension\\Controller\\Controller1',
126  'alias' => 'Controller1',
127  'actions' => ['action2', 'action1', 'action3']
128  ]
129  ];
130  $actualResult = $mergedConfiguration['controllerConfiguration'];
131  self::assertEquals($expectedResult, $actualResult);
132  }
133 
138  {
139  $configuration = [
140  'extensionName' => 'CurrentExtensionName',
141  'pluginName' => 'CurrentPluginName',
142  'switchableControllerActions' => [
143  'MyExtension\\Controller\\Controller1' => ['action2', 'action1', 'action3'],
144  '\\MyExtension\\Controller\\Controller2' => ['newAction2', 'action4', 'action5']
145  ]
146  ];
147  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
148  $this->abstractConfigurationManager->setConfiguration($configuration);
149  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
150  'CurrentExtensionName',
151  'CurrentPluginName'
152  )->willReturn($this->testPluginConfiguration);
153  $this->abstractConfigurationManager->expects(self::once())->method('getControllerConfiguration')->with(
154  'CurrentExtensionName',
155  'CurrentPluginName'
156  )->willReturn($this->testSwitchableControllerActions);
157  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturnCallback(function (
158  $a
159  ) {
160  return $a;
161  });
162  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
163  $expectedResult = [
164  'MyExtension\\Controller\\Controller1' => [
165  'className' => 'MyExtension\\Controller\\Controller1',
166  'alias' => 'Controller1',
167  'actions' => ['action2', 'action1', 'action3']
168  ],
169  'MyExtension\\Controller\\Controller2' => [
170  'className' => 'MyExtension\\Controller\\Controller2',
171  'alias' => 'Controller2',
172  'actions' => ['newAction2', 'action4', 'action5'],
173  'nonCacheableActions' => ['action4']
174  ]
175  ];
176  $actualResult = $mergedConfiguration['controllerConfiguration'];
177  self::assertEquals($expectedResult, $actualResult);
178  }
179 
183  public function ‪newActionsCanBeAddedForCurrentPlugin(): void
184  {
185  $configuration = [
186  'extensionName' => 'CurrentExtensionName',
187  'pluginName' => 'CurrentPluginName',
188  'switchableControllerActions' => [
189  'Controller1' => ['action2', 'action1', 'action3', 'newAction']
190  ]
191  ];
192  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
193  $this->abstractConfigurationManager->setConfiguration($configuration);
194  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
195  'CurrentExtensionName',
196  'CurrentPluginName'
197  )->willReturn($this->testPluginConfiguration);
198  $this->abstractConfigurationManager->expects(self::once())->method('getControllerConfiguration')->with(
199  'CurrentExtensionName',
200  'CurrentPluginName'
201  )->willReturn($this->testSwitchableControllerActions);
202  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturnCallback(function (
203  $a
204  ) {
205  return $a;
206  });
207  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
208  $expectedResult = [
209  'MyExtension\\Controller\\Controller1' => [
210  'className' => 'MyExtension\\Controller\\Controller1',
211  'alias' => 'Controller1',
212  'actions' => ['action2', 'action1', 'action3', 'newAction']
213  ]
214  ];
215  $actualResult = $mergedConfiguration['controllerConfiguration'];
216  self::assertEquals($expectedResult, $actualResult);
217  }
218 
222  public function ‪controllersCanNotBeOverridden(): void
223  {
224  $configuration = [
225  'extensionName' => 'CurrentExtensionName',
226  'pluginName' => 'CurrentPluginName',
227  'switchableControllerActions' => [
228  'NewController' => ['action1', 'action2']
229  ]
230  ];
231  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
232  $this->abstractConfigurationManager->setConfiguration($configuration);
233  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
234  'CurrentExtensionName',
235  'CurrentPluginName'
236  )->willReturn($this->testPluginConfiguration);
237  $this->abstractConfigurationManager->expects(self::once())->method('getControllerConfiguration')->with(
238  'CurrentExtensionName',
239  'CurrentPluginName'
240  )->willReturn($this->testSwitchableControllerActions);
241  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturnCallback(function (
242  $a
243  ) {
244  return $a;
245  });
246  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
247  $expectedResult = [];
248  $actualResult = $mergedConfiguration['controllerConfiguration'];
249  self::assertEquals($expectedResult, $actualResult);
250  }
251 
255  public function ‪cachingOfActionsCanNotBeChanged(): void
256  {
257  $configuration = [
258  'extensionName' => 'CurrentExtensionName',
259  'pluginName' => 'CurrentPluginName',
260  'switchableControllerActions' => [
261  'Controller1' => ['newAction', 'action1'],
262  'Controller2' => ['newAction2', 'action4', 'action5']
263  ]
264  ];
265  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
266  $this->abstractConfigurationManager->setConfiguration($configuration);
267  $this->abstractConfigurationManager->expects(self::once())->method('getPluginConfiguration')->with(
268  'CurrentExtensionName',
269  'CurrentPluginName'
270  )->willReturn($this->testPluginConfiguration);
271  $this->abstractConfigurationManager->expects(self::once())->method('getControllerConfiguration')->with(
272  'CurrentExtensionName',
273  'CurrentPluginName'
274  )->willReturn($this->testSwitchableControllerActions);
275  $this->abstractConfigurationManager->expects(self::once())->method('getContextSpecificFrameworkConfiguration')->willReturnCallback(function (
276  $a
277  ) {
278  return $a;
279  });
280  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
281  $expectedResult = [
282  'MyExtension\\Controller\\Controller1' => [
283  'className' => 'MyExtension\\Controller\\Controller1',
284  'alias' => 'Controller1',
285  'actions' => ['newAction', 'action1']
286  ],
287  'MyExtension\\Controller\\Controller2' => [
288  'className' => 'MyExtension\\Controller\\Controller2',
289  'alias' => 'Controller2',
290  'actions' => ['newAction2', 'action4', 'action5'],
291  'nonCacheableActions' => ['action4']
292  ]
293  ];
294  $actualResult = $mergedConfiguration['controllerConfiguration'];
295  self::assertEquals($expectedResult, $actualResult);
296  }
297 
302  {
304  ‪$abstractConfigurationManager = $this->getAccessibleMock(
305  AbstractConfigurationManager::class,
306  [
307  'overrideControllerConfigurationWithSwitchableControllerActions',
308  'getContextSpecificFrameworkConfiguration',
309  'getTypoScriptSetup',
310  'getPluginConfiguration',
311  'getControllerConfiguration',
312  'getRecursiveStoragePids'
313  ],
314  [],
315  '',
316  false
317  );
318  ‪$abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
319  ‪$abstractConfigurationManager->‪setConfiguration(['switchableControllerActions' => ['overriddenSwitchableControllerActions']]);
320  ‪$abstractConfigurationManager->expects(self::any())->method('getPluginConfiguration')->willReturn([]);
321  ‪$abstractConfigurationManager->expects(self::never())->method('overrideControllerConfigurationWithSwitchableControllerActions');
322  ‪$abstractConfigurationManager->‪getConfiguration('SomeExtensionName', 'SomePluginName');
323  }
324 
329  {
331  $configuration = [
332  'extensionName' => 'CurrentExtensionName',
333  'pluginName' => 'CurrentPluginName',
334  'switchableControllerActions' => ['overriddenSwitchableControllerActions']
335  ];
336  ‪$abstractConfigurationManager = $this->getAccessibleMock(
337  AbstractConfigurationManager::class,
338  [
339  'overrideControllerConfigurationWithSwitchableControllerActions',
340  'getContextSpecificFrameworkConfiguration',
341  'getTypoScriptSetup',
342  'getPluginConfiguration',
343  'getControllerConfiguration',
344  'getRecursiveStoragePids'
345  ],
346  [],
347  '',
348  false
349  );
350  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
351  ‪$abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
353  ‪$abstractConfigurationManager->expects(self::any())->method('getPluginConfiguration')->willReturn([]);
354  ‪$abstractConfigurationManager->expects(self::once())->method('overrideControllerConfigurationWithSwitchableControllerActions');
355  ‪$abstractConfigurationManager->‪getConfiguration('CurrentExtensionName', 'CurrentPluginName');
356  }
357 
362  {
364  $configuration = ['switchableControllerActions' => ['overriddenSwitchableControllerActions']];
365  ‪$abstractConfigurationManager = $this->getAccessibleMock(
366  AbstractConfigurationManager::class,
367  [
368  'overrideControllerConfigurationWithSwitchableControllerActions',
369  'getContextSpecificFrameworkConfiguration',
370  'getTypoScriptSetup',
371  'getPluginConfiguration',
372  'getControllerConfiguration',
373  'getRecursiveStoragePids'
374  ],
375  [],
376  '',
377  false
378  );
379  $this->mockTypoScriptService->expects(self::any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->willReturn($configuration);
380  ‪$abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
382  ‪$abstractConfigurationManager->expects(self::any())->method('getPluginConfiguration')->willReturn([]);
383  ‪$abstractConfigurationManager->expects(self::once())->method('overrideControllerConfigurationWithSwitchableControllerActions');
385  }
386 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\$testSwitchableControllerActions
‪array $testSwitchableControllerActions
Definition: AbstractConfigurationManagerTest.php:56
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\newActionsCanBeAddedForCurrentPlugin
‪newActionsCanBeAddedForCurrentPlugin()
Definition: AbstractConfigurationManagerTest.php:179
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\setUp
‪setUp()
Definition: AbstractConfigurationManagerTest.php:71
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\controllerOfSwitchableControllerActionsCanBeAFullyQualifiedClassName
‪controllerOfSwitchableControllerActionsCanBeAFullyQualifiedClassName()
Definition: AbstractConfigurationManagerTest.php:133
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\controllersCanNotBeOverridden
‪controllersCanNotBeOverridden()
Definition: AbstractConfigurationManagerTest.php:218
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:34
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getConfiguration
‪array getConfiguration(?string $extensionName=null, ?string $pluginName=null)
Definition: AbstractConfigurationManager.php:136
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\$testPluginConfiguration
‪array $testPluginConfiguration
Definition: AbstractConfigurationManagerTest.php:38
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\$mockTypoScriptService
‪TypoScriptService MockObject AccessibleObjectInterface $mockTypoScriptService
Definition: AbstractConfigurationManagerTest.php:34
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\switchableControllerActionsAreOverriddenIfSpecifiedPluginIsTheCurrentPlugin
‪switchableControllerActionsAreOverriddenIfSpecifiedPluginIsTheCurrentPlugin()
Definition: AbstractConfigurationManagerTest.php:324
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration
Definition: AbstractConfigurationManagerTest.php:18
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\cachingOfActionsCanNotBeChanged
‪cachingOfActionsCanNotBeChanged()
Definition: AbstractConfigurationManagerTest.php:251
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\orderOfActionsCanBeOverriddenForCurrentPlugin
‪orderOfActionsCanBeOverriddenForCurrentPlugin()
Definition: AbstractConfigurationManagerTest.php:94
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\$abstractConfigurationManager
‪AbstractConfigurationManager MockObject AccessibleObjectInterface $abstractConfigurationManager
Definition: AbstractConfigurationManagerTest.php:30
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\switchableControllerActionsAreNotOverriddenIfPluginNameIsSpecified
‪switchableControllerActionsAreNotOverriddenIfPluginNameIsSpecified()
Definition: AbstractConfigurationManagerTest.php:297
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest\switchableControllerActionsAreOverriddenIfPluginNameIsNotSpecified
‪switchableControllerActionsAreOverriddenIfPluginNameIsNotSpecified()
Definition: AbstractConfigurationManagerTest.php:357
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\setConfiguration
‪setConfiguration(array $configuration=[])
Definition: AbstractConfigurationManager.php:117
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Configuration\AbstractConfigurationManagerTest
Definition: AbstractConfigurationManagerTest.php:27