TYPO3 CMS  TYPO3_8-7
ServerRequestFactoryTest.php
Go to the documentation of this file.
1 <?php
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 
19 
23 class ServerRequestFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
29  {
30  $_SERVER['HTTP_HOST'] = 'localhost';
31  $_SERVER['REQUEST_URI'] = '/index.php';
32  $_FILES = [
33  'tx_uploadexample_piexample' => [
34  'name' => [
35  'newExample' => [
36  'image' => 'o51pb.jpg',
37  'imageCollection' => [
38  0 => 'composer.json',
39  ],
40  ],
41  ],
42  'type' => [
43  'newExample' => [
44  'image' => 'image/jpeg',
45  'imageCollection' => [
46  0 => 'application/json'
47  ]
48  ]
49  ],
50  'tmp_name' => [
51  'newExample' => [
52  'image' => '/Applications/MAMP/tmp/php/phphXdbcd',
53  'imageCollection' => [
54  0 => '/Applications/MAMP/tmp/php/phpgrZ4bb'
55  ]
56  ]
57  ],
58  'error' => [
59  'newExample' => [
60  'image' => 0,
61  'imageCollection' => [
62  0 => 0
63  ]
64  ]
65  ],
66  'size' => [
67  'newExample' => [
68  'image' => 59065,
69  'imageCollection' => [
70  0 => 683
71  ]
72  ]
73  ]
74  ]
75  ];
76 
77  $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
78 
79  $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['image']);
80  $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['image'] instanceof UploadedFile);
81  $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0]);
82  $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0] instanceof UploadedFile);
83  }
84 
89  {
90  $_SERVER['HTTP_HOST'] = 'localhost';
91  $_SERVER['REQUEST_URI'] = '/index.php';
92  $_FILES = [];
93 
94  $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
95 
96  $this->assertEmpty($uploadedFiles);
97  }
98 
103  {
104  $_SERVER['HTTP_HOST'] = 'localhost';
105  $_SERVER['REQUEST_URI'] = '/index.php';
106  $_FILES = [
107  'tx_uploadexample_piexample' => [
108  'name' => '',
109  'tmp_name' => '',
110  'error' => 4,
111  'size' => 0,
112  ],
113  ];
114 
115  $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
116 
117  $this->assertEmpty($uploadedFiles);
118  }
119 }