2 declare(strict_types = 1);
17 use Doctrine\DBAL\Statement;
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
50 protected function setUp()
53 $this->extensionService = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Service\ExtensionService::class, [
'dummy']);
54 $this->mockConfigurationManager = $this->createMock(\
TYPO3\CMS\
Extbase\Configuration\ConfigurationManagerInterface::class);
55 $this->extensionService->_set(
'configurationManager', $this->mockConfigurationManager);
56 $GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'extbase'][
'extensions'] = [
62 'actions' => [
'index',
'otherAction']
69 'actions' => [
'otherAction',
'thirdAction']
75 'SomeOtherExtensionName' => [
80 'actions' => [
'index',
'otherAction']
82 'SecondControllerName' => [
83 'actions' => [
'someAction',
'someOtherAction'],
84 'nonCacheableActions' => [
'someOtherAction']
101 $connection = $this->prophesize(Connection::class);
102 $connection->getDatabasePlatform()->willReturn(
new MockPlatform());
103 $connection->getExpressionBuilder()->willReturn(
new ExpressionBuilder($connection->reveal()));
104 $connection->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
107 $connection->reveal(),
109 new \Doctrine\DBAL\Query\
QueryBuilder($connection->reveal())
112 $connectionPool = $this->prophesize(ConnectionPool::class);
113 $connectionPool->getQueryBuilderForTable(
'tt_content')->willReturn($queryBuilder);
114 GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
127 [
'SomeExtension',
'SomePlugin',
'tx_someextension_someplugin'],
128 [
'NonExistingExtension',
'SomePlugin',
'tx_nonexistingextension_someplugin'],
129 [
'Invalid',
'',
'tx_invalid_']
142 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will($this->returnValue([]));
143 $actualResult = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
144 $this->assertEquals($expectedResult, $actualResult,
'Failing for extension: "' . $extensionName .
'", plugin: "' . $pluginName .
'"');
152 $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']]));
153 $expectedResult =
'overridden_plugin_namespace';
154 $actualResult = $this->extensionService->getPluginNamespace(
'SomeExtension',
'SomePlugin');
155 $this->assertEquals($expectedResult, $actualResult);
166 [
'ExtensionName',
'ControllerName',
'someNonExistingAction',
null],
167 [
'ExtensionName',
'ControllerName',
'index',
'SomePlugin'],
168 [
'ExtensionName',
'ControllerName',
'thirdAction',
'ThirdPlugin'],
169 [
'eXtEnSiOnNaMe',
'cOnTrOlLeRnAmE',
'thirdAction',
null],
170 [
'eXtEnSiOnNaMe',
'cOnTrOlLeRnAmE',
'ThIrDaCtIoN',
null],
171 [
'SomeOtherExtensionName',
'ControllerName',
'otherAction',
'SecondPlugin']
185 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->with(\
TYPO3\CMS\
Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue([
'view' => [
'pluginNamespace' =>
'overridden_plugin_namespace']]));
186 $actualResult = $this->extensionService->getPluginNameByAction($extensionName, $controllerName, $actionName);
187 $this->assertEquals($expectedResult, $actualResult,
'Failing for $extensionName: "' . $extensionName .
'", $controllerName: "' . $controllerName .
'", $actionName: "' . $actionName .
'" - ');
195 $this->expectException(Exception::class);
196 $this->expectExceptionCode(1280825466);
197 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->with(\
TYPO3\CMS\
Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue([
'view' => [
'pluginNamespace' =>
'overridden_plugin_namespace']]));
198 $this->extensionService->getPluginNameByAction(
'ExtensionName',
'ControllerName',
'otherAction');
206 $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']]]]));
207 $actualResult = $this->extensionService->getPluginNameByAction(
'CurrentExtension',
'ControllerName',
'otherAction');
208 $expectedResult =
'CurrentPlugin';
209 $this->assertEquals($expectedResult, $actualResult);
217 $mockConfiguration = [];
218 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($mockConfiguration));
219 $actualResult = $this->extensionService->isActionCacheable(
'SomeExtension',
'SomePlugin',
'SomeController',
'someAction');
220 $this->assertTrue($actualResult);
228 $mockConfiguration = [
229 'controllerConfiguration' => [
230 'SomeController' => [
231 'nonCacheableActions' => [
'someAction']
235 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($mockConfiguration));
236 $actualResult = $this->extensionService->isActionCacheable(
'SomeExtension',
'SomePlugin',
'SomeController',
'someAction');
237 $this->assertFalse($actualResult);
245 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will($this->returnValue(
null));
246 $this->assertNull($this->extensionService->getTargetPidByPlugin(
'ExtensionName',
'PluginName'));
254 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will($this->returnValue([
'view' => [
'defaultPid' => 0]]));
255 $this->assertNull($this->extensionService->getTargetPidByPlugin(
'ExtensionName',
'PluginName'));
263 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will($this->returnValue([
'view' => [
'defaultPid' => 123]]));
264 $expectedResult = 123;
265 $actualResult = $this->extensionService->getTargetPidByPlugin(
'ExtensionName',
'SomePlugin');
266 $this->assertEquals($expectedResult, $actualResult);
275 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will(
276 $this->returnValue([
'view' => [
'defaultPid' =>
'auto']])
278 $expectedResult = 321;
280 $statement = $this->prophesize(Statement::class);
281 $statement->fetchAll()->shouldBeCalled()->willReturn([[
'pid' => (
string)$expectedResult]]);
284 $connection->executeQuery(
285 'SELECT pid FROM tt_content WHERE (list_type = :dcValue1) AND (CType = :dcValue2) AND (sys_language_uid = :dcValue3) LIMIT 2',
286 [
'dcValue1' =>
'extensionname_someplugin',
'dcValue2' =>
'list',
'dcValue3' => 0],
288 )->shouldBeCalled()->willReturn($statement->reveal());
290 $actualResult = $this->extensionService->getTargetPidByPlugin(
'ExtensionName',
'SomePlugin');
291 $this->assertEquals($expectedResult, $actualResult);
300 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will(
301 $this->returnValue([
'view' => [
'defaultPid' =>
'auto']])
304 $statement = $this->prophesize(Statement::class);
305 $statement->fetchAll()->shouldBeCalled()->willReturn([]);
308 $connection->executeQuery(
309 'SELECT pid FROM tt_content WHERE (list_type = :dcValue1) AND (CType = :dcValue2) AND (sys_language_uid = :dcValue3) LIMIT 2',
310 [
'dcValue1' =>
'extensionname_someplugin',
'dcValue2' =>
'list',
'dcValue3' => 0],
312 )->shouldBeCalled()->willReturn($statement->reveal());
314 $this->assertNull($this->extensionService->getTargetPidByPlugin(
'ExtensionName',
'SomePlugin'));
323 $this->expectException(Exception::class);
324 $this->expectExceptionCode(1280773643);
326 $this->mockConfigurationManager->expects($this->once())->method(
'getConfiguration')->will(
327 $this->returnValue([
'view' => [
'defaultPid' =>
'auto']])
330 $statement = $this->prophesize(Statement::class);
331 $statement->fetchAll()->shouldBeCalled()->willReturn([[
'pid' => 123], [
'pid' => 124]]);
334 $connection->executeQuery(
335 'SELECT pid FROM tt_content WHERE (list_type = :dcValue1) AND (CType = :dcValue2) AND (sys_language_uid = :dcValue3) LIMIT 2',
336 [
'dcValue1' =>
'extensionname_someplugin',
'dcValue2' =>
'list',
'dcValue3' => 0],
338 )->shouldBeCalled()->willReturn($statement->reveal());
341 $this->expectExceptionCode(1280773643);
343 $this->extensionService->getTargetPidByPlugin(
'ExtensionName',
'SomePlugin');
351 $this->assertNull($this->extensionService->getDefaultControllerNameByPlugin(
'NonExistingExtensionName',
'SomePlugin'));
359 $this->assertNull($this->extensionService->getDefaultControllerNameByPlugin(
'ExtensionName',
'NonExistingPlugin'));
367 $expectedResult =
'ControllerName';
368 $actualResult = $this->extensionService->getDefaultControllerNameByPlugin(
'ExtensionName',
'SomePlugin');
369 $this->assertEquals($expectedResult, $actualResult);
377 $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController(
'NonExistingExtensionName',
'SomePlugin',
'ControllerName'));
385 $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController(
'ExtensionName',
'NonExistingPlugin',
'ControllerName'));
393 $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController(
'ExtensionName',
'SomePlugin',
'NonExistingControllerName'));
401 $expectedResult =
'someAction';
402 $actualResult = $this->extensionService->getDefaultActionNameByPluginAndController(
'SomeOtherExtensionName',
'SecondPlugin',
'SecondControllerName');
403 $this->assertEquals($expectedResult, $actualResult);