TYPO3 CMS  TYPO3_7-6
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  */
17 
22 {
27 
32 
36  protected function setUp()
37  {
38  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, []);
39  $this->backendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['getTypoScriptSetup']);
40  $this->mockTypoScriptService = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Service\TypoScriptService::class);
41  $this->backendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
42  }
43 
48  {
50  $expectedResult = 123;
51  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
52  $this->assertEquals($expectedResult, $actualResult);
53  }
54 
59  {
61  $_POST['id'] = 321;
62  $expectedResult = 321;
63  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
64  $this->assertEquals($expectedResult, $actualResult);
65  }
66 
71  {
72  $GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue([]));
73  $GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(
74  ['pid' => 123]
75  ));
76  $expectedResult = 123;
77  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
78  $this->assertEquals($expectedResult, $actualResult);
79  }
80 
85  {
86  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(
87  ['uid' => 321]
88  ));
89  $expectedResult = 321;
90  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
91  $this->assertEquals($expectedResult, $actualResult);
92  }
93 
98  {
99  $GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue([]));
100  $GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue([]));
102  $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
103  $this->assertEquals($expectedResult, $actualResult);
104  }
105 
110  {
111  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(['foo' => 'bar']));
112  $expectedResult = [];
113  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
114  $this->assertEquals($expectedResult, $actualResult);
115  }
116 
121  {
122  $testSettings = [
123  'settings.' => [
124  'foo' => 'bar'
125  ]
126  ];
127  $testSettingsConverted = [
128  'settings' => [
129  'foo' => 'bar'
130  ]
131  ];
132  $testSetup = [
133  'module.' => [
134  'tx_someextensionname.' => $testSettings
135  ]
136  ];
137  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
138  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
139  $expectedResult = [
140  'settings' => [
141  'foo' => 'bar'
142  ]
143  ];
144  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
145  $this->assertEquals($expectedResult, $actualResult);
146  }
147 
152  {
153  $testSettings = [
154  'settings.' => [
155  'foo' => 'bar'
156  ]
157  ];
158  $testSettingsConverted = [
159  'settings' => [
160  'foo' => 'bar'
161  ]
162  ];
163  $testSetup = [
164  'module.' => [
165  'tx_someextensionname_somepluginname.' => $testSettings
166  ]
167  ];
168  $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
169  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
170  $expectedResult = [
171  'settings' => [
172  'foo' => 'bar'
173  ]
174  ];
175  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
176  $this->assertEquals($expectedResult, $actualResult);
177  }
178 
183  {
184  $testExtensionSettings = [
185  'settings.' => [
186  'foo' => 'bar',
187  'some.' => [
188  'nested' => 'value'
189  ]
190  ]
191  ];
192  $testExtensionSettingsConverted = [
193  'settings' => [
194  'foo' => 'bar',
195  'some' => [
196  'nested' => 'value'
197  ]
198  ]
199  ];
200  $testPluginSettings = [
201  'settings.' => [
202  'some.' => [
203  'nested' => 'valueOverridde',
204  'new' => 'value'
205  ]
206  ]
207  ];
208  $testPluginSettingsConverted = [
209  'settings' => [
210  'some' => [
211  'nested' => 'valueOverridde',
212  'new' => 'value'
213  ]
214  ]
215  ];
216  $testSetup = [
217  'module.' => [
218  'tx_someextensionname.' => $testExtensionSettings,
219  'tx_someextensionname_somepluginname.' => $testPluginSettings
220  ]
221  ];
222  $this->mockTypoScriptService->expects($this->at(0))->method('convertTypoScriptArrayToPlainArray')->with($testExtensionSettings)->will($this->returnValue($testExtensionSettingsConverted));
223  $this->mockTypoScriptService->expects($this->at(1))->method('convertTypoScriptArrayToPlainArray')->with($testPluginSettings)->will($this->returnValue($testPluginSettingsConverted));
224  $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
225  $expectedResult = [
226  'settings' => [
227  'foo' => 'bar',
228  'some' => [
229  'nested' => 'valueOverridde',
230  'new' => 'value'
231  ]
232  ]
233  ];
234  $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
235  $this->assertEquals($expectedResult, $actualResult);
236  }
237 
242  {
243  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = null;
244  $expectedResult = [];
245  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
246  $this->assertEquals($expectedResult, $actualResult);
247  }
248 
253  {
254  $testSwitchableControllerActions = [
255  'Controller1' => [
256  'actions' => [
257  'action1',
258  'action2'
259  ],
260  'nonCacheableActions' => [
261  'action1'
262  ]
263  ],
264  'Controller2' => [
265  'actions' => [
266  'action3',
267  'action4'
268  ]
269  ]
270  ];
271  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['modules']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
272  $expectedResult = $testSwitchableControllerActions;
273  $actualResult = $this->backendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
274  $this->assertEquals($expectedResult, $actualResult);
275  }
276 
281  {
282  $frameworkConfiguration = [
283  'pluginName' => 'Pi1',
284  'extensionName' => 'SomeExtension',
285  'foo' => [
286  'bar' => [
287  'baz' => 'Foo'
288  ]
289  ],
290  'mvc' => [
291  'requestHandlers' => [
292  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => 'SomeRequestHandler'
293  ]
294  ]
295  ];
296  $expectedResult = $frameworkConfiguration;
297  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
298  $this->assertEquals($expectedResult, $actualResult);
299  }
300 
305  {
306  $frameworkConfiguration = [
307  'pluginName' => 'Pi1',
308  'extensionName' => 'SomeExtension',
309  'foo' => [
310  'bar' => [
311  'baz' => 'Foo'
312  ]
313  ]
314  ];
315  $expectedResult = [
316  'pluginName' => 'Pi1',
317  'extensionName' => 'SomeExtension',
318  'foo' => [
319  'bar' => [
320  'baz' => 'Foo'
321  ]
322  ],
323  'mvc' => [
324  'requestHandlers' => [
325  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class,
326  \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class
327  ]
328  ]
329  ];
330  $actualResult = $this->backendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
331  $this->assertEquals($expectedResult, $actualResult);
332  }
333 
337  public function storagePidsAreExtendedIfRecursiveSearchIsConfigured()
338  {
339  $storagePid = '1,2,3';
340  $recursive = 99;
341 
343  $beUserAuthentication = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
344  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
345  $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
346 
348  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
349  $queryGenerator = $this->getMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
350  $queryGenerator->expects($this->any())
351  ->method('getTreeList')
352  ->will($this->onConsecutiveCalls('4', '', '5,6'));
353  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
354 
355  $expectedResult = '4,5,6';
356  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
357  $this->assertEquals($expectedResult, $actualResult);
358  }
359 
363  public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid()
364  {
365  $storagePid = '1,2,-3';
366  $recursive = 99;
367 
369  $beUserAuthentication = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
370  $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
371  $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
372 
374  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
375  $queryGenerator = $this->getMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
376  $queryGenerator->expects($this->any())
377  ->method('getTreeList')
378  ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
379  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
380 
381  $expectedResult = '4,3,5,6';
382  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
383  $this->assertEquals($expectedResult, $actualResult);
384  }
385 
390  {
391  $storagePid = '1,2,3';
392 
393  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
394 
395  $queryGenerator = $this->getMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
396  $queryGenerator->expects($this->never())->method('getTreeList');
397  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
398 
399  $expectedResult = '1,2,3';
400  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
401  $this->assertEquals($expectedResult, $actualResult);
402  }
403 
408  {
409  $storagePid = '1,2,3';
410  $recursive = 0;
411 
412  $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
413 
414  $queryGenerator = $this->getMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
415  $queryGenerator->expects($this->never())->method('getTreeList');
416  $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
417 
418  $expectedResult = '1,2,3';
419  $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
420  $this->assertEquals($expectedResult, $actualResult);
421  }
422 }
static _GETset($inputGet, $key='')
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']