72633a6bb7dc4e8265d51cf18b739fdc0284db4e
[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 'TheFirstController' => [
84 'actions' => ['show', 'index', 'new', 'create', 'delete', 'edit', 'update', 'setup', 'test']
85 ],
86 'TheSecondController' => [
87 'actions' => ['show', 'index']
88 ],
89 'TheThirdController' => [
90 'actions' => ['delete', 'create', 'onlyInThirdController']
91 ]
92 ]
93 ];
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'])
100 ->getMock();
101 }
102
103 /**
104 */
105 protected function injectDependencies(): void
106 {
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);
116 }
117
118 /**
119 * @test
120 */
121 public function buildReturnsAWebRequestObject(): void
122 {
123 $this->injectDependencies();
124 $request = $this->requestBuilder->build();
125 $this->assertSame($this->mockRequest, $request);
126 }
127
128 /**
129 * @test
130 */
131 public function buildSetsRequestPluginName(): void
132 {
133 $this->injectDependencies();
134 $this->mockRequest->expects($this->once())->method('setPluginName')->with('Pi1');
135 $this->requestBuilder->build();
136 }
137
138 /**
139 * @test
140 */
141 public function buildSetsRequestControllerExtensionName(): void
142 {
143 $this->injectDependencies();
144 $this->mockRequest->expects($this->once())->method('setControllerExtensionName')->with('MyExtension');
145 $this->requestBuilder->build();
146 }
147
148 /**
149 * @test
150 */
151 public function buildSetsRequestControllerName(): void
152 {
153 $this->injectDependencies();
154 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
155 $this->requestBuilder->build();
156 }
157
158 /**
159 * @test
160 */
161 public function buildSetsRequestControllerActionName(): void
162 {
163 $this->injectDependencies();
164 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('show');
165 $this->requestBuilder->build();
166 }
167
168 /**
169 * @test
170 */
171 public function buildSetsRequestRequestUri(): void
172 {
173 $this->injectDependencies();
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();
177 }
178
179 /**
180 * @test
181 */
182 public function buildSetsRequestBaseUri(): void
183 {
184 $this->injectDependencies();
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();
188 }
189
190 /**
191 * @test
192 */
193 public function buildSetsRequestMethod(): void
194 {
195 $this->injectDependencies();
196 $expectedMethod = 'SomeRequestMethod';
197 $mockEnvironmentService = $this->getMockBuilder(EnvironmentService::class)
198 ->setMethods(['getServerRequestMethod'])
199 ->getMock();
200 $mockEnvironmentService->expects($this->once())->method('getServerRequestMethod')->will($this->returnValue($expectedMethod));
201 $this->requestBuilder->_set('environmentService', $mockEnvironmentService);
202 $this->mockRequest->expects($this->once())->method('setMethod')->with($expectedMethod);
203 $this->requestBuilder->build();
204 }
205
206 /**
207 * @test
208 */
209 public function buildSetsVendorNameIfConfigured(): void
210 {
211 $this->injectDependencies();
212 $expectedVendor = 'Vendor';
213 $this->configuration['vendorName'] = $expectedVendor;
214 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
215 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
216 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
217 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
218 $this->mockRequest->expects($this->once())->method('setControllerVendorName')->with($expectedVendor);
219 $this->requestBuilder->build();
220 }
221
222 /**
223 * @test
224 */
225 public function buildDoesNotSetVendorNameIfNotConfiguredInSecondRequest(): void
226 {
227 $this->injectDependencies();
228 $expectedVendor = 'Vendor';
229 $this->configuration['vendorName'] = $expectedVendor;
230
231 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
232 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
233 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
234 $this->mockRequest->expects($this->once())->method('setControllerVendorName')->with($expectedVendor);
235
236 $this->requestBuilder->build();
237
238 unset($this->configuration['vendorName']);
239 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
240 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
241 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
242
243 $this->mockRequest->expects($this->never())->method('setControllerVendorName');
244 $this->requestBuilder->build();
245 }
246
247 /**
248 * @test
249 */
250 public function buildThrowsExceptionIfExtensionNameIsNotConfigured(): void
251 {
252 $this->expectException(Exception::class);
253 $this->expectExceptionCode(1289843275);
254 unset($this->configuration['extensionName']);
255 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
256 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
257 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
258 $this->requestBuilder->build();
259 }
260
261 /**
262 * @test
263 */
264 public function buildThrowsExceptionIfPluginNameIsNotConfigured(): void
265 {
266 $this->expectException(Exception::class);
267 $this->expectExceptionCode(1289843277);
268 unset($this->configuration['pluginName']);
269 $mockConfigurationManager = $this->createMock(ConfigurationManagerInterface::class);
270 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
271 $this->requestBuilder->_set('configurationManager', $mockConfigurationManager);
272 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
273 $this->requestBuilder->build();
274 }
275
276 /**
277 * @test
278 */
279 public function buildThrowsExceptionIfControllerConfigurationIsEmptyOrNotSet(): void
280 {
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();
288 }
289
290 /**
291 * @test
292 */
293 public function buildThrowsExceptionIfControllerConfigurationHasNoDefaultActionDefined(): void
294 {
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();
302 }
303
304 /**
305 * @test
306 */
307 public function buildThrowsExceptionIfNoDefaultControllerCanBeResolved(): void
308 {
309 $this->expectException(Exception::class);
310 $this->expectExceptionCode(1316104317);
311 $this->configuration['controllerConfiguration'] = [
312 '' => [
313 'actions' => ['foo']
314 ]
315 ];
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();
320 }
321
322 /**
323 * @test
324 */
325 public function buildSetsParametersFromGetAndPostVariables(): void
326 {
327 $this->configuration['extensionName'] = 'SomeExtensionName';
328 $this->configuration['pluginName'] = 'SomePluginName';
329 $this->injectDependencies();
330 $_GET = [
331 'tx_someotherextensionname_somepluginname' => [
332 'foo' => 'bar'
333 ],
334 'tx_someextensionname_somepluginname' => [
335 'parameter1' => 'valueGetsOverwritten',
336 'parameter2' => [
337 'parameter3' => 'value3'
338 ]
339 ]
340 ];
341 $_POST = [
342 'tx_someextensionname_someotherpluginname' => [
343 'foo' => 'bar'
344 ],
345 'tx_someextensionname_somepluginname' => [
346 'parameter1' => 'value1',
347 'parameter2' => [
348 'parameter4' => 'value4'
349 ]
350 ]
351 ];
352 $this->mockRequest->expects($this->at(8))->method('setArgument')->with('parameter1', 'value1');
353 $this->mockRequest->expects($this->at(9))->method('setArgument')->with(
354 'parameter2',
355 ['parameter3' => 'value3', 'parameter4' => 'value4']
356 );
357 $this->requestBuilder->build();
358 }
359
360 /**
361 * @test
362 */
363 public function buildSetsFormatFromGetAndPostVariables(): void
364 {
365 $this->configuration['extensionName'] = 'SomeExtensionName';
366 $this->configuration['pluginName'] = 'SomePluginName';
367 $this->injectDependencies();
368 $_GET = [
369 'tx_someextensionname_somepluginname' => [
370 'format' => 'GET'
371 ]
372 ];
373 $_POST = [
374 'tx_someextensionname_somepluginname' => [
375 'format' => 'POST'
376 ]
377 ];
378 $this->mockRequest->expects($this->at(7))->method('setFormat')->with('POST');
379 $this->requestBuilder->build();
380 }
381
382 /**
383 * @test
384 */
385 public function buildCorrectlySetsAllowedControllerActions(): void
386 {
387 $this->injectDependencies();
388 $expectedResult = [
389 'TheFirstController' => [
390 'show',
391 'index',
392 'new',
393 'create',
394 'delete',
395 'edit',
396 'update',
397 'setup',
398 'test'
399 ],
400 'TheSecondController' => [
401 'show',
402 'index'
403 ],
404 'TheThirdController' => [
405 'delete',
406 'create',
407 'onlyInThirdController'
408 ]
409 ];
410 $this->requestBuilder->build();
411 $actualResult = $this->requestBuilder->_get('allowedControllerActions');
412 $this->assertEquals($expectedResult, $actualResult);
413 }
414
415 /**
416 * @test
417 */
418 public function buildThrowsExceptionIfDefaultControllerCantBeDetermined(): void
419 {
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();
428 }
429
430 /**
431 * @test
432 */
433 public function buildSetsDefaultControllerIfNoControllerIsSpecified(): void
434 {
435 $this->injectDependencies();
436 $_GET = [
437 'tx_myextension_pi1' => [
438 'foo' => 'bar'
439 ]
440 ];
441 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
442 $this->requestBuilder->build();
443 }
444
445 /**
446 * @test
447 */
448 public function buildCorrectlySetsSpecifiedControllerNameIfItsAllowedForTheCurrentPlugin(): void
449 {
450 $this->injectDependencies();
451 $_GET = [
452 'tx_myextension_pi1' => [
453 'controller' => 'TheSecondController'
454 ]
455 ];
456 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheSecondController');
457 $this->requestBuilder->build();
458 }
459
460 /**
461 * @test
462 */
463 public function buildThrowsInvalidControllerNameExceptionIfSpecifiedControllerIsNotAllowed(): void
464 {
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);
471 $_GET = [
472 'tx_myextension_pi1' => [
473 'controller' => 'SomeInvalidController'
474 ]
475 ];
476 $this->requestBuilder->build();
477 }
478
479 /**
480 * @test
481 */
482 public function buildThrowsPageNotFoundExceptionIfEnabledAndSpecifiedControllerIsNotAllowed(): void
483 {
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);
491 $_GET = [
492 'tx_myextension_pi1' => [
493 'controller' => 'SomeInvalidController'
494 ]
495 ];
496 $this->requestBuilder->build();
497 }
498
499 /**
500 * @test
501 */
502 public function buildSetsDefaultControllerNameIfSpecifiedControllerIsNotAllowedAndCallDefaultActionIfActionCantBeResolvedIsSet(): void
503 {
504 $this->configuration['mvc']['callDefaultActionIfActionCantBeResolved'] = 1;
505 $this->injectDependencies();
506 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
507 $_GET = [
508 'tx_myextension_pi1' => [
509 'controller' => 'SomeInvalidController'
510 ]
511 ];
512 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
513 $this->requestBuilder->build();
514 }
515
516 /**
517 * @test
518 */
519 public function buildThrowsExceptionIfDefaultActionCantBeDetermined(): void
520 {
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();
529 }
530
531 /**
532 * @test
533 */
534 public function buildSetsDefaultActionOfTheCurrentControllerIfNoActionIsSpecified(): void
535 {
536 $this->injectDependencies();
537 $_GET = [
538 'tx_myextension_pi1' => [
539 'controller' => 'TheThirdController'
540 ]
541 ];
542 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('delete');
543 $this->requestBuilder->build();
544 }
545
546 /**
547 * @test
548 */
549 public function buildCorrectlySetsSpecifiedActionNameForTheDefaultControllerIfItsAllowedForTheCurrentPlugin(): void
550 {
551 $this->injectDependencies();
552 $_GET = [
553 'tx_myextension_pi1' => [
554 'action' => 'create'
555 ]
556 ];
557 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('create');
558 $this->requestBuilder->build();
559 }
560
561 /**
562 * @test
563 */
564 public function buildCorrectlySetsSpecifiedActionNameForTheSpecifiedControllerIfItsAllowedForTheCurrentPlugin(): void
565 {
566 $this->injectDependencies();
567 $_GET = [
568 'tx_myextension_pi1' => [
569 'controller' => 'TheThirdController',
570 'action' => 'onlyInThirdController'
571 ]
572 ];
573 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('onlyInThirdController');
574 $this->requestBuilder->build();
575 }
576
577 /**
578 * @test
579 */
580 public function buildThrowsInvalidActionNameExceptionIfSpecifiedActionIsNotAllowed(): void
581 {
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);
588 $_GET = [
589 'tx_myextension_pi1' => [
590 'action' => 'someInvalidAction'
591 ]
592 ];
593 $this->requestBuilder->build();
594 }
595
596 /**
597 * @test
598 */
599 public function buildThrowsPageNotFoundExceptionIfEnabledAndSpecifiedActionIsNotAllowed(): void
600 {
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);
608 $_GET = [
609 'tx_myextension_pi1' => [
610 'action' => 'someInvalidAction'
611 ]
612 ];
613 $this->requestBuilder->build();
614 }
615
616 /**
617 * @test
618 */
619 public function buildSetsDefaultActionNameIfSpecifiedActionIsNotAllowedAndCallDefaultActionIfActionCantBeResolvedIsSet(): void
620 {
621 $this->configuration['mvc']['callDefaultActionIfActionCantBeResolved'] = 1;
622 $this->injectDependencies();
623 $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
624 $_GET = [
625 'tx_myextension_pi1' => [
626 'controller' => 'TheThirdController',
627 'action' => 'someInvalidAction'
628 ]
629 ];
630 $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheThirdController');
631 $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('delete');
632 $this->requestBuilder->build();
633 }
634
635 /**
636 * @test
637 * @see TYPO3\Flow\Tests\Unit\Utility\EnvironmentTest
638 */
639 public function untangleFilesArrayTransformsTheFilesSuperglobalIntoAManageableForm(): void
640 {
641 $convolutedFiles = [
642 'a0' => [
643 'name' => [
644 'a1' => 'a.txt'
645 ],
646 'type' => [
647 'a1' => 'text/plain'
648 ],
649 'tmp_name' => [
650 'a1' => '/private/var/tmp/phpbqXsYt'
651 ],
652 'error' => [
653 'a1' => 0
654 ],
655 'size' => [
656 'a1' => 100
657 ]
658 ],
659 'b0' => [
660 'name' => [
661 'b1' => 'b.txt'
662 ],
663 'type' => [
664 'b1' => 'text/plain'
665 ],
666 'tmp_name' => [
667 'b1' => '/private/var/tmp/phpvZ6oUD'
668 ],
669 'error' => [
670 'b1' => 0
671 ],
672 'size' => [
673 'b1' => 200
674 ]
675 ],
676 'c' => [
677 'name' => 'c.txt',
678 'type' => 'text/plain',
679 'tmp_name' => '/private/var/tmp/phpS9KMNw',
680 'error' => 0,
681 'size' => 300
682 ],
683 'd0' => [
684 'name' => [
685 'd1' => [
686 0 => 'd12.txt',
687 'd2' => [
688 'd3' => 'd.txt'
689 ]
690 ]
691 ],
692 'type' => [
693 'd1' => [
694 0 => 'text/plain',
695 'd2' => [
696 'd3' => 'text/plain'
697 ]
698 ]
699 ],
700 'tmp_name' => [
701 'd1' => [
702 0 => '/private/var/tmp/phpMf9Qx9',
703 'd2' => [
704 'd3' => '/private/var/tmp/phprR3fax'
705 ]
706 ]
707 ],
708 'error' => [
709 'd1' => [
710 0 => 0,
711 'd2' => [
712 'd3' => 0
713 ]
714 ]
715 ],
716 'size' => [
717 'd1' => [
718 0 => 200,
719 'd2' => [
720 'd3' => 400
721 ]
722 ]
723 ]
724 ],
725 'e0' => [
726 'name' => [
727 'e1' => [
728 'e2' => [
729 0 => 'e_one.txt',
730 1 => 'e_two.txt'
731 ]
732 ]
733 ],
734 'type' => [
735 'e1' => [
736 'e2' => [
737 0 => 'text/plain',
738 1 => 'text/plain'
739 ]
740 ]
741 ],
742 'tmp_name' => [
743 'e1' => [
744 'e2' => [
745 0 => '/private/var/tmp/php01fitB',
746 1 => '/private/var/tmp/phpUUB2cv'
747 ]
748 ]
749 ],
750 'error' => [
751 'e1' => [
752 'e2' => [
753 0 => 0,
754 1 => 0
755 ]
756 ]
757 ],
758 'size' => [
759 'e1' => [
760 'e2' => [
761 0 => 510,
762 1 => 520
763 ]
764 ]
765 ]
766 ],
767 'error' => [
768 'name' => 'error_file.txt',
769 'type' => 'text/plain',
770 'tmp_name' => '/private/var/tmp/phpADDu87fE',
771 'error' => 0,
772 'size' => 120
773 ]
774 ];
775 $untangledFiles = [
776 'a0' => [
777 'a1' => [
778 'name' => 'a.txt',
779 'type' => 'text/plain',
780 'tmp_name' => '/private/var/tmp/phpbqXsYt',
781 'error' => 0,
782 'size' => 100
783 ]
784 ],
785 'b0' => [
786 'b1' => [
787 'name' => 'b.txt',
788 'type' => 'text/plain',
789 'tmp_name' => '/private/var/tmp/phpvZ6oUD',
790 'error' => 0,
791 'size' => 200
792 ]
793 ],
794 'c' => [
795 'name' => 'c.txt',
796 'type' => 'text/plain',
797 'tmp_name' => '/private/var/tmp/phpS9KMNw',
798 'error' => 0,
799 'size' => 300
800 ],
801 'd0' => [
802 'd1' => [
803 0 => [
804 'name' => 'd12.txt',
805 'type' => 'text/plain',
806 'tmp_name' => '/private/var/tmp/phpMf9Qx9',
807 'error' => 0,
808 'size' => 200
809 ],
810 'd2' => [
811 'd3' => [
812 'name' => 'd.txt',
813 'type' => 'text/plain',
814 'tmp_name' => '/private/var/tmp/phprR3fax',
815 'error' => 0,
816 'size' => 400
817 ]
818 ]
819 ]
820 ],
821 'e0' => [
822 'e1' => [
823 'e2' => [
824 0 => [
825 'name' => 'e_one.txt',
826 'type' => 'text/plain',
827 'tmp_name' => '/private/var/tmp/php01fitB',
828 'error' => 0,
829 'size' => 510
830 ],
831 1 => [
832 'name' => 'e_two.txt',
833 'type' => 'text/plain',
834 'tmp_name' => '/private/var/tmp/phpUUB2cv',
835 'error' => 0,
836 'size' => 520
837 ]
838 ]
839 ]
840 ],
841 'error' => [
842 'name' => 'error_file.txt',
843 'type' => 'text/plain',
844 'tmp_name' => '/private/var/tmp/phpADDu87fE',
845 'error' => 0,
846 'size' => 120
847 ]
848 ];
849 $requestBuilder = $this->getAccessibleMock(RequestBuilder::class, ['dummy'], [], '', false);
850 $result = $requestBuilder->_call('untangleFilesArray', $convolutedFiles);
851 $this->assertSame($untangledFiles, $result);
852 }
853 }