[TASK] Use FQCN's when registering plugins/modules
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Web / RequestBuilderTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Web;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18 use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
19 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
20 use TYPO3\CMS\Extbase\Mvc\Exception;
21 use TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException;
22 use TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException;
23 use TYPO3\CMS\Extbase\Mvc\Web\Request;
24 use TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder;
25 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
26 use TYPO3\CMS\Extbase\Service\EnvironmentService;
27 use TYPO3\CMS\Extbase\Service\ExtensionService;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29
30 /**
31 * Test case
32 */
33 class RequestBuilderTest extends UnitTestCase
34 {
35 /**
36 * @var RequestBuilder|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
37 */
38 protected $requestBuilder;
39
40 /**
41 * @var ConfigurationManagerInterface|\PHPUnit_Framework_MockObject_MockObject
42 */
43 protected $mockConfigurationManager;
44
45 /**
46 * @var array
47 */
48 protected $configuration;
49
50 /**
51 * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
52 */
53 protected $mockObjectManager;
54
55 /**
56 * @var ExtensionService|\PHPUnit_Framework_MockObject_MockObject
57 */
58 protected $mockExtensionService;
59
60 /**
61 * @var EnvironmentService|\PHPUnit_Framework_MockObject_MockObject
62 */
63 protected $mockEnvironmentService;
64
65 /**
66 * @var Request|\PHPUnit_Framework_MockObject_MockObject
67 */
68 protected $mockRequest;
69
70 /**
71 * Set up
72 */
73 protected function setUp(): void
74 {
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',
81 'action' => 'show',
82 'controllerConfiguration' => [
83 'MyExtension\Controller\TheFirstControllerController' => [
84 'className' => 'MyExtension\Controller\TheFirstControllerController',
85 'alias' => 'TheFirstController',
86 'actions' => ['show', 'index', 'new', 'create', 'delete', 'edit', 'update', 'setup', 'test']
87 ],
88 'MyExtension\Controller\TheSecondControllerController' => [
89 'className' => 'MyExtension\Controller\TheSecondControllerController',
90 'alias' => 'TheSecondController',
91 'actions' => ['show', 'index']
92 ],
93 'MyExtension\Controller\TheThirdControllerController' => [
94 'className' => 'MyExtension\Controller\TheThirdControllerController',
95 'alias' => 'TheThirdController',
96 'actions' => ['delete', 'create', 'onlyInThirdController']
97 ]
98 ]
99 ];
100 $this->mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
101 $this->mockRequest = $this->createMock(Request::class);
102 $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class);
103 $this->mockExtensionService = $this->createMock(ExtensionService::class);
104 $this->mockEnvironmentService = $this->getMockBuilder(EnvironmentService::class)
105 ->setMethods(['getServerRequestMethod'])
106 ->getMock();
107 }
108
109 /**
110 */
111 protected function injectDependencies(): void
112 {
113 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
114 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
115 $this->mockObjectManager->expects($this->any())->method('get')->with(Request::class)->will($this->returnValue($this->mockRequest));
116 $this->requestBuilder->_set('objectManager', $this->mockObjectManager);
117 $pluginNamespace = 'tx_' . strtolower($this->configuration['extensionName'] . '_' . $this->configuration['pluginName']);
118 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue($pluginNamespace));
119 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
120 $this->mockEnvironmentService->expects($this->any())->method('getServerRequestMethod')->will($this->returnValue('GET'));
121 $this->requestBuilder->_set('environmentService', $this->mockEnvironmentService);
122 }
123
124 /**
125 * @test
126 */
127 public function buildReturnsAWebRequestObject(): void
128 {
129 $this->injectDependencies();
130 $request = $this->requestBuilder->build();
131 $this->assertSame($this->mockRequest, $request);
132 }
133
134 /**
135 * @test
136 */
137 public function buildSetsRequestPluginName(): void
138 {
139 $this->injectDependencies();
140 $this->mockRequest->expects($this->once())->method('setPluginName')->with('Pi1');
141 $this->requestBuilder->build();
142 }
143
144 /**
145 * @test
146 */
147 public function buildSetsRequestControllerExtensionName(): void
148 {
149 $this->injectDependencies();
150 $this->mockRequest->expects($this->once())->method('setControllerExtensionName')->with('MyExtension');
151 $this->requestBuilder->build();
152 }
153
154 /**
155 * @test
156 */
157 public function buildSetsRequestControllerName(): void
158 {
159 $this->injectDependencies();
160 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
161 $this->requestBuilder->build();
162 }
163
164 /**
165 * @test
166 */
167 public function buildSetsRequestControllerActionName(): void
168 {
169 $this->injectDependencies();
170 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('show');
171 $this->requestBuilder->build();
172 }
173
174 /**
175 * @test
176 */
177 public function buildSetsRequestRequestUri(): void
178 {
179 $this->injectDependencies();
180 $expectedRequestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
181 $this->mockRequest->expects($this->once())->method('setRequestUri')->with($expectedRequestUri);
182 $this->requestBuilder->build();
183 }
184
185 /**
186 * @test
187 */
188 public function buildSetsRequestBaseUri(): void
189 {
190 $this->injectDependencies();
191 $expectedBaseUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
192 $this->mockRequest->expects($this->once())->method('setBaseUri')->with($expectedBaseUri);
193 $this->requestBuilder->build();
194 }
195
196 /**
197 * @test
198 */
199 public function buildSetsRequestMethod(): void
200 {
201 $this->injectDependencies();
202 $expectedMethod = 'SomeRequestMethod';
203 $mockEnvironmentService = $this->getMockBuilder(EnvironmentService::class)
204 ->setMethods(['getServerRequestMethod'])
205 ->getMock();
206 $mockEnvironmentService->expects($this->once())->method('getServerRequestMethod')->will($this->returnValue($expectedMethod));
207 $this->requestBuilder->_set('environmentService', $mockEnvironmentService);
208 $this->mockRequest->expects($this->once())->method('setMethod')->with($expectedMethod);
209 $this->requestBuilder->build();
210 }
211
212 /**
213 * @test
214 */
215 public function buildSetsVendorNameIfConfigured(): void
216 {
217 $this->injectDependencies();
218 $expectedVendor = 'Vendor';
219 $this->configuration['vendorName'] = $expectedVendor;
220 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
221 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
222 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
223 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
224 $this->mockRequest->expects($this->once())->method('setControllerVendorName')->with($expectedVendor);
225 $this->requestBuilder->build();
226 }
227
228 /**
229 * @test
230 */
231 public function buildDoesNotSetVendorNameIfNotConfiguredInSecondRequest(): void
232 {
233 $this->injectDependencies();
234 $expectedVendor = 'Vendor';
235 $this->configuration['vendorName'] = $expectedVendor;
236
237 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
238 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
239 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
240 $this->mockRequest->expects($this->once())->method('setControllerVendorName')->with($expectedVendor);
241
242 $this->requestBuilder->build();
243
244 unset($this->configuration['vendorName']);
245 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
246 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
247 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
248
249 $this->mockRequest->expects($this->never())->method('setControllerVendorName');
250 $this->requestBuilder->build();
251 }
252
253 /**
254 * @test
255 */
256 public function buildThrowsExceptionIfExtensionNameIsNotConfigured(): void
257 {
258 $this->expectException(Exception::class);
259 $this->expectExceptionCode(1289843275);
260 unset($this->configuration['extensionName']);
261 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
262 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
263 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
264 $this->requestBuilder->build();
265 }
266
267 /**
268 * @test
269 */
270 public function buildThrowsExceptionIfPluginNameIsNotConfigured(): void
271 {
272 $this->expectException(Exception::class);
273 $this->expectExceptionCode(1289843277);
274 unset($this->configuration['pluginName']);
275 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
276 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
277 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
278 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
279 $this->requestBuilder->build();
280 }
281
282 /**
283 * @test
284 */
285 public function buildThrowsExceptionIfControllerConfigurationIsEmptyOrNotSet(): void
286 {
287 $this->expectException(Exception::class);
288 $this->expectExceptionCode(1316104317);
289 $this->configuration['controllerConfiguration'] = [];
290 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
291 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
292 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
293 $this->requestBuilder->build();
294 }
295
296 /**
297 * @test
298 */
299 public function buildThrowsExceptionIfControllerConfigurationHasNoDefaultActionDefined(): void
300 {
301 $this->expectException(Exception::class);
302 $this->expectExceptionCode(1295479651);
303 $this->configuration['controllerConfiguration']['MyExtension\Controller\TheFirstControllerController'] = [
304 'className' => 'MyExtension\Controller\TheFirstControllerController',
305 'alias' => 'TheFirstController',
306 ];
307 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
308 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
309 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
310 $this->requestBuilder->build();
311 }
312
313 /**
314 * @test
315 */
316 public function buildThrowsExceptionIfNoDefaultControllerCanBeResolved(): void
317 {
318 $this->expectException(Exception::class);
319 $this->expectExceptionCode(1316104317);
320 $this->configuration['controllerConfiguration'] = [
321 '' => [
322 'className' => '',
323 'alias' => '',
324 'actions' => ['foo']
325 ]
326 ];
327 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
328 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
329 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
330 $this->requestBuilder->build();
331 }
332
333 /**
334 * @test
335 */
336 public function buildSetsParametersFromGetAndPostVariables(): void
337 {
338 $this->configuration['extensionName'] = 'SomeExtensionName';
339 $this->configuration['pluginName'] = 'SomePluginName';
340 $this->injectDependencies();
341 $_GET = [
342 'tx_someotherextensionname_somepluginname' => [
343 'foo' => 'bar'
344 ],
345 'tx_someextensionname_somepluginname' => [
346 'parameter1' => 'valueGetsOverwritten',
347 'parameter2' => [
348 'parameter3' => 'value3'
349 ]
350 ]
351 ];
352 $_POST = [
353 'tx_someextensionname_someotherpluginname' => [
354 'foo' => 'bar'
355 ],
356 'tx_someextensionname_somepluginname' => [
357 'parameter1' => 'value1',
358 'parameter2' => [
359 'parameter4' => 'value4'
360 ]
361 ]
362 ];
363
364 // testing at which position something gets called is fishy.
365 // why not make this a functional test and test with an actual requestBuilder instance and check the arguments
366 // later on?
367 $this->mockRequest->expects($this->at(9))->method('setArgument')->with('parameter1', 'value1');
368 $this->mockRequest->expects($this->at(10))->method('setArgument')->with(
369 'parameter2',
370 ['parameter3' => 'value3', 'parameter4' => 'value4']
371 );
372 $this->requestBuilder->build();
373 }
374
375 /**
376 * @test
377 */
378 public function buildSetsFormatFromGetAndPostVariables(): void
379 {
380 $this->configuration['extensionName'] = 'SomeExtensionName';
381 $this->configuration['pluginName'] = 'SomePluginName';
382 $this->injectDependencies();
383 $_GET = [
384 'tx_someextensionname_somepluginname' => [
385 'format' => 'GET'
386 ]
387 ];
388 $_POST = [
389 'tx_someextensionname_somepluginname' => [
390 'format' => 'POST'
391 ]
392 ];
393 // phew! Shitty position tests. Who thought this was a good idea?
394 $this->mockRequest->expects($this->at(8))->method('setFormat')->with('POST');
395 $this->requestBuilder->build();
396 }
397
398 /**
399 * @test
400 */
401 public function buildCorrectlySetsAllowedControllerActions(): void
402 {
403 $this->injectDependencies();
404 $expectedResult = [
405 'MyExtension\Controller\TheFirstControllerController' => [
406 'show',
407 'index',
408 'new',
409 'create',
410 'delete',
411 'edit',
412 'update',
413 'setup',
414 'test'
415 ],
416 'MyExtension\Controller\TheSecondControllerController' => [
417 'show',
418 'index'
419 ],
420 'MyExtension\Controller\TheThirdControllerController' => [
421 'delete',
422 'create',
423 'onlyInThirdController'
424 ]
425 ];
426 $this->requestBuilder->build();
427 $actualResult = $this->requestBuilder->_get('allowedControllerActions');
428 $this->assertEquals($expectedResult, $actualResult);
429 }
430
431 /**
432 * @test
433 */
434 public function buildThrowsExceptionIfDefaultControllerCantBeDetermined(): void
435 {
436 $this->expectException(Exception::class);
437 $this->expectExceptionCode(1316104317);
438 $this->configuration['controllerConfiguration'] = [];
439 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
440 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
441 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
442 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
443 $this->requestBuilder->build();
444 }
445
446 /**
447 * @test
448 */
449 public function buildSetsDefaultControllerIfNoControllerIsSpecified(): void
450 {
451 $this->injectDependencies();
452 $_GET = [
453 'tx_myextension_pi1' => [
454 'foo' => 'bar'
455 ]
456 ];
457 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
458 $this->requestBuilder->build();
459 }
460
461 /**
462 * @test
463 */
464 public function buildCorrectlySetsSpecifiedControllerNameIfItsAllowedForTheCurrentPlugin(): void
465 {
466 $this->injectDependencies();
467 $_GET = [
468 'tx_myextension_pi1' => [
469 'controller' => 'TheSecondController'
470 ]
471 ];
472 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheSecondController');
473 $this->requestBuilder->build();
474 }
475
476 /**
477 * @test
478 */
479 public function buildThrowsInvalidControllerNameExceptionIfSpecifiedControllerIsNotAllowed(): void
480 {
481 $this->expectException(InvalidControllerNameException::class);
482 $this->expectExceptionCode(1313855173);
483 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
484 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
485 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
486 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
487 $_GET = [
488 'tx_myextension_pi1' => [
489 'controller' => 'SomeInvalidController'
490 ]
491 ];
492 $this->requestBuilder->build();
493 }
494
495 /**
496 * @test
497 */
498 public function buildThrowsPageNotFoundExceptionIfEnabledAndSpecifiedControllerIsNotAllowed(): void
499 {
500 $this->expectException(PageNotFoundException::class);
501 $this->expectExceptionCode(1313857897);
502 $this->configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved'] = 1;
503 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
504 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
505 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
506 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
507 $_GET = [
508 'tx_myextension_pi1' => [
509 'controller' => 'SomeInvalidController'
510 ]
511 ];
512 $this->requestBuilder->build();
513 }
514
515 /**
516 * @test
517 */
518 public function buildSetsDefaultControllerNameIfSpecifiedControllerIsNotAllowedAndCallDefaultActionIfActionCantBeResolvedIsSet(): void
519 {
520 $this->configuration['mvc']['callDefaultActionIfActionCantBeResolved'] = 1;
521 $this->injectDependencies();
522 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
523 $_GET = [
524 'tx_myextension_pi1' => [
525 'controller' => 'SomeInvalidController'
526 ]
527 ];
528 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
529 $this->requestBuilder->build();
530 }
531
532 /**
533 * @test
534 */
535 public function buildThrowsExceptionIfDefaultActionCantBeDetermined(): void
536 {
537 $this->expectException(Exception::class);
538 $this->expectExceptionCode(1316104317);
539 $this->configuration['controllerConfiguration'] = [];
540 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
541 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
542 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
543 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
544 $this->requestBuilder->build();
545 }
546
547 /**
548 * @test
549 */
550 public function buildSetsDefaultActionOfTheCurrentControllerIfNoActionIsSpecified(): void
551 {
552 $this->injectDependencies();
553 $_GET = [
554 'tx_myextension_pi1' => [
555 'controller' => 'TheThirdController'
556 ]
557 ];
558 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('delete');
559 $this->requestBuilder->build();
560 }
561
562 /**
563 * @test
564 */
565 public function buildCorrectlySetsSpecifiedActionNameForTheDefaultControllerIfItsAllowedForTheCurrentPlugin(): void
566 {
567 $this->injectDependencies();
568 $_GET = [
569 'tx_myextension_pi1' => [
570 'action' => 'create'
571 ]
572 ];
573 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('create');
574 $this->requestBuilder->build();
575 }
576
577 /**
578 * @test
579 */
580 public function buildCorrectlySetsSpecifiedActionNameForTheSpecifiedControllerIfItsAllowedForTheCurrentPlugin(): void
581 {
582 $this->injectDependencies();
583 $_GET = [
584 'tx_myextension_pi1' => [
585 'controller' => 'TheThirdController',
586 'action' => 'onlyInThirdController'
587 ]
588 ];
589 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('onlyInThirdController');
590 $this->requestBuilder->build();
591 }
592
593 /**
594 * @test
595 */
596 public function buildThrowsInvalidActionNameExceptionIfSpecifiedActionIsNotAllowed(): void
597 {
598 $this->expectException(InvalidActionNameException::class);
599 $this->expectExceptionCode(1313855175);
600 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
601 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
602 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
603 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
604 $_GET = [
605 'tx_myextension_pi1' => [
606 'action' => 'someInvalidAction'
607 ]
608 ];
609 $this->requestBuilder->build();
610 }
611
612 /**
613 * @test
614 */
615 public function buildThrowsPageNotFoundExceptionIfEnabledAndSpecifiedActionIsNotAllowed(): void
616 {
617 $this->expectException(PageNotFoundException::class);
618 $this->expectExceptionCode(1313857898);
619 $this->configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved'] = 1;
620 $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
621 $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
622 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
623 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
624 $_GET = [
625 'tx_myextension_pi1' => [
626 'action' => 'someInvalidAction'
627 ]
628 ];
629 $this->requestBuilder->build();
630 }
631
632 /**
633 * @test
634 */
635 public function buildSetsDefaultActionNameIfSpecifiedActionIsNotAllowedAndCallDefaultActionIfActionCantBeResolvedIsSet(): void
636 {
637 $this->configuration['mvc']['callDefaultActionIfActionCantBeResolved'] = 1;
638 $this->injectDependencies();
639 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
640 $_GET = [
641 'tx_myextension_pi1' => [
642 'controller' => 'TheThirdController',
643 'action' => 'someInvalidAction'
644 ]
645 ];
646 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheThirdController');
647 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('delete');
648 $this->requestBuilder->build();
649 }
650
651 /**
652 * @test
653 * @see TYPO3\Flow\Tests\Unit\Utility\EnvironmentTest
654 */
655 public function untangleFilesArrayTransformsTheFilesSuperglobalIntoAManageableForm(): void
656 {
657 $convolutedFiles = [
658 'a0' => [
659 'name' => [
660 'a1' => 'a.txt'
661 ],
662 'type' => [
663 'a1' => 'text/plain'
664 ],
665 'tmp_name' => [
666 'a1' => '/private/var/tmp/phpbqXsYt'
667 ],
668 'error' => [
669 'a1' => 0
670 ],
671 'size' => [
672 'a1' => 100
673 ]
674 ],
675 'b0' => [
676 'name' => [
677 'b1' => 'b.txt'
678 ],
679 'type' => [
680 'b1' => 'text/plain'
681 ],
682 'tmp_name' => [
683 'b1' => '/private/var/tmp/phpvZ6oUD'
684 ],
685 'error' => [
686 'b1' => 0
687 ],
688 'size' => [
689 'b1' => 200
690 ]
691 ],
692 'c' => [
693 'name' => 'c.txt',
694 'type' => 'text/plain',
695 'tmp_name' => '/private/var/tmp/phpS9KMNw',
696 'error' => 0,
697 'size' => 300
698 ],
699 'd0' => [
700 'name' => [
701 'd1' => [
702 0 => 'd12.txt',
703 'd2' => [
704 'd3' => 'd.txt'
705 ]
706 ]
707 ],
708 'type' => [
709 'd1' => [
710 0 => 'text/plain',
711 'd2' => [
712 'd3' => 'text/plain'
713 ]
714 ]
715 ],
716 'tmp_name' => [
717 'd1' => [
718 0 => '/private/var/tmp/phpMf9Qx9',
719 'd2' => [
720 'd3' => '/private/var/tmp/phprR3fax'
721 ]
722 ]
723 ],
724 'error' => [
725 'd1' => [
726 0 => 0,
727 'd2' => [
728 'd3' => 0
729 ]
730 ]
731 ],
732 'size' => [
733 'd1' => [
734 0 => 200,
735 'd2' => [
736 'd3' => 400
737 ]
738 ]
739 ]
740 ],
741 'e0' => [
742 'name' => [
743 'e1' => [
744 'e2' => [
745 0 => 'e_one.txt',
746 1 => 'e_two.txt'
747 ]
748 ]
749 ],
750 'type' => [
751 'e1' => [
752 'e2' => [
753 0 => 'text/plain',
754 1 => 'text/plain'
755 ]
756 ]
757 ],
758 'tmp_name' => [
759 'e1' => [
760 'e2' => [
761 0 => '/private/var/tmp/php01fitB',
762 1 => '/private/var/tmp/phpUUB2cv'
763 ]
764 ]
765 ],
766 'error' => [
767 'e1' => [
768 'e2' => [
769 0 => 0,
770 1 => 0
771 ]
772 ]
773 ],
774 'size' => [
775 'e1' => [
776 'e2' => [
777 0 => 510,
778 1 => 520
779 ]
780 ]
781 ]
782 ],
783 'error' => [
784 'name' => 'error_file.txt',
785 'type' => 'text/plain',
786 'tmp_name' => '/private/var/tmp/phpADDu87fE',
787 'error' => 0,
788 'size' => 120
789 ]
790 ];
791 $untangledFiles = [
792 'a0' => [
793 'a1' => [
794 'name' => 'a.txt',
795 'type' => 'text/plain',
796 'tmp_name' => '/private/var/tmp/phpbqXsYt',
797 'error' => 0,
798 'size' => 100
799 ]
800 ],
801 'b0' => [
802 'b1' => [
803 'name' => 'b.txt',
804 'type' => 'text/plain',
805 'tmp_name' => '/private/var/tmp/phpvZ6oUD',
806 'error' => 0,
807 'size' => 200
808 ]
809 ],
810 'c' => [
811 'name' => 'c.txt',
812 'type' => 'text/plain',
813 'tmp_name' => '/private/var/tmp/phpS9KMNw',
814 'error' => 0,
815 'size' => 300
816 ],
817 'd0' => [
818 'd1' => [
819 0 => [
820 'name' => 'd12.txt',
821 'type' => 'text/plain',
822 'tmp_name' => '/private/var/tmp/phpMf9Qx9',
823 'error' => 0,
824 'size' => 200
825 ],
826 'd2' => [
827 'd3' => [
828 'name' => 'd.txt',
829 'type' => 'text/plain',
830 'tmp_name' => '/private/var/tmp/phprR3fax',
831 'error' => 0,
832 'size' => 400
833 ]
834 ]
835 ]
836 ],
837 'e0' => [
838 'e1' => [
839 'e2' => [
840 0 => [
841 'name' => 'e_one.txt',
842 'type' => 'text/plain',
843 'tmp_name' => '/private/var/tmp/php01fitB',
844 'error' => 0,
845 'size' => 510
846 ],
847 1 => [
848 'name' => 'e_two.txt',
849 'type' => 'text/plain',
850 'tmp_name' => '/private/var/tmp/phpUUB2cv',
851 'error' => 0,
852 'size' => 520
853 ]
854 ]
855 ]
856 ],
857 'error' => [
858 'name' => 'error_file.txt',
859 'type' => 'text/plain',
860 'tmp_name' => '/private/var/tmp/phpADDu87fE',
861 'error' => 0,
862 'size' => 120
863 ]
864 ];
865 $requestBuilder = $this->getAccessibleMock(RequestBuilder::class, ['dummy'], [], '', false);
866 $result = $requestBuilder->_call('untangleFilesArray', $convolutedFiles);
867 $this->assertSame($untangledFiles, $result);
868 }
869 }