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