[TASK] Remove unneeded SingletonInstance resets in recent extbase tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Configuration / AbstractConfigurationManagerTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Extbase\Tests\Unit\Configuration;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\TypoScript\TypoScriptService;
20 use TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager;
21 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
22 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24
25 /**
26 * Test case
27 */
28 class AbstractConfigurationManagerTest extends UnitTestCase
29 {
30 /**
31 * @var AbstractConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
32 */
33 protected $abstractConfigurationManager;
34
35 /**
36 * @var TypoScriptService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
37 */
38 protected $mockTypoScriptService;
39
40 /**
41 * @var array
42 */
43 protected $testTypoScriptSetup = [
44 'foo.' => [
45 'bar' => 'baz'
46 ],
47 'config.' => [
48 'tx_extbase.' => [
49 'settings.' => [
50 'setting1' => 'value1',
51 'setting2' => 'value2'
52 ],
53 'view.' => [
54 'viewSub.' => [
55 'key1' => 'value1',
56 'key2' => 'value2'
57 ]
58 ]
59 ]
60 ]
61 ];
62
63 /**
64 * @var array
65 */
66 protected $testTypoScriptSetupConverted = [
67 'foo' => [
68 'bar' => 'baz'
69 ],
70 'config' => [
71 'tx_extbase' => [
72 'settings' => [
73 'setting1' => 'value1',
74 'setting2' => 'value2'
75 ],
76 'view' => [
77 'viewSub' => [
78 'key1' => 'value1',
79 'key2' => 'value2'
80 ]
81 ]
82 ]
83 ]
84 ];
85
86 /**
87 * @var array
88 */
89 protected $testPluginConfiguration = [
90 'settings' => [
91 'setting1' => 'overriddenValue1',
92 'setting3' => 'additionalValue'
93 ],
94 'view' => [
95 'viewSub' => [
96 'key1' => 'overridden',
97 'key3' => 'new key'
98 ]
99 ],
100 'persistence' => [
101 'storagePid' => '123'
102 ]
103 ];
104
105 /**
106 * @var array
107 */
108 protected $testSwitchableControllerActions = [
109 'MyExtension\\Controller\\Controller1' => [
110 'alias' => 'Controller1',
111 'actions' => ['action1', 'action2', 'action3']
112 ],
113 'MyExtension\\Controller\\Controller2' => [
114 'alias' => 'Controller2',
115 'actions' => ['action4', 'action5', 'action6'],
116 'nonCacheableActions' => ['action4', 'action6']
117 ]
118 ];
119
120 /**
121 * Sets up this testcase
122 */
123 protected function setUp(): void
124 {
125 parent::setUp();
126 $this->abstractConfigurationManager = $this->getAccessibleMock(
127 AbstractConfigurationManager::class,
128 [
129 'getContextSpecificFrameworkConfiguration',
130 'getTypoScriptSetup',
131 'getPluginConfiguration',
132 'getSwitchableControllerActions',
133 'getRecursiveStoragePids'
134 ],
135 [],
136 '',
137 false
138 );
139 $this->mockTypoScriptService = $this->getAccessibleMock(TypoScriptService::class);
140 $this->abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
141 }
142
143 /**
144 * @test
145 */
146 public function setConfigurationResetsConfigurationCache(): void
147 {
148 $this->abstractConfigurationManager->_set('configurationCache', ['foo' => 'bar']);
149 $this->abstractConfigurationManager->setConfiguration([]);
150 $this->assertEquals([], $this->abstractConfigurationManager->_get('configurationCache'));
151 }
152
153 /**
154 * @test
155 */
156 public function setConfigurationSetsExtensionAndPluginName(): void
157 {
158 $configuration = [
159 'extensionName' => 'SomeExtensionName',
160 'pluginName' => 'SomePluginName'
161 ];
162 $this->abstractConfigurationManager->setConfiguration($configuration);
163 $this->assertEquals('SomeExtensionName', $this->abstractConfigurationManager->_get('extensionName'));
164 $this->assertEquals('SomePluginName', $this->abstractConfigurationManager->_get('pluginName'));
165 }
166
167 /**
168 * @test
169 */
170 public function setConfigurationConvertsTypoScriptArrayToPlainArray(): void
171 {
172 $configuration = [
173 'foo' => 'bar',
174 'settings.' => ['foo' => 'bar'],
175 'view.' => ['subkey.' => ['subsubkey' => 'subsubvalue']]
176 ];
177 $expectedResult = [
178 'foo' => 'bar',
179 'settings' => ['foo' => 'bar'],
180 'view' => ['subkey' => ['subsubkey' => 'subsubvalue']]
181 ];
182 $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($expectedResult));
183 $this->abstractConfigurationManager->setConfiguration($configuration);
184 $this->assertEquals($expectedResult, $this->abstractConfigurationManager->_get('configuration'));
185 }
186
187 /**
188 * @test
189 */
190 public function getConfigurationReturnsCachedResultOfCurrentPlugin(): void
191 {
192 $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
193 $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
194 $this->abstractConfigurationManager->_set('configurationCache', [
195 'currentextensionname_currentpluginname' => ['foo' => 'bar'],
196 'someotherextension_somepluginname' => ['baz' => 'shouldnotbereturned']
197 ]);
198 $expectedResult = ['foo' => 'bar'];
199 $actualResult = $this->abstractConfigurationManager->getConfiguration();
200 $this->assertEquals($expectedResult, $actualResult);
201 }
202
203 /**
204 * @test
205 */
206 public function getConfigurationReturnsCachedResultForGivenExtension(): void
207 {
208 $this->abstractConfigurationManager->_set('configurationCache', [
209 'someextensionname_somepluginname' => ['foo' => 'bar'],
210 'someotherextension_somepluginname' => ['baz' => 'shouldnotbereturned']
211 ]);
212 $expectedResult = ['foo' => 'bar'];
213 $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
214 $this->assertEquals($expectedResult, $actualResult);
215 }
216
217 /**
218 * @test
219 */
220 public function getConfigurationRecursivelyMergesCurrentPluginConfigurationWithFrameworkConfiguration(): void
221 {
222 $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
223 $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
224 $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
225 $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->will($this->returnValue($this->testTypoScriptSetupConverted['config']['tx_extbase']));
226 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
227 'CurrentExtensionName',
228 'CurrentPluginName'
229 )->will($this->returnValue($this->testPluginConfiguration));
230 $expectedResult = [
231 'settings' => [
232 'setting1' => 'overriddenValue1',
233 'setting2' => 'value2',
234 'setting3' => 'additionalValue'
235 ],
236 'view' => [
237 'viewSub' => [
238 'key1' => 'overridden',
239 'key2' => 'value2',
240 'key3' => 'new key'
241 ]
242 ],
243 'persistence' => [
244 'storagePid' => '123'
245 ],
246 'controllerConfiguration' => []
247 ];
248 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->with($expectedResult)->willReturn($expectedResult);
249 $actualResult = $this->abstractConfigurationManager->getConfiguration();
250 $this->assertEquals($expectedResult, $actualResult);
251 }
252
253 /**
254 * @test
255 */
256 public function getConfigurationRecursivelyMergesPluginConfigurationOfSpecifiedPluginWithFrameworkConfiguration(
257 ): void {
258 $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
259 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
260 'SomeExtensionName',
261 'SomePluginName'
262 )->will($this->returnValue($this->testPluginConfiguration));
263 $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->will($this->returnValue($this->testTypoScriptSetupConverted['config']['tx_extbase']));
264 $expectedResult = [
265 'settings' => [
266 'setting1' => 'overriddenValue1',
267 'setting2' => 'value2',
268 'setting3' => 'additionalValue'
269 ],
270 'view' => [
271 'viewSub' => [
272 'key1' => 'overridden',
273 'key2' => 'value2',
274 'key3' => 'new key'
275 ]
276 ],
277 'persistence' => [
278 'storagePid' => '123'
279 ],
280 'controllerConfiguration' => []
281 ];
282 $this->abstractConfigurationManager->expects($this->never())->method('getContextSpecificFrameworkConfiguration');
283 $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
284 $this->assertEquals($expectedResult, $actualResult);
285 }
286
287 /**
288 * @test
289 */
290 public function getConfigurationDoesNotOverrideConfigurationWithContextSpecificFrameworkConfigurationIfDifferentPluginIsSpecified(
291 ): void {
292 $this->abstractConfigurationManager->expects($this->never())->method('getContextSpecificFrameworkConfiguration');
293 $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
294 }
295
296 /**
297 * @test
298 */
299 public function getConfigurationOverridesConfigurationWithContextSpecificFrameworkConfigurationIfNoPluginWasSpecified(
300 ): void {
301 $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
302 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with()->will($this->returnValue($this->testPluginConfiguration));
303 $contextSpecifixFrameworkConfiguration = [
304 'context' => [
305 'specific' => 'framwork',
306 'conf' => 'iguration'
307 ]
308 ];
309 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue($contextSpecifixFrameworkConfiguration));
310 $actualResult = $this->abstractConfigurationManager->getConfiguration();
311 $this->assertEquals($contextSpecifixFrameworkConfiguration, $actualResult);
312 }
313
314 /**
315 * @test
316 */
317 public function getConfigurationOverridesConfigurationWithContextSpecificFrameworkConfigurationIfSpecifiedPluginIsTheCurrentPlugin(
318 ): void {
319 $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
320 $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
321 $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
322 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
323 'CurrentExtensionName',
324 'CurrentPluginName'
325 )->will($this->returnValue($this->testPluginConfiguration));
326 $contextSpecifixFrameworkConfiguration = [
327 'context' => [
328 'specific' => 'framwork',
329 'conf' => 'iguration'
330 ]
331 ];
332 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue($contextSpecifixFrameworkConfiguration));
333 $actualResult = $this->abstractConfigurationManager->getConfiguration(
334 'CurrentExtensionName',
335 'CurrentPluginName'
336 );
337 $this->assertEquals($contextSpecifixFrameworkConfiguration, $actualResult);
338 }
339
340 /**
341 * @test
342 */
343 public function getConfigurationStoresResultInConfigurationCache(): void
344 {
345 $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
346 $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
347 $this->abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue(['foo' => 'bar']));
348 $this->abstractConfigurationManager->getConfiguration();
349 $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
350 $expectedResult = [
351 'currentextensionname_currentpluginname',
352 'someotherextensionname_someothercurrentpluginname'
353 ];
354 $actualResult = array_keys($this->abstractConfigurationManager->_get('configurationCache'));
355 $this->assertEquals($expectedResult, $actualResult);
356 }
357
358 /**
359 * @test
360 */
361 public function getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForSingleStoragePid(
362 ): void {
363 $pluginConfiguration = [
364 'persistence' => [
365 'storagePid' => 1,
366 'recursive' => 99
367 ]
368 ];
369 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
370 $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with([-1]);
371 $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
372 }
373
374 /**
375 * @test
376 */
377 public function getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForMultipleStoragePid(
378 ): void {
379 $pluginConfiguration = [
380 'persistence' => [
381 'storagePid' => '1,25',
382 'recursive' => 99
383 ]
384 ];
385 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
386 $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with([-1, -25]);
387 $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
388 }
389
390 /**
391 * switchableControllerActions *
392 */
393 /**
394 * @test
395 */
396 public function switchableControllerActionsAreNotOverriddenIfPluginNameIsSpecified(): void
397 {
398 /** @var AbstractConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface $abstractConfigurationManager */
399 $abstractConfigurationManager = $this->getAccessibleMock(
400 AbstractConfigurationManager::class,
401 [
402 'overrideSwitchableControllerActions',
403 'getContextSpecificFrameworkConfiguration',
404 'getTypoScriptSetup',
405 'getPluginConfiguration',
406 'getSwitchableControllerActions',
407 'getRecursiveStoragePids'
408 ],
409 [],
410 '',
411 false
412 );
413 $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
414 $abstractConfigurationManager->setConfiguration(['switchableControllerActions' => ['overriddenSwitchableControllerActions']]);
415 $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue([]));
416 $abstractConfigurationManager->expects($this->never())->method('overrideSwitchableControllerActions');
417 $abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
418 }
419
420 /**
421 * @test
422 */
423 public function switchableControllerActionsAreOverriddenIfSpecifiedPluginIsTheCurrentPlugin(): void
424 {
425 /** @var AbstractConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface $abstractConfigurationManager */
426 $configuration = [
427 'extensionName' => 'CurrentExtensionName',
428 'pluginName' => 'CurrentPluginName',
429 'switchableControllerActions' => ['overriddenSwitchableControllerActions']
430 ];
431 $abstractConfigurationManager = $this->getAccessibleMock(
432 AbstractConfigurationManager::class,
433 [
434 'overrideSwitchableControllerActions',
435 'getContextSpecificFrameworkConfiguration',
436 'getTypoScriptSetup',
437 'getPluginConfiguration',
438 'getSwitchableControllerActions',
439 'getRecursiveStoragePids'
440 ],
441 [],
442 '',
443 false
444 );
445 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
446 $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
447 $abstractConfigurationManager->setConfiguration($configuration);
448 $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue([]));
449 $abstractConfigurationManager->expects($this->once())->method('overrideSwitchableControllerActions');
450 $abstractConfigurationManager->getConfiguration('CurrentExtensionName', 'CurrentPluginName');
451 }
452
453 /**
454 * @test
455 */
456 public function switchableControllerActionsAreOverriddenIfPluginNameIsNotSpecified(): void
457 {
458 /** @var AbstractConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface $abstractConfigurationManager */
459 $configuration = ['switchableControllerActions' => ['overriddenSwitchableControllerActions']];
460 $abstractConfigurationManager = $this->getAccessibleMock(
461 AbstractConfigurationManager::class,
462 [
463 'overrideSwitchableControllerActions',
464 'getContextSpecificFrameworkConfiguration',
465 'getTypoScriptSetup',
466 'getPluginConfiguration',
467 'getSwitchableControllerActions',
468 'getRecursiveStoragePids'
469 ],
470 [],
471 '',
472 false
473 );
474 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
475 $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
476 $abstractConfigurationManager->setConfiguration($configuration);
477 $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue([]));
478 $abstractConfigurationManager->expects($this->once())->method('overrideSwitchableControllerActions');
479 $abstractConfigurationManager->getConfiguration();
480 }
481
482 /**
483 * @test
484 */
485 public function orderOfActionsCanBeOverriddenForCurrentPlugin(): void
486 {
487 $configuration = [
488 'extensionName' => 'CurrentExtensionName',
489 'pluginName' => 'CurrentPluginName',
490 'switchableControllerActions' => [
491 'Controller1' => ['action2', 'action1', 'action3']
492 ]
493 ];
494 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
495 $this->abstractConfigurationManager->setConfiguration($configuration);
496 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
497 'CurrentExtensionName',
498 'CurrentPluginName'
499 )->will($this->returnValue($this->testPluginConfiguration));
500 $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with(
501 'CurrentExtensionName',
502 'CurrentPluginName'
503 )->will($this->returnValue($this->testSwitchableControllerActions));
504 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallback(function (
505 $a
506 ) {
507 return $a;
508 }));
509 $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
510 $expectedResult = [
511 'MyExtension\\Controller\\Controller1' => [
512 'className' => 'MyExtension\\Controller\\Controller1',
513 'alias' => 'Controller1',
514 'actions' => ['action2', 'action1', 'action3']
515 ]
516 ];
517 $actualResult = $mergedConfiguration['controllerConfiguration'];
518 $this->assertEquals($expectedResult, $actualResult);
519 }
520
521 /**
522 * @test
523 */
524 public function controllerOfSwitchableControllerActionsCanBeAFullyQualifiedClassName(): void
525 {
526 $configuration = [
527 'extensionName' => 'CurrentExtensionName',
528 'pluginName' => 'CurrentPluginName',
529 'switchableControllerActions' => [
530 'MyExtension\\Controller\\Controller1' => ['action2', 'action1', 'action3'],
531 '\\MyExtension\\Controller\\Controller2' => ['newAction2', 'action4', 'action5']
532 ]
533 ];
534 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
535 $this->abstractConfigurationManager->setConfiguration($configuration);
536 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
537 'CurrentExtensionName',
538 'CurrentPluginName'
539 )->will($this->returnValue($this->testPluginConfiguration));
540 $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with(
541 'CurrentExtensionName',
542 'CurrentPluginName'
543 )->will($this->returnValue($this->testSwitchableControllerActions));
544 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallback(function (
545 $a
546 ) {
547 return $a;
548 }));
549 $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
550 $expectedResult = [
551 'MyExtension\\Controller\\Controller1' => [
552 'className' => 'MyExtension\\Controller\\Controller1',
553 'alias' => 'Controller1',
554 'actions' => ['action2', 'action1', 'action3']
555 ],
556 'MyExtension\\Controller\\Controller2' => [
557 'className' => 'MyExtension\\Controller\\Controller2',
558 'alias' => 'Controller2',
559 'actions' => ['newAction2', 'action4', 'action5'],
560 'nonCacheableActions' => ['action4']
561 ]
562 ];
563 $actualResult = $mergedConfiguration['controllerConfiguration'];
564 $this->assertEquals($expectedResult, $actualResult);
565 }
566
567 /**
568 * @test
569 */
570 public function newActionsCanBeAddedForCurrentPlugin(): void
571 {
572 $configuration = [
573 'extensionName' => 'CurrentExtensionName',
574 'pluginName' => 'CurrentPluginName',
575 'switchableControllerActions' => [
576 'Controller1' => ['action2', 'action1', 'action3', 'newAction']
577 ]
578 ];
579 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
580 $this->abstractConfigurationManager->setConfiguration($configuration);
581 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
582 'CurrentExtensionName',
583 'CurrentPluginName'
584 )->will($this->returnValue($this->testPluginConfiguration));
585 $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with(
586 'CurrentExtensionName',
587 'CurrentPluginName'
588 )->will($this->returnValue($this->testSwitchableControllerActions));
589 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallback(function (
590 $a
591 ) {
592 return $a;
593 }));
594 $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
595 $expectedResult = [
596 'MyExtension\\Controller\\Controller1' => [
597 'className' => 'MyExtension\\Controller\\Controller1',
598 'alias' => 'Controller1',
599 'actions' => ['action2', 'action1', 'action3', 'newAction']
600 ]
601 ];
602 $actualResult = $mergedConfiguration['controllerConfiguration'];
603 $this->assertEquals($expectedResult, $actualResult);
604 }
605
606 /**
607 * @test
608 */
609 public function controllersCanNotBeOverridden(): void
610 {
611 $configuration = [
612 'extensionName' => 'CurrentExtensionName',
613 'pluginName' => 'CurrentPluginName',
614 'switchableControllerActions' => [
615 'NewController' => ['action1', 'action2']
616 ]
617 ];
618 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
619 $this->abstractConfigurationManager->setConfiguration($configuration);
620 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
621 'CurrentExtensionName',
622 'CurrentPluginName'
623 )->will($this->returnValue($this->testPluginConfiguration));
624 $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with(
625 'CurrentExtensionName',
626 'CurrentPluginName'
627 )->will($this->returnValue($this->testSwitchableControllerActions));
628 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallback(function (
629 $a
630 ) {
631 return $a;
632 }));
633 $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
634 $expectedResult = [];
635 $actualResult = $mergedConfiguration['controllerConfiguration'];
636 $this->assertEquals($expectedResult, $actualResult);
637 }
638
639 /**
640 * @test
641 */
642 public function cachingOfActionsCanNotBeChanged(): void
643 {
644 $configuration = [
645 'extensionName' => 'CurrentExtensionName',
646 'pluginName' => 'CurrentPluginName',
647 'switchableControllerActions' => [
648 'Controller1' => ['newAction', 'action1'],
649 'Controller2' => ['newAction2', 'action4', 'action5']
650 ]
651 ];
652 $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
653 $this->abstractConfigurationManager->setConfiguration($configuration);
654 $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with(
655 'CurrentExtensionName',
656 'CurrentPluginName'
657 )->will($this->returnValue($this->testPluginConfiguration));
658 $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with(
659 'CurrentExtensionName',
660 'CurrentPluginName'
661 )->will($this->returnValue($this->testSwitchableControllerActions));
662 $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallback(function (
663 $a
664 ) {
665 return $a;
666 }));
667 $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
668 $expectedResult = [
669 'MyExtension\\Controller\\Controller1' => [
670 'className' => 'MyExtension\\Controller\\Controller1',
671 'alias' => 'Controller1',
672 'actions' => ['newAction', 'action1']
673 ],
674 'MyExtension\\Controller\\Controller2' => [
675 'className' => 'MyExtension\\Controller\\Controller2',
676 'alias' => 'Controller2',
677 'actions' => ['newAction2', 'action4', 'action5'],
678 'nonCacheableActions' => ['action4']
679 ]
680 ];
681 $actualResult = $mergedConfiguration['controllerConfiguration'];
682 $this->assertEquals($expectedResult, $actualResult);
683 }
684
685 /**
686 * @test
687 */
688 public function getContentObjectReturnsNullIfNoContentObjectHasBeenSet(): void
689 {
690 $this->assertNull($this->abstractConfigurationManager->getContentObject());
691 }
692
693 /**
694 * @test
695 */
696 public function getContentObjectTheCurrentContentObject(): void
697 {
698 /** @var ContentObjectRenderer|\PHPUnit_Framework_MockObject_MockObject $mockContentObject */
699 $mockContentObject = $this->createMock(ContentObjectRenderer::class);
700 $this->abstractConfigurationManager->setContentObject($mockContentObject);
701 $this->assertSame($this->abstractConfigurationManager->getContentObject(), $mockContentObject);
702 }
703 }