[TASK] Introduce runtime cache for getIndpEnv()
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Testcase for \TYPO3\CMS\Core\Http\ServerRequestFactory
23 */
24 class ServerRequestFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * Set up
28 */
29 protected function setUp() {
30 GeneralUtility::flushInternalRuntimeCaches();
31 }
32
33 /**
34 * @test
35 */
36 public function uploadedFilesAreNormalizedFromFilesSuperGlobal() {
37 $_SERVER['HTTP_HOST'] = 'localhost';
38 $_SERVER['REQUEST_URI'] = '/index.php';
39 $_FILES = array(
40 'tx_uploadexample_piexample' => array(
41 'name' => array(
42 'newExample' => array(
43 'image' => 'o51pb.jpg',
44 'imageCollection' => array(
45 0 => 'composer.json',
46 ),
47 ),
48 ),
49 'type' => array(
50 'newExample' => array(
51 'image' => 'image/jpeg',
52 'imageCollection' => array(
53 0 => 'application/json'
54 )
55 )
56 ),
57 'tmp_name' => array(
58 'newExample' => array(
59 'image' => '/Applications/MAMP/tmp/php/phphXdbcd',
60 'imageCollection' => array(
61 0 => '/Applications/MAMP/tmp/php/phpgrZ4bb'
62 )
63 )
64 ),
65 'error' => array(
66 'newExample' => array(
67 'image' => 0,
68 'imageCollection' => array(
69 0 => 0
70 )
71 )
72 ),
73 'size' => array(
74 'newExample' => array(
75 'image' => 59065,
76 'imageCollection' => array(
77 0 => 683
78 )
79 )
80 )
81 )
82 );
83
84 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
85
86 $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['image']);
87 $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['image'] instanceof UploadedFile);
88 $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0]);
89 $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0] instanceof UploadedFile);
90 }
91
92 /**
93 * @test
94 */
95 public function uploadedFilesAreNotCreatedForEmptyFilesArray() {
96 $_SERVER['HTTP_HOST'] = 'localhost';
97 $_SERVER['REQUEST_URI'] = '/index.php';
98 $_FILES = array();
99
100 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
101
102 $this->assertEmpty($uploadedFiles);
103 }
104
105 /**
106 * @test
107 */
108 public function uploadedFilesAreNotCreatedIfTmpNameIsEmpty() {
109 $_SERVER['HTTP_HOST'] = 'localhost';
110 $_SERVER['REQUEST_URI'] = '/index.php';
111 $_FILES = array(
112 'tx_uploadexample_piexample' => array(
113 'name' => '',
114 'tmp_name' => '',
115 'error' => 4,
116 'size' => 0,
117 ),
118 );
119
120 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
121
122 $this->assertEmpty($uploadedFiles);
123 }
124
125 }