[TASK] typo3/testing-framework now flushes runtime caches
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Http / ServerRequestFactoryTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Http;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Http\ServerRequestFactory;
19 use TYPO3\CMS\Core\Http\UploadedFile;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Testcase for \TYPO3\CMS\Core\Http\ServerRequestFactory
24 */
25 class ServerRequestFactoryTest extends UnitTestCase
26 {
27 /**
28 * @test
29 */
30 public function uploadedFilesAreNormalizedFromFilesSuperGlobal()
31 {
32 $_SERVER['HTTP_HOST'] = 'localhost';
33 $_SERVER['REQUEST_URI'] = '/index.php';
34 $_SERVER['REMOTE_ADDR'] = '';
35 $_SERVER['SSL_SESSION_ID'] = '';
36 $_FILES = [
37 'tx_uploadexample_piexample' => [
38 'name' => [
39 'newExample' => [
40 'image' => 'o51pb.jpg',
41 'imageCollection' => [
42 0 => 'composer.json',
43 ],
44 ],
45 ],
46 'type' => [
47 'newExample' => [
48 'image' => 'image/jpeg',
49 'imageCollection' => [
50 0 => 'application/json'
51 ]
52 ]
53 ],
54 'tmp_name' => [
55 'newExample' => [
56 'image' => '/Applications/MAMP/tmp/php/phphXdbcd',
57 'imageCollection' => [
58 0 => '/Applications/MAMP/tmp/php/phpgrZ4bb'
59 ]
60 ]
61 ],
62 'error' => [
63 'newExample' => [
64 'image' => 0,
65 'imageCollection' => [
66 0 => 0
67 ]
68 ]
69 ],
70 'size' => [
71 'newExample' => [
72 'image' => 59065,
73 'imageCollection' => [
74 0 => 683
75 ]
76 ]
77 ]
78 ]
79 ];
80
81 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
82
83 $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['image']);
84 $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['image'] instanceof UploadedFile);
85 $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0]);
86 $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0] instanceof UploadedFile);
87 }
88
89 /**
90 * @test
91 */
92 public function uploadedFilesAreNotCreatedForEmptyFilesArray()
93 {
94 $_SERVER['HTTP_HOST'] = 'localhost';
95 $_SERVER['REQUEST_URI'] = '/index.php';
96 $_SERVER['REMOTE_ADDR'] = '';
97 $_SERVER['SSL_SESSION_ID'] = '';
98 $_FILES = [];
99
100 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
101
102 $this->assertEmpty($uploadedFiles);
103 }
104
105 /**
106 * @test
107 */
108 public function uploadedFilesAreNotCreatedIfTmpNameIsEmpty()
109 {
110 $_SERVER['HTTP_HOST'] = 'localhost';
111 $_SERVER['REQUEST_URI'] = '/index.php';
112 $_SERVER['REMOTE_ADDR'] = '';
113 $_SERVER['SSL_SESSION_ID'] = '';
114 $_FILES = [
115 'tx_uploadexample_piexample' => [
116 'name' => '',
117 'tmp_name' => '',
118 'error' => 4,
119 'size' => 0,
120 ],
121 ];
122
123 $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
124
125 $this->assertEmpty($uploadedFiles);
126 }
127 }