[FEATURE] Introduce Request/Response based on PSR-7
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Http / ServerRequestFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Http;
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
17 use TYPO3\CMS\Core\Http\ServerRequestFactory;
18 use TYPO3\CMS\Core\Http\UploadedFile;
19
20 /**
21 * Testcase for \TYPO3\CMS\Core\Http\ServerRequestFactory
22 */
23 class ServerRequestFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
24
25 /**
26 * @test
27 */
28 public function uploadedFilesAreNormalizedFromFilesSuperGlobal() {
29 $_SERVER['HTTP_HOST'] = 'localhost';
30 $_SERVER['REQUEST_URI'] = '/index.php';
31 $_FILES = array(
32 'tx_uploadexample_piexample' => array(
33 'name' => array(
34 'newExample' => array(
35 'image' => 'o51pb.jpg',
36 'imageCollection' => array(
37 0 => 'composer.json',
38 ),
39 ),
40 ),
41 'type' => array(
42 'newExample' => array(
43 'image' => 'image/jpeg',
44 'imageCollection' => array(
45 0 => 'application/json'
46 )
47 )
48 ),
49 'tmp_name' => array(
50 'newExample' => array(
51 'image' => '/Applications/MAMP/tmp/php/phphXdbcd',
52 'imageCollection' => array(
53 0 => '/Applications/MAMP/tmp/php/phpgrZ4bb'
54 )
55 )
56 ),
57 'error' => array(
58 'newExample' => array(
59 'image' => 0,
60 'imageCollection' => array(
61 0 => 0
62 )
63 )
64 ),
65 'size' => array(
66 'newExample' => array(
67 'image' => 59065,
68 'imageCollection' => array(
69 0 => 683
70 )
71 )
72 )
73 )
74 );
75
76 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
77
78 $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['image']);
79 $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['image'] instanceof UploadedFile);
80 $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0]);
81 $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0] instanceof UploadedFile);
82 }
83
84 }