TYPO3 CMS  TYPO3_8-7
BackendConfigurationManagerTest.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  */
19 
23 class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
29 
34 
38  protected function setUp()
39  {
40  $this->backendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['getTypoScriptSetup']);
41  $this->mockTypoScriptService = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
42  $this->backendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
43  }
44 
49  {
51  $expectedResult = 123;
52  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
53  $this->assertEquals($expectedResult, $actualResult);
54  }
55 
60  {
62  $_POST['id'] = 321;
63  $expectedResult = 321;
64  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
65  $this->assertEquals($expectedResult, $actualResult);
66  }
67 
72  {
73  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(['foo' => 'bar']));
74  $expectedResult = [];
75  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
76  $this->assertEquals($expectedResult, $actualResult);
77  }
78 
83  {
84  $testSettings = [
85  'settings.' => [
86  'foo' => 'bar'
87  ]
88  ];
89  $testSettingsConverted = [
90  'settings' => [
91  'foo' => 'bar'
92  ]
93  ];
94  $testSetup = [
95  'module.' => [
96  'tx_someextensionname.' => $testSettings
97  ]
98  ];
99  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
100  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
101  $expectedResult = [
102  'settings' => [
103  'foo' => 'bar'
104  ]
105  ];
106  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
107  $this->assertEquals($expectedResult, $actualResult);
108  }
109 
114  {
115  $testSettings = [
116  'settings.' => [
117  'foo' => 'bar'
118  ]
119  ];
120  $testSettingsConverted = [
121  'settings' => [
122  'foo' => 'bar'
123  ]
124  ];
125  $testSetup = [
126  'module.' => [
127  'tx_someextensionname_somepluginname.' => $testSettings
128  ]
129  ];
130  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
131  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
132  $expectedResult = [
133  'settings' => [
134  'foo' => 'bar'
135  ]
136  ];
137  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
138  $this->assertEquals($expectedResult, $actualResult);
139  }
140 
145  {
146  $testExtensionSettings = [
147  'settings.' => [
148  'foo' => 'bar',
149  'some.' => [
150  'nested' => 'value'
151  ]
152  ]
153  ];
154  $testExtensionSettingsConverted = [
155  'settings' => [
156  'foo' => 'bar',
157  'some' => [
158  'nested' => 'value'
159  ]
160  ]
161  ];
162  $testPluginSettings = [
163  'settings.' => [
164  'some.' => [
165  'nested' => 'valueOverridde',
166  'new' => 'value'
167  ]
168  ]
169  ];
170  $testPluginSettingsConverted = [
171  'settings' => [
172  'some' => [
173  'nested' => 'valueOverridde',
174  'new' => 'value'
175  ]
176  ]
177  ];
178  $testSetup = [
179  'module.' => [
180  'tx_someextensionname.' => $testExtensionSettings,
181  'tx_someextensionname_somepluginname.' => $testPluginSettings
182  ]
183  ];
184  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
185  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
186  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
187  $expectedResult = [
188  'settings' => [
189  'foo' => 'bar',
190  'some' => [
191  'nested' => 'valueOverridde',
192  'new' => 'value'
193  ]
194  ]
195  ];
196  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
197  $this->assertEquals($expectedResult, $actualResult);
198  }
199 
204  {
205  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = null;
206  $expectedResult = [];
207  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
208  $this->assertEquals($expectedResult, $actualResult);
209  }
210 
215  {
216  $testSwitchableControllerActions = [
217  'Controller1' => [
218  'actions' => [
219  'action1',
220  'action2'
221  ],
222  'nonCacheableActions' => [
223  'action1'
224  ]
225  ],
226  'Controller2' => [
227  'actions' => [
228  'action3',
229  'action4'
230  ]
231  ]
232  ];
233  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
234  $expectedResult = $testSwitchableControllerActions;
235  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
236  $this->assertEquals($expectedResult, $actualResult);
237  }
238 
243  {
244  $frameworkConfiguration = [
245  'pluginName' => 'Pi1',
246  'extensionName' => 'SomeExtension',
247  'foo' => [
248  'bar' => [
249  'baz' => 'Foo'
250  ]
251  ],
252  'mvc' => [
253  'requestHandlers' => [
254  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => 'SomeRequestHandler'
255  ]
256  ]
257  ];
258  $expectedResult = $frameworkConfiguration;
259  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
260  $this->assertEquals($expectedResult, $actualResult);
261  }
262 
267  {
268  $frameworkConfiguration = [
269  'pluginName' => 'Pi1',
270  'extensionName' => 'SomeExtension',
271  'foo' => [
272  'bar' => [
273  'baz' => 'Foo'
274  ]
275  ]
276  ];
277  $expectedResult = [
278  'pluginName' => 'Pi1',
279  'extensionName' => 'SomeExtension',
280  'foo' => [
281  'bar' => [
282  'baz' => 'Foo'
283  ]
284  ],
285  'mvc' => [
286  'requestHandlers' => [
287  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class,
288  \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class
289  ]
290  ]
291  ];
292  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
293  $this->assertEquals($expectedResult, $actualResult);
294  }
295 
299  public function storagePidsAreExtendedIfRecursiveSearchIsConfigured()
300  {
301  $storagePid = '1,2,3';
302  $recursive = 99;
303 
305  $beUserAuthentication = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
306  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
307  $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
308 
309  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
310  $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
311  $queryGenerator->expects($this->any())
312  ->method('getTreeList')
313  ->will($this->onConsecutiveCalls('4', '', '5,6'));
314  GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
315 
316  $expectedResult = '4,5,6';
317  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
318  $this->assertEquals($expectedResult, $actualResult);
319  }
320 
324  public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid()
325  {
326  $storagePid = '1,2,-3';
327  $recursive = 99;
328 
330  $beUserAuthentication = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
331  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
332  $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
333 
334  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getQueryGenerator']);
335  $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
336  $queryGenerator->expects($this->any())
337  ->method('getTreeList')
338  ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
339  GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
340 
341  $expectedResult = '4,3,5,6';
342  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
343  $this->assertEquals($expectedResult, $actualResult);
344  }
345 
350  {
351  $storagePid = '1,2,3';
352 
353  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
354 
355  $expectedResult = '1,2,3';
356  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
357  $this->assertEquals($expectedResult, $actualResult);
358  }
359 
364  {
365  $storagePid = '1,2,3';
366  $recursive = 0;
367 
368  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
369 
370  $expectedResult = '1,2,3';
371  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
372  $this->assertEquals($expectedResult, $actualResult);
373  }
374 }
static addInstance($className, $instance)
static _GETset($inputGet, $key='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']