TYPO3 CMS  TYPO3_7-6
AbstractConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
26 
31 
35  protected $testTypoScriptSetup = [
36  'foo.' => [
37  'bar' => 'baz'
38  ],
39  'config.' => [
40  'tx_extbase.' => [
41  'settings.' => [
42  'setting1' => 'value1',
43  'setting2' => 'value2'
44  ],
45  'view.' => [
46  'viewSub.' => [
47  'key1' => 'value1',
48  'key2' => 'value2'
49  ]
50  ]
51  ]
52  ]
53  ];
54 
59  'foo' => [
60  'bar' => 'baz'
61  ],
62  'config' => [
63  'tx_extbase' => [
64  'settings' => [
65  'setting1' => 'value1',
66  'setting2' => 'value2'
67  ],
68  'view' => [
69  'viewSub' => [
70  'key1' => 'value1',
71  'key2' => 'value2'
72  ]
73  ]
74  ]
75  ]
76  ];
77 
82  'settings' => [
83  'setting1' => 'overriddenValue1',
84  'setting3' => 'additionalValue'
85  ],
86  'view' => [
87  'viewSub' => [
88  'key1' => 'overridden',
89  'key3' => 'new key'
90  ]
91  ],
92  'persistence' => [
93  'storagePid' => '123'
94  ]
95  ];
96 
101  'Controller1' => [
102  'actions' => ['action1', 'action2', 'action3']
103  ],
104  'Controller2' => [
105  'actions' => ['action4', 'action5', 'action6'],
106  'nonCacheableActions' => ['action4', 'action6']
107  ]
108  ];
109 
113  protected function setUp()
114  {
115  $this->abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::class, ['getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids']);
116  $this->mockTypoScriptService = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Service\TypoScriptService::class);
117  $this->abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
118  }
119 
124  {
125  $this->abstractConfigurationManager->_set('configurationCache', ['foo' => 'bar']);
126  $this->abstractConfigurationManager->setConfiguration([]);
127  $this->assertEquals([], $this->abstractConfigurationManager->_get('configurationCache'));
128  }
129 
134  {
135  $configuration = [
136  'extensionName' => 'SomeExtensionName',
137  'pluginName' => 'SomePluginName'
138  ];
139  $this->abstractConfigurationManager->setConfiguration($configuration);
140  $this->assertEquals('SomeExtensionName', $this->abstractConfigurationManager->_get('extensionName'));
141  $this->assertEquals('SomePluginName', $this->abstractConfigurationManager->_get('pluginName'));
142  }
143 
148  {
149  $configuration = [
150  'foo' => 'bar',
151  'settings.' => ['foo' => 'bar'],
152  'view.' => ['subkey.' => ['subsubkey' => 'subsubvalue']]
153  ];
154  $expectedResult = [
155  'foo' => 'bar',
156  'settings' => ['foo' => 'bar'],
157  'view' => ['subkey' => ['subsubkey' => 'subsubvalue']]
158  ];
159  $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($expectedResult));
160  $this->abstractConfigurationManager->setConfiguration($configuration);
161  $this->assertEquals($expectedResult, $this->abstractConfigurationManager->_get('configuration'));
162  }
163 
168  {
169  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
170  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
171  $this->abstractConfigurationManager->_set('configurationCache', ['currentextensionname_currentpluginname' => ['foo' => 'bar'], 'someotherextension_somepluginname' => ['baz' => 'shouldnotbereturned']]);
172  $expectedResult = ['foo' => 'bar'];
173  $actualResult = $this->abstractConfigurationManager->getConfiguration();
174  $this->assertEquals($expectedResult, $actualResult);
175  }
176 
181  {
182  $this->abstractConfigurationManager->_set('configurationCache', ['someextensionname_somepluginname' => ['foo' => 'bar'], 'someotherextension_somepluginname' => ['baz' => 'shouldnotbereturned']]);
183  $expectedResult = ['foo' => 'bar'];
184  $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
185  $this->assertEquals($expectedResult, $actualResult);
186  }
187 
192  {
193  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
194  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
195  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
196  $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->will($this->returnValue($this->testTypoScriptSetupConverted['config']['tx_extbase']));
197  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
198  $expectedResult = [
199  'settings' => [
200  'setting1' => 'overriddenValue1',
201  'setting2' => 'value2',
202  'setting3' => 'additionalValue'
203  ],
204  'view' => [
205  'viewSub' => [
206  'key1' => 'overridden',
207  'key2' => 'value2',
208  'key3' => 'new key'
209  ]
210  ],
211  'persistence' => [
212  'storagePid' => '123'
213  ],
214  'controllerConfiguration' => null
215  ];
216  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->with($expectedResult)->will($this->returnValue($expectedResult));
217  $actualResult = $this->abstractConfigurationManager->getConfiguration();
218  $this->assertEquals($expectedResult, $actualResult);
219  }
220 
225  {
226  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
227  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('SomeExtensionName', 'SomePluginName')->will($this->returnValue($this->testPluginConfiguration));
228  $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->will($this->returnValue($this->testTypoScriptSetupConverted['config']['tx_extbase']));
229  $expectedResult = [
230  'settings' => [
231  'setting1' => 'overriddenValue1',
232  'setting2' => 'value2',
233  'setting3' => 'additionalValue'
234  ],
235  'view' => [
236  'viewSub' => [
237  'key1' => 'overridden',
238  'key2' => 'value2',
239  'key3' => 'new key'
240  ]
241  ],
242  'persistence' => [
243  'storagePid' => '123'
244  ],
245  'controllerConfiguration' => null
246  ];
247  $this->abstractConfigurationManager->expects($this->never())->method('getContextSpecificFrameworkConfiguration');
248  $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
249  $this->assertEquals($expectedResult, $actualResult);
250  }
251 
256  {
257  $this->abstractConfigurationManager->expects($this->never())->method('getContextSpecificFrameworkConfiguration');
258  $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
259  }
260 
265  {
266  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
267  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with()->will($this->returnValue($this->testPluginConfiguration));
268  $contextSpecifixFrameworkConfiguration = [
269  'context' => [
270  'specific' => 'framwork',
271  'conf' => 'iguration'
272  ]
273  ];
274  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue($contextSpecifixFrameworkConfiguration));
275  $actualResult = $this->abstractConfigurationManager->getConfiguration();
276  $this->assertEquals($contextSpecifixFrameworkConfiguration, $actualResult);
277  }
278 
283  {
284  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
285  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
286  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
287  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
288  $contextSpecifixFrameworkConfiguration = [
289  'context' => [
290  'specific' => 'framwork',
291  'conf' => 'iguration'
292  ]
293  ];
294  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue($contextSpecifixFrameworkConfiguration));
295  $actualResult = $this->abstractConfigurationManager->getConfiguration('CurrentExtensionName', 'CurrentPluginName');
296  $this->assertEquals($contextSpecifixFrameworkConfiguration, $actualResult);
297  }
298 
303  {
304  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
305  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
306  $this->abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue(['foo' => 'bar']));
307  $this->abstractConfigurationManager->getConfiguration();
308  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
309  $expectedResult = ['currentextensionname_currentpluginname', 'someotherextensionname_someothercurrentpluginname'];
310  $actualResult = array_keys($this->abstractConfigurationManager->_get('configurationCache'));
311  $this->assertEquals($expectedResult, $actualResult);
312  }
313 
318  {
319  $pluginConfiguration = [
320  'persistence' => [
321  'storagePid' => 1,
322  'recursive' => 99
323  ]
324  ];
325  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
326  $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with('-1');
327  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
328  }
329 
334  {
335  $pluginConfiguration = [
336  'persistence' => [
337  'storagePid' => '1,25',
338  'recursive' => 99
339  ]
340  ];
341  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
342  $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with('-1,-25');
343  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
344  }
345 
352  public function switchableControllerActionsAreNotOverriddenIfPluginNameIsSpecified()
353  {
355  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids']);
356  $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
357  $abstractConfigurationManager->setConfiguration(['switchableControllerActions' => ['overriddenSwitchableControllerActions']]);
358  $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue([]));
359  $abstractConfigurationManager->expects($this->never())->method('overrideSwitchableControllerActions');
360  $abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
361  }
362 
366  public function switchableControllerActionsAreOverriddenIfSpecifiedPluginIsTheCurrentPlugin()
367  {
369  $configuration = ['extensionName' => 'CurrentExtensionName', 'pluginName' => 'CurrentPluginName', 'switchableControllerActions' => ['overriddenSwitchableControllerActions']];
370  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids']);
371  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
372  $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
373  $abstractConfigurationManager->setConfiguration($configuration);
374  $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue([]));
375  $abstractConfigurationManager->expects($this->once())->method('overrideSwitchableControllerActions');
376  $abstractConfigurationManager->getConfiguration('CurrentExtensionName', 'CurrentPluginName');
377  }
378 
382  public function switchableControllerActionsAreOverriddenIfPluginNameIsNotSpecified()
383  {
385  $configuration = ['switchableControllerActions' => ['overriddenSwitchableControllerActions']];
386  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids']);
387  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
388  $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
389  $abstractConfigurationManager->setConfiguration($configuration);
390  $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue([]));
391  $abstractConfigurationManager->expects($this->once())->method('overrideSwitchableControllerActions');
392  $abstractConfigurationManager->getConfiguration();
393  }
394 
399  {
400  $configuration = [
401  'extensionName' => 'CurrentExtensionName',
402  'pluginName' => 'CurrentPluginName',
403  'switchableControllerActions' => [
404  'Controller1' => ['action2', 'action1', 'action3']
405  ]
406  ];
407  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
408  $this->abstractConfigurationManager->setConfiguration($configuration);
409  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
410  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
411  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function ($a) {
412  return $a;
413  }));
414  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
415  $expectedResult = [
416  'Controller1' => [
417  'actions' => ['action2', 'action1', 'action3']
418  ]
419  ];
420  $actualResult = $mergedConfiguration['controllerConfiguration'];
421  $this->assertEquals($expectedResult, $actualResult);
422  }
423 
428  {
429  $configuration = [
430  'extensionName' => 'CurrentExtensionName',
431  'pluginName' => 'CurrentPluginName',
432  'switchableControllerActions' => [
433  'Controller1' => ['action2', 'action1', 'action3', 'newAction']
434  ]
435  ];
436  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
437  $this->abstractConfigurationManager->setConfiguration($configuration);
438  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
439  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
440  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function ($a) {
441  return $a;
442  }));
443  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
444  $expectedResult = [
445  'Controller1' => [
446  'actions' => ['action2', 'action1', 'action3', 'newAction']
447  ]
448  ];
449  $actualResult = $mergedConfiguration['controllerConfiguration'];
450  $this->assertEquals($expectedResult, $actualResult);
451  }
452 
457  {
458  $configuration = [
459  'extensionName' => 'CurrentExtensionName',
460  'pluginName' => 'CurrentPluginName',
461  'switchableControllerActions' => [
462  'NewController' => ['action1', 'action2']
463  ]
464  ];
465  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
466  $this->abstractConfigurationManager->setConfiguration($configuration);
467  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
468  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
469  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function ($a) {
470  return $a;
471  }));
472  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
473  $expectedResult = [];
474  $actualResult = $mergedConfiguration['controllerConfiguration'];
475  $this->assertEquals($expectedResult, $actualResult);
476  }
477 
482  {
483  $configuration = [
484  'extensionName' => 'CurrentExtensionName',
485  'pluginName' => 'CurrentPluginName',
486  'switchableControllerActions' => [
487  'Controller1' => ['newAction', 'action1'],
488  'Controller2' => ['newAction2', 'action4', 'action5']
489  ]
490  ];
491  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
492  $this->abstractConfigurationManager->setConfiguration($configuration);
493  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
494  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
495  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function ($a) {
496  return $a;
497  }));
498  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
499  $expectedResult = [
500  'Controller1' => [
501  'actions' => ['newAction', 'action1']
502  ],
503  'Controller2' => [
504  'actions' => ['newAction2', 'action4', 'action5'],
505  'nonCacheableActions' => ['action4']
506  ]
507  ];
508  $actualResult = $mergedConfiguration['controllerConfiguration'];
509  $this->assertEquals($expectedResult, $actualResult);
510  }
511 
516  {
517  $this->assertNull($this->abstractConfigurationManager->getContentObject());
518  }
519 
524  {
525  $mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
526  $this->abstractConfigurationManager->setContentObject($mockContentObject);
527  $this->assertSame($this->abstractConfigurationManager->getContentObject(), $mockContentObject);
528  }
529 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)