TYPO3 CMS  TYPO3_6-2
AbstractConfigurationManagerTest.php
Go to the documentation of this file.
1 <?php
3 
21 
26 
31 
35  protected $testTypoScriptSetup = array(
36  'foo.' => array(
37  'bar' => 'baz'
38  ),
39  'config.' => array(
40  'tx_extbase.' => array(
41  'settings.' => array(
42  'setting1' => 'value1',
43  'setting2' => 'value2'
44  ),
45  'view.' => array(
46  'viewSub.' => array(
47  'key1' => 'value1',
48  'key2' => 'value2'
49  )
50  )
51  )
52  )
53  );
54 
58  protected $testTypoScriptSetupConverted = array(
59  'foo' => array(
60  'bar' => 'baz'
61  ),
62  'config' => array(
63  'tx_extbase' => array(
64  'settings' => array(
65  'setting1' => 'value1',
66  'setting2' => 'value2'
67  ),
68  'view' => array(
69  'viewSub' => array(
70  'key1' => 'value1',
71  'key2' => 'value2'
72  )
73  )
74  )
75  )
76  );
77 
81  protected $testPluginConfiguration = array(
82  'settings' => array(
83  'setting1' => 'overriddenValue1',
84  'setting3' => 'additionalValue'
85  ),
86  'view' => array(
87  'viewSub' => array(
88  'key1' => 'overridden',
89  'key3' => 'new key'
90  )
91  ),
92  'persistence' => array(
93  'storagePid' => '123'
94  )
95  );
96 
101  'Controller1' => array(
102  'actions' => array('action1', 'action2', 'action3')
103  ),
104  'Controller2' => array(
105  'actions' => array('action4', 'action5', 'action6'),
106  'nonCacheableActions' => array('action4', 'action6')
107  )
108  );
109 
113  public function setUp() {
114  $this->abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\AbstractConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids'));
115  $this->mockTypoScriptService = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
116  $this->abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
117  }
118 
123  $this->abstractConfigurationManager->_set('configurationCache', array('foo' => 'bar'));
124  $this->abstractConfigurationManager->setConfiguration(array());
125  $this->assertEquals(array(), $this->abstractConfigurationManager->_get('configurationCache'));
126  }
127 
132  $configuration = array(
133  'extensionName' => 'SomeExtensionName',
134  'pluginName' => 'SomePluginName'
135  );
136  $this->abstractConfigurationManager->setConfiguration($configuration);
137  $this->assertEquals('SomeExtensionName', $this->abstractConfigurationManager->_get('extensionName'));
138  $this->assertEquals('SomePluginName', $this->abstractConfigurationManager->_get('pluginName'));
139  }
140 
145  $configuration = array(
146  'foo' => 'bar',
147  'settings.' => array('foo' => 'bar'),
148  'view.' => array('subkey.' => array('subsubkey' => 'subsubvalue'))
149  );
150  $expectedResult = array(
151  'foo' => 'bar',
152  'settings' => array('foo' => 'bar'),
153  'view' => array('subkey' => array('subsubkey' => 'subsubvalue'))
154  );
155  $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($expectedResult));
156  $this->abstractConfigurationManager->setConfiguration($configuration);
157  $this->assertEquals($expectedResult, $this->abstractConfigurationManager->_get('configuration'));
158  }
159 
164  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
165  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
166  $this->abstractConfigurationManager->_set('configurationCache', array('currentextensionname_currentpluginname' => array('foo' => 'bar'), 'someotherextension_somepluginname' => array('baz' => 'shouldnotbereturned')));
167  $expectedResult = array('foo' => 'bar');
168  $actualResult = $this->abstractConfigurationManager->getConfiguration();
169  $this->assertEquals($expectedResult, $actualResult);
170  }
171 
176  $this->abstractConfigurationManager->_set('configurationCache', array('someextensionname_somepluginname' => array('foo' => 'bar'), 'someotherextension_somepluginname' => array('baz' => 'shouldnotbereturned')));
177  $expectedResult = array('foo' => 'bar');
178  $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
179  $this->assertEquals($expectedResult, $actualResult);
180  }
181 
186  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
187  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
188  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
189  $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->will($this->returnValue($this->testTypoScriptSetupConverted['config']['tx_extbase']));
190  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
191  $expectedResult = array(
192  'settings' => array(
193  'setting1' => 'overriddenValue1',
194  'setting2' => 'value2',
195  'setting3' => 'additionalValue'
196  ),
197  'view' => array(
198  'viewSub' => array(
199  'key1' => 'overridden',
200  'key2' => 'value2',
201  'key3' => 'new key'
202  )
203  ),
204  'persistence' => array(
205  'storagePid' => '123'
206  ),
207  'controllerConfiguration' => NULL
208  );
209  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->with($expectedResult)->will($this->returnValue($expectedResult));
210  $actualResult = $this->abstractConfigurationManager->getConfiguration();
211  $this->assertEquals($expectedResult, $actualResult);
212  }
213 
218  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
219  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('SomeExtensionName', 'SomePluginName')->will($this->returnValue($this->testPluginConfiguration));
220  $this->mockTypoScriptService->expects($this->atLeastOnce())->method('convertTypoScriptArrayToPlainArray')->with($this->testTypoScriptSetup['config.']['tx_extbase.'])->will($this->returnValue($this->testTypoScriptSetupConverted['config']['tx_extbase']));
221  $expectedResult = array(
222  'settings' => array(
223  'setting1' => 'overriddenValue1',
224  'setting2' => 'value2',
225  'setting3' => 'additionalValue'
226  ),
227  'view' => array(
228  'viewSub' => array(
229  'key1' => 'overridden',
230  'key2' => 'value2',
231  'key3' => 'new key'
232  )
233  ),
234  'persistence' => array(
235  'storagePid' => '123'
236  ),
237  'controllerConfiguration' => NULL
238  );
239  $this->abstractConfigurationManager->expects($this->never())->method('getContextSpecificFrameworkConfiguration');
240  $actualResult = $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
241  $this->assertEquals($expectedResult, $actualResult);
242  }
243 
248  $this->abstractConfigurationManager->expects($this->never())->method('getContextSpecificFrameworkConfiguration');
249  $this->abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
250  }
251 
256  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
257  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with()->will($this->returnValue($this->testPluginConfiguration));
258  $contextSpecifixFrameworkConfiguration = array(
259  'context' => array(
260  'specific' => 'framwork',
261  'conf' => 'iguration'
262  )
263  );
264  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue($contextSpecifixFrameworkConfiguration));
265  $actualResult = $this->abstractConfigurationManager->getConfiguration();
266  $this->assertEquals($contextSpecifixFrameworkConfiguration, $actualResult);
267  }
268 
273  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
274  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
275  $this->abstractConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($this->testTypoScriptSetup));
276  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
277  $contextSpecifixFrameworkConfiguration = array(
278  'context' => array(
279  'specific' => 'framwork',
280  'conf' => 'iguration'
281  )
282  );
283  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue($contextSpecifixFrameworkConfiguration));
284  $actualResult = $this->abstractConfigurationManager->getConfiguration('CurrentExtensionName', 'CurrentPluginName');
285  $this->assertEquals($contextSpecifixFrameworkConfiguration, $actualResult);
286  }
287 
292  $this->abstractConfigurationManager->_set('extensionName', 'CurrentExtensionName');
293  $this->abstractConfigurationManager->_set('pluginName', 'CurrentPluginName');
294  $this->abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue(array('foo' => 'bar')));
295  $this->abstractConfigurationManager->getConfiguration();
296  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
297  $expectedResult = array('currentextensionname_currentpluginname', 'someotherextensionname_someothercurrentpluginname');
298  $actualResult = array_keys($this->abstractConfigurationManager->_get('configurationCache'));
299  $this->assertEquals($expectedResult, $actualResult);
300  }
301 
306  $pluginConfiguration = array(
307  'persistence' => array(
308  'storagePid' => 1,
309  'recursive' => 99
310  )
311  );
312  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
313  $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with('-1');
314  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
315  }
316 
321  $pluginConfiguration = array(
322  'persistence' => array(
323  'storagePid' => '1,25',
324  'recursive' => 99
325  )
326  );
327  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
328  $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with('-1,-25');
329  $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
330  }
331 
338  public function switchableControllerActionsAreNotOverriddenIfPluginNameIsSpecified() {
340  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\AbstractConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids'));
341  $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
342  $abstractConfigurationManager->setConfiguration(array('switchableControllerActions' => array('overriddenSwitchableControllerActions')));
343  $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue(array()));
344  $abstractConfigurationManager->expects($this->never())->method('overrideSwitchableControllerActions');
345  $abstractConfigurationManager->getConfiguration('SomeExtensionName', 'SomePluginName');
346  }
347 
351  public function switchableControllerActionsAreOverriddenIfSpecifiedPluginIsTheCurrentPlugin() {
353  $configuration = array('extensionName' => 'CurrentExtensionName', 'pluginName' => 'CurrentPluginName', 'switchableControllerActions' => array('overriddenSwitchableControllerActions'));
354  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\AbstractConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids'));
355  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
356  $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
357  $abstractConfigurationManager->setConfiguration($configuration);
358  $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue(array()));
359  $abstractConfigurationManager->expects($this->once())->method('overrideSwitchableControllerActions');
360  $abstractConfigurationManager->getConfiguration('CurrentExtensionName', 'CurrentPluginName');
361  }
362 
366  public function switchableControllerActionsAreOverriddenIfPluginNameIsNotSpecified() {
368  $configuration = array('switchableControllerActions' => array('overriddenSwitchableControllerActions'));
369  $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\AbstractConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getRecursiveStoragePids'));
370  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
371  $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
372  $abstractConfigurationManager->setConfiguration($configuration);
373  $abstractConfigurationManager->expects($this->any())->method('getPluginConfiguration')->will($this->returnValue(array()));
374  $abstractConfigurationManager->expects($this->once())->method('overrideSwitchableControllerActions');
375  $abstractConfigurationManager->getConfiguration();
376  }
377 
382  $configuration = array(
383  'extensionName' => 'CurrentExtensionName',
384  'pluginName' => 'CurrentPluginName',
385  'switchableControllerActions' => array(
386  'Controller1' => array('action2', 'action1', 'action3')
387  )
388  );
389  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
390  $this->abstractConfigurationManager->setConfiguration($configuration);
391  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
392  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
393  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
394  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
395  $expectedResult = array(
396  'Controller1' => array(
397  'actions' => array('action2', 'action1', 'action3')
398  )
399  );
400  $actualResult = $mergedConfiguration['controllerConfiguration'];
401  $this->assertEquals($expectedResult, $actualResult);
402  }
403 
408  $configuration = array(
409  'extensionName' => 'CurrentExtensionName',
410  'pluginName' => 'CurrentPluginName',
411  'switchableControllerActions' => array(
412  'Controller1' => array('action2', 'action1', 'action3', 'newAction')
413  )
414  );
415  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
416  $this->abstractConfigurationManager->setConfiguration($configuration);
417  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
418  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
419  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
420  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
421  $expectedResult = array(
422  'Controller1' => array(
423  'actions' => array('action2', 'action1', 'action3', 'newAction')
424  )
425  );
426  $actualResult = $mergedConfiguration['controllerConfiguration'];
427  $this->assertEquals($expectedResult, $actualResult);
428  }
429 
433  public function controllersCanNotBeOverridden() {
434  $configuration = array(
435  'extensionName' => 'CurrentExtensionName',
436  'pluginName' => 'CurrentPluginName',
437  'switchableControllerActions' => array(
438  'NewController' => array('action1', 'action2')
439  )
440  );
441  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
442  $this->abstractConfigurationManager->setConfiguration($configuration);
443  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
444  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
445  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
446  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
447  $expectedResult = array();
448  $actualResult = $mergedConfiguration['controllerConfiguration'];
449  $this->assertEquals($expectedResult, $actualResult);
450  }
451 
456  $configuration = array(
457  'extensionName' => 'CurrentExtensionName',
458  'pluginName' => 'CurrentPluginName',
459  'switchableControllerActions' => array(
460  'Controller1' => array('newAction', 'action1'),
461  'Controller2' => array('newAction2', 'action4', 'action5')
462  )
463  );
464  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
465  $this->abstractConfigurationManager->setConfiguration($configuration);
466  $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
467  $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
468  $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
469  $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
470  $expectedResult = array(
471  'Controller1' => array(
472  'actions' => array('newAction', 'action1')
473  ),
474  'Controller2' => array(
475  'actions' => array('newAction2', 'action4', 'action5'),
476  'nonCacheableActions' => array('action4')
477  )
478  );
479  $actualResult = $mergedConfiguration['controllerConfiguration'];
480  $this->assertEquals($expectedResult, $actualResult);
481  }
482 
487  $this->assertNull($this->abstractConfigurationManager->getContentObject());
488  }
489 
494  $mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
495  $this->abstractConfigurationManager->setContentObject($mockContentObject);
496  $this->assertSame($this->abstractConfigurationManager->getContentObject(), $mockContentObject);
497  }
498 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)