2 declare(strict_types = 1);
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
73 protected function setUp(): void
75 $this->requestBuilder = $this->getAccessibleMock(RequestBuilder::class, [
'dummy']);
76 $this->configuration = [
77 'userFunc' =>
'Tx_Extbase_Dispatcher->dispatch',
78 'pluginName' =>
'Pi1',
79 'extensionName' =>
'MyExtension',
80 'controller' =>
'TheFirstController',
82 'controllerConfiguration' => [
83 'TheFirstController' => [
84 'actions' => [
'show',
'index',
'new',
'create',
'delete',
'edit',
'update',
'setup',
'test']
86 'TheSecondController' => [
87 'actions' => [
'show',
'index']
89 'TheThirdController' => [
90 'actions' => [
'delete',
'create',
'onlyInThirdController']
94 $this->mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
95 $this->mockRequest = $this->createMock(Request::class);
96 $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class);
97 $this->mockExtensionService = $this->createMock(ExtensionService::class);
98 $this->mockEnvironmentService = $this->getMockBuilder(EnvironmentService::class)
99 ->setMethods([
'getServerRequestMethod'])
107 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
108 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
109 $this->mockObjectManager->expects($this->any())->method(
'get')->with(Request::class)->will($this->returnValue($this->mockRequest));
110 $this->requestBuilder->_set(
'objectManager', $this->mockObjectManager);
111 $pluginNamespace =
'tx_' . strtolower($this->configuration[
'extensionName'] .
'_' . $this->configuration[
'pluginName']);
112 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue($pluginNamespace));
113 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
114 $this->mockEnvironmentService->expects($this->any())->method(
'getServerRequestMethod')->will($this->returnValue(
'GET'));
115 $this->requestBuilder->_set(
'environmentService', $this->mockEnvironmentService);
124 $request = $this->requestBuilder->build();
125 $this->assertSame($this->mockRequest, $request);
134 $this->mockRequest->expects($this->once())->method(
'setPluginName')->with(
'Pi1');
135 $this->requestBuilder->build();
144 $this->mockRequest->expects($this->once())->method(
'setControllerExtensionName')->with(
'MyExtension');
145 $this->requestBuilder->build();
154 $this->mockRequest->expects($this->once())->method(
'setControllerName')->with(
'TheFirstController');
155 $this->requestBuilder->build();
164 $this->mockRequest->expects($this->once())->method(
'setControllerActionName')->with(
'show');
165 $this->requestBuilder->build();
174 $expectedRequestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(
'TYPO3_REQUEST_URL');
175 $this->mockRequest->expects($this->once())->method(
'setRequestUri')->with($expectedRequestUri);
176 $this->requestBuilder->build();
185 $expectedBaseUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(
'TYPO3_SITE_URL');
186 $this->mockRequest->expects($this->once())->method(
'setBaseUri')->with($expectedBaseUri);
187 $this->requestBuilder->build();
196 $expectedMethod =
'SomeRequestMethod';
198 ->setMethods([
'getServerRequestMethod'])
200 $mockEnvironmentService->expects($this->once())->method(
'getServerRequestMethod')->will($this->returnValue($expectedMethod));
202 $this->mockRequest->expects($this->once())->method(
'setMethod')->with($expectedMethod);
203 $this->requestBuilder->build();
212 $expectedVendor =
'Vendor';
213 $this->configuration[
'vendorName'] = $expectedVendor;
215 $mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
217 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
218 $this->mockRequest->expects($this->once())->method(
'setControllerVendorName')->with($expectedVendor);
219 $this->requestBuilder->build();
228 $expectedVendor =
'Vendor';
229 $this->configuration[
'vendorName'] = $expectedVendor;
232 $mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
234 $this->mockRequest->expects($this->once())->method(
'setControllerVendorName')->with($expectedVendor);
236 $this->requestBuilder->build();
238 unset($this->configuration[
'vendorName']);
240 $mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
243 $this->mockRequest->expects($this->never())->method(
'setControllerVendorName');
244 $this->requestBuilder->build();
252 $this->expectException(Exception::class);
253 $this->expectExceptionCode(1289843275);
254 unset($this->configuration[
'extensionName']);
256 $mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
258 $this->requestBuilder->build();
266 $this->expectException(Exception::class);
267 $this->expectExceptionCode(1289843277);
268 unset($this->configuration[
'pluginName']);
270 $mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
272 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
273 $this->requestBuilder->build();
281 $this->expectException(Exception::class);
282 $this->expectExceptionCode(1316104317);
283 $this->configuration[
'controllerConfiguration'] = [];
284 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
285 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
286 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
287 $this->requestBuilder->build();
295 $this->expectException(Exception::class);
296 $this->expectExceptionCode(1295479651);
297 $this->configuration[
'controllerConfiguration'][
'TheFirstController'] = [];
298 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
299 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
300 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
301 $this->requestBuilder->build();
309 $this->expectException(Exception::class);
310 $this->expectExceptionCode(1316104317);
311 $this->configuration[
'controllerConfiguration'] = [
316 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
317 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
318 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
319 $this->requestBuilder->build();
327 $this->configuration[
'extensionName'] =
'SomeExtensionName';
328 $this->configuration[
'pluginName'] =
'SomePluginName';
331 'tx_someotherextensionname_somepluginname' => [
334 'tx_someextensionname_somepluginname' => [
335 'parameter1' =>
'valueGetsOverwritten',
337 'parameter3' =>
'value3'
342 'tx_someextensionname_someotherpluginname' => [
345 'tx_someextensionname_somepluginname' => [
346 'parameter1' =>
'value1',
348 'parameter4' =>
'value4'
352 $this->mockRequest->expects($this->at(8))->method(
'setArgument')->with(
'parameter1',
'value1');
353 $this->mockRequest->expects($this->at(9))->method(
'setArgument')->with(
355 [
'parameter3' =>
'value3',
'parameter4' =>
'value4']
357 $this->requestBuilder->build();
365 $this->configuration[
'extensionName'] =
'SomeExtensionName';
366 $this->configuration[
'pluginName'] =
'SomePluginName';
369 'tx_someextensionname_somepluginname' => [
374 'tx_someextensionname_somepluginname' => [
378 $this->mockRequest->expects($this->at(7))->method(
'setFormat')->with(
'POST');
379 $this->requestBuilder->build();
389 'TheFirstController' => [
400 'TheSecondController' => [
404 'TheThirdController' => [
407 'onlyInThirdController'
410 $this->requestBuilder->build();
411 $actualResult = $this->requestBuilder->_get(
'allowedControllerActions');
412 $this->assertEquals($expectedResult, $actualResult);
420 $this->expectException(Exception::class);
421 $this->expectExceptionCode(1316104317);
422 $this->configuration[
'controllerConfiguration'] = [];
423 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
424 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
425 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue(
'tx_myextension_pi1'));
426 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
427 $this->requestBuilder->build();
437 'tx_myextension_pi1' => [
441 $this->mockRequest->expects($this->once())->method(
'setControllerName')->with(
'TheFirstController');
442 $this->requestBuilder->build();
452 'tx_myextension_pi1' => [
453 'controller' =>
'TheSecondController'
456 $this->mockRequest->expects($this->once())->method(
'setControllerName')->with(
'TheSecondController');
457 $this->requestBuilder->build();
465 $this->expectException(InvalidControllerNameException::class);
466 $this->expectExceptionCode(1313855173);
467 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
468 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
469 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue(
'tx_myextension_pi1'));
470 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
472 'tx_myextension_pi1' => [
473 'controller' =>
'SomeInvalidController'
476 $this->requestBuilder->build();
484 $this->expectException(PageNotFoundException::class);
485 $this->expectExceptionCode(1313857897);
486 $this->configuration[
'mvc'][
'throwPageNotFoundExceptionIfActionCantBeResolved'] = 1;
487 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
488 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
489 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue(
'tx_myextension_pi1'));
490 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
492 'tx_myextension_pi1' => [
493 'controller' =>
'SomeInvalidController'
496 $this->requestBuilder->build();
504 $this->configuration[
'mvc'][
'callDefaultActionIfActionCantBeResolved'] = 1;
506 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
508 'tx_myextension_pi1' => [
509 'controller' =>
'SomeInvalidController'
512 $this->mockRequest->expects($this->once())->method(
'setControllerName')->with(
'TheFirstController');
513 $this->requestBuilder->build();
521 $this->expectException(Exception::class);
522 $this->expectExceptionCode(1316104317);
523 $this->configuration[
'controllerConfiguration'] = [];
524 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
525 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
526 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue(
'tx_myextension_pi1'));
527 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
528 $this->requestBuilder->build();
538 'tx_myextension_pi1' => [
539 'controller' =>
'TheThirdController'
542 $this->mockRequest->expects($this->once())->method(
'setControllerActionName')->with(
'delete');
543 $this->requestBuilder->build();
553 'tx_myextension_pi1' => [
557 $this->mockRequest->expects($this->once())->method(
'setControllerActionName')->with(
'create');
558 $this->requestBuilder->build();
568 'tx_myextension_pi1' => [
569 'controller' =>
'TheThirdController',
570 'action' =>
'onlyInThirdController'
573 $this->mockRequest->expects($this->once())->method(
'setControllerActionName')->with(
'onlyInThirdController');
574 $this->requestBuilder->build();
582 $this->expectException(InvalidActionNameException::class);
583 $this->expectExceptionCode(1313855175);
584 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
585 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
586 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue(
'tx_myextension_pi1'));
587 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
589 'tx_myextension_pi1' => [
590 'action' =>
'someInvalidAction'
593 $this->requestBuilder->build();
601 $this->expectException(PageNotFoundException::class);
602 $this->expectExceptionCode(1313857898);
603 $this->configuration[
'mvc'][
'throwPageNotFoundExceptionIfActionCantBeResolved'] = 1;
604 $this->mockConfigurationManager->expects($this->any())->method(
'getConfiguration')->will($this->returnValue($this->configuration));
605 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
606 $this->mockExtensionService->expects($this->any())->method(
'getPluginNamespace')->will($this->returnValue(
'tx_myextension_pi1'));
607 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
609 'tx_myextension_pi1' => [
610 'action' =>
'someInvalidAction'
613 $this->requestBuilder->build();
621 $this->configuration[
'mvc'][
'callDefaultActionIfActionCantBeResolved'] = 1;
623 $this->requestBuilder->_set(
'extensionService', $this->mockExtensionService);
625 'tx_myextension_pi1' => [
626 'controller' =>
'TheThirdController',
627 'action' =>
'someInvalidAction'
630 $this->mockRequest->expects($this->once())->method(
'setControllerName')->with(
'TheThirdController');
631 $this->mockRequest->expects($this->once())->method(
'setControllerActionName')->with(
'delete');
632 $this->requestBuilder->build();
650 'a1' =>
'/private/var/tmp/phpbqXsYt'
667 'b1' =>
'/private/var/tmp/phpvZ6oUD'
678 'type' =>
'text/plain',
679 'tmp_name' =>
'/private/var/tmp/phpS9KMNw',
702 0 =>
'/private/var/tmp/phpMf9Qx9',
704 'd3' =>
'/private/var/tmp/phprR3fax'
745 0 =>
'/private/var/tmp/php01fitB',
746 1 =>
'/private/var/tmp/phpUUB2cv'
768 'name' =>
'error_file.txt',
769 'type' =>
'text/plain',
770 'tmp_name' =>
'/private/var/tmp/phpADDu87fE',
779 'type' =>
'text/plain',
780 'tmp_name' =>
'/private/var/tmp/phpbqXsYt',
788 'type' =>
'text/plain',
789 'tmp_name' =>
'/private/var/tmp/phpvZ6oUD',
796 'type' =>
'text/plain',
797 'tmp_name' =>
'/private/var/tmp/phpS9KMNw',
805 'type' =>
'text/plain',
806 'tmp_name' =>
'/private/var/tmp/phpMf9Qx9',
813 'type' =>
'text/plain',
814 'tmp_name' =>
'/private/var/tmp/phprR3fax',
825 'name' =>
'e_one.txt',
826 'type' =>
'text/plain',
827 'tmp_name' =>
'/private/var/tmp/php01fitB',
832 'name' =>
'e_two.txt',
833 'type' =>
'text/plain',
834 'tmp_name' =>
'/private/var/tmp/phpUUB2cv',
842 'name' =>
'error_file.txt',
843 'type' =>
'text/plain',
844 'tmp_name' =>
'/private/var/tmp/phpADDu87fE',
849 $requestBuilder = $this->getAccessibleMock(RequestBuilder::class, [
'dummy'], [],
'',
false);
851 $this->assertSame($untangledFiles, $result);