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