TYPO3 CMS  TYPO3_7-6
ExtensionServiceTest.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 
30  protected $extensionService;
31 
32  protected function setUp()
33  {
34  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, ['fullQuoteStr', 'exec_SELECTgetRows']);
35  $GLOBALS['TSFE'] = new \stdClass();
36  $this->extensionService = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Service\ExtensionService::class, ['dummy']);
37  $this->mockConfigurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
38  $this->extensionService->_set('configurationManager', $this->mockConfigurationManager);
39  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'] = [
40  'ExtensionName' => [
41  'plugins' => [
42  'SomePlugin' => [
43  'controllers' => [
44  'ControllerName' => [
45  'actions' => ['index', 'otherAction']
46  ]
47  ]
48  ],
49  'ThirdPlugin' => [
50  'controllers' => [
51  'ControllerName' => [
52  'actions' => ['otherAction', 'thirdAction']
53  ]
54  ]
55  ]
56  ]
57  ],
58  'SomeOtherExtensionName' => [
59  'plugins' => [
60  'SecondPlugin' => [
61  'controllers' => [
62  'ControllerName' => [
63  'actions' => ['index', 'otherAction']
64  ],
65  'SecondControllerName' => [
66  'actions' => ['someAction', 'someOtherAction'],
67  'nonCacheableActions' => ['someOtherAction']
68  ]
69  ]
70  ]
71  ]
72  ]
73  ];
74  }
75 
82  {
83  return [
84  ['SomeExtension', 'SomePlugin', 'tx_someextension_someplugin'],
85  ['NonExistingExtension', 'SomePlugin', 'tx_nonexistingextension_someplugin'],
86  ['Invalid', '', 'tx_invalid_']
87  ];
88  }
89 
97  public function getPluginNamespaceTests($extensionName, $pluginName, $expectedResult)
98  {
99  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue([]));
100  $actualResult = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
101  $this->assertEquals($expectedResult, $actualResult, 'Failing for extension: "' . $extensionName . '", plugin: "' . $pluginName . '"');
102  }
103 
108  {
109  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'SomeExtension', 'SomePlugin')->will($this->returnValue(['view' => ['pluginNamespace' => 'overridden_plugin_namespace']]));
110  $expectedResult = 'overridden_plugin_namespace';
111  $actualResult = $this->extensionService->getPluginNamespace('SomeExtension', 'SomePlugin');
112  $this->assertEquals($expectedResult, $actualResult);
113  }
114 
121  {
122  return [
123  ['ExtensionName', 'ControllerName', 'someNonExistingAction', null],
124  ['ExtensionName', 'ControllerName', 'index', 'SomePlugin'],
125  ['ExtensionName', 'ControllerName', 'thirdAction', 'ThirdPlugin'],
126  ['eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'thirdAction', null],
127  ['eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'ThIrDaCtIoN', null],
128  ['SomeOtherExtensionName', 'ControllerName', 'otherAction', 'SecondPlugin']
129  ];
130  }
131 
140  public function getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult)
141  {
142  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(['view' => ['pluginNamespace' => 'overridden_plugin_namespace']]));
143  $actualResult = $this->extensionService->getPluginNameByAction($extensionName, $controllerName, $actionName);
144  $this->assertEquals($expectedResult, $actualResult, 'Failing for $extensionName: "' . $extensionName . '", $controllerName: "' . $controllerName . '", $actionName: "' . $actionName . '" - ');
145  }
146 
152  {
153  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(['view' => ['pluginNamespace' => 'overridden_plugin_namespace']]));
154  $this->extensionService->getPluginNameByAction('ExtensionName', 'ControllerName', 'otherAction');
155  }
156 
161  {
162  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(['extensionName' => 'CurrentExtension', 'pluginName' => 'CurrentPlugin', 'controllerConfiguration' => ['ControllerName' => ['actions' => ['otherAction']]]]));
163  $actualResult = $this->extensionService->getPluginNameByAction('CurrentExtension', 'ControllerName', 'otherAction');
164  $expectedResult = 'CurrentPlugin';
165  $this->assertEquals($expectedResult, $actualResult);
166  }
167 
172  {
173  $mockConfiguration = [];
174  $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
175  $actualResult = $this->extensionService->isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
176  $this->assertTrue($actualResult);
177  }
178 
183  {
184  $mockConfiguration = [
185  'controllerConfiguration' => [
186  'SomeController' => [
187  'nonCacheableActions' => ['someAction']
188  ]
189  ]
190  ];
191  $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
192  $actualResult = $this->extensionService->isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
193  $this->assertFalse($actualResult);
194  }
195 
200  {
201  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(null));
202  $this->assertNull($this->extensionService->getTargetPidByPlugin('ExtensionName', 'PluginName'));
203  }
204 
209  {
210  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(['view' => ['defaultPid' => 0]]));
211  $this->assertNull($this->extensionService->getTargetPidByPlugin('ExtensionName', 'PluginName'));
212  }
213 
218  {
219  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(['view' => ['defaultPid' => 123]]));
220  $expectedResult = 123;
221  $actualResult = $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
222  $this->assertEquals($expectedResult, $actualResult);
223  }
224 
229  {
230  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(['view' => ['defaultPid' => 'auto']]));
231  $pluginSignature = 'extensionname_someplugin';
232  $GLOBALS['TSFE']->sys_page = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, ['enableFields']);
233  $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->with('tt_content')->will($this->returnValue(' AND enable_fields'));
234  $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->with($pluginSignature, 'tt_content')->will($this->returnValue('"pluginSignature"'));
235  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('pid', 'tt_content', 'list_type="pluginSignature" AND CType="list" AND enable_fields AND sys_language_uid=', '', '')->will($this->returnValue([['pid' => '321']]));
236  $expectedResult = 321;
237  $actualResult = $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
238  $this->assertEquals($expectedResult, $actualResult);
239  }
240 
245  {
246  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(['view' => ['defaultPid' => 'auto']]));
247  $GLOBALS['TSFE']->sys_page = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, ['enableFields']);
248  $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
249  $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
250  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue([]));
251  $this->assertNull($this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin'));
252  }
253 
259  {
260  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(['view' => ['defaultPid' => 'auto']]));
261  $GLOBALS['TSFE']->sys_page = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, ['enableFields']);
262  $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
263  $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
264  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue([['pid' => 123], ['pid' => 124]]));
265  $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
266  }
267 
272  {
273  $this->assertNull($this->extensionService->getDefaultControllerNameByPlugin('NonExistingExtensionName', 'SomePlugin'));
274  }
275 
280  {
281  $this->assertNull($this->extensionService->getDefaultControllerNameByPlugin('ExtensionName', 'NonExistingPlugin'));
282  }
283 
288  {
289  $expectedResult = 'ControllerName';
290  $actualResult = $this->extensionService->getDefaultControllerNameByPlugin('ExtensionName', 'SomePlugin');
291  $this->assertEquals($expectedResult, $actualResult);
292  }
293 
298  {
299  $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController('NonExistingExtensionName', 'SomePlugin', 'ControllerName'));
300  }
301 
306  {
307  $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController('ExtensionName', 'NonExistingPlugin', 'ControllerName'));
308  }
309 
314  {
315  $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController('ExtensionName', 'SomePlugin', 'NonExistingControllerName'));
316  }
317 
322  {
323  $expectedResult = 'someAction';
324  $actualResult = $this->extensionService->getDefaultActionNameByPluginAndController('SomeOtherExtensionName', 'SecondPlugin', 'SecondControllerName');
325  $this->assertEquals($expectedResult, $actualResult);
326  }
327 }
getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult)
getPluginNamespaceTests($extensionName, $pluginName, $expectedResult)
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']