PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.3.1
GiveWP – Donation Plugin and Fundraising Platform v3.3.1
4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / vendor / vendor-prefixed / symfony / http-foundation / Tests / File / UploadedFileTest.php
give / vendor / vendor-prefixed / symfony / http-foundation / Tests / File Last commit date
Fixtures 2 years ago MimeType 2 years ago FakeFile.php 2 years ago FileTest.php 2 years ago UploadedFileTest.php 2 years ago
UploadedFileTest.php
302 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 *
11 * Modified by impress-org on 23-January-2024 using Strauss.
12 * @see https://github.com/BrianHenryIE/strauss
13 */
14
15 namespace Give\Vendors\Symfony\Component\HttpFoundation\Tests\File;
16
17 use PHPUnit\Framework\TestCase;
18 use Give\Vendors\Symfony\Component\HttpFoundation\File\UploadedFile;
19
20 class UploadedFileTest extends TestCase
21 {
22 protected function setUp()
23 {
24 if (!ini_get('file_uploads')) {
25 $this->markTestSkipped('file_uploads is disabled in php.ini');
26 }
27 }
28
29 public function testConstructWhenFileNotExists()
30 {
31 $this->expectException('Give\Vendors\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
32
33 new UploadedFile(
34 __DIR__.'/Fixtures/not_here',
35 'original.gif',
36 null
37 );
38 }
39
40 public function testFileUploadsWithNoMimeType()
41 {
42 $file = new UploadedFile(
43 __DIR__.'/Fixtures/test.gif',
44 'original.gif',
45 null,
46 filesize(__DIR__.'/Fixtures/test.gif'),
47 \UPLOAD_ERR_OK
48 );
49
50 $this->assertEquals('application/octet-stream', $file->getClientMimeType());
51
52 if (\extension_loaded('fileinfo')) {
53 $this->assertEquals('image/gif', $file->getMimeType());
54 }
55 }
56
57 public function testFileUploadsWithUnknownMimeType()
58 {
59 $file = new UploadedFile(
60 __DIR__.'/Fixtures/.unknownextension',
61 'original.gif',
62 null,
63 filesize(__DIR__.'/Fixtures/.unknownextension'),
64 \UPLOAD_ERR_OK
65 );
66
67 $this->assertEquals('application/octet-stream', $file->getClientMimeType());
68 }
69
70 public function testGuessClientExtension()
71 {
72 $file = new UploadedFile(
73 __DIR__.'/Fixtures/test.gif',
74 'original.gif',
75 'image/gif',
76 filesize(__DIR__.'/Fixtures/test.gif'),
77 null
78 );
79
80 $this->assertEquals('gif', $file->guessClientExtension());
81 }
82
83 public function testGuessClientExtensionWithIncorrectMimeType()
84 {
85 $file = new UploadedFile(
86 __DIR__.'/Fixtures/test.gif',
87 'original.gif',
88 'image/png',
89 filesize(__DIR__.'/Fixtures/test.gif'),
90 null
91 );
92
93 $this->assertEquals('png', $file->guessClientExtension());
94 }
95
96 public function testCaseSensitiveMimeType()
97 {
98 $file = new UploadedFile(
99 __DIR__.'/Fixtures/case-sensitive-mime-type.xlsm',
100 'test.xlsm',
101 'application/vnd.ms-excel.sheet.macroEnabled.12',
102 filesize(__DIR__.'/Fixtures/case-sensitive-mime-type.xlsm'),
103 null
104 );
105
106 $this->assertEquals('xlsm', $file->guessClientExtension());
107 }
108
109 public function testErrorIsOkByDefault()
110 {
111 $file = new UploadedFile(
112 __DIR__.'/Fixtures/test.gif',
113 'original.gif',
114 'image/gif',
115 filesize(__DIR__.'/Fixtures/test.gif'),
116 null
117 );
118
119 $this->assertEquals(\UPLOAD_ERR_OK, $file->getError());
120 }
121
122 public function testGetClientOriginalName()
123 {
124 $file = new UploadedFile(
125 __DIR__.'/Fixtures/test.gif',
126 'original.gif',
127 'image/gif',
128 filesize(__DIR__.'/Fixtures/test.gif'),
129 null
130 );
131
132 $this->assertEquals('original.gif', $file->getClientOriginalName());
133 }
134
135 public function testGetClientOriginalExtension()
136 {
137 $file = new UploadedFile(
138 __DIR__.'/Fixtures/test.gif',
139 'original.gif',
140 'image/gif',
141 filesize(__DIR__.'/Fixtures/test.gif'),
142 null
143 );
144
145 $this->assertEquals('gif', $file->getClientOriginalExtension());
146 }
147
148 public function testMoveLocalFileIsNotAllowed()
149 {
150 $this->expectException('Give\Vendors\Symfony\Component\HttpFoundation\File\Exception\FileException');
151 $file = new UploadedFile(
152 __DIR__.'/Fixtures/test.gif',
153 'original.gif',
154 'image/gif',
155 filesize(__DIR__.'/Fixtures/test.gif'),
156 \UPLOAD_ERR_OK
157 );
158
159 $file->move(__DIR__.'/Fixtures/directory');
160 }
161
162 public function testMoveLocalFileIsAllowedInTestMode()
163 {
164 $path = __DIR__.'/Fixtures/test.copy.gif';
165 $targetDir = __DIR__.'/Fixtures/directory';
166 $targetPath = $targetDir.'/test.copy.gif';
167 @unlink($path);
168 @unlink($targetPath);
169 copy(__DIR__.'/Fixtures/test.gif', $path);
170
171 $file = new UploadedFile(
172 $path,
173 'original.gif',
174 'image/gif',
175 filesize($path),
176 \UPLOAD_ERR_OK,
177 true
178 );
179
180 $movedFile = $file->move(__DIR__.'/Fixtures/directory');
181
182 $this->assertFileExists($targetPath);
183 $this->assertFileDoesNotExist($path);
184 $this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
185
186 @unlink($targetPath);
187 }
188
189 public function testGetClientOriginalNameSanitizeFilename()
190 {
191 $file = new UploadedFile(
192 __DIR__.'/Fixtures/test.gif',
193 '../../original.gif',
194 'image/gif',
195 filesize(__DIR__.'/Fixtures/test.gif'),
196 null
197 );
198
199 $this->assertEquals('original.gif', $file->getClientOriginalName());
200 }
201
202 public function testGetSize()
203 {
204 $file = new UploadedFile(
205 __DIR__.'/Fixtures/test.gif',
206 'original.gif',
207 'image/gif',
208 filesize(__DIR__.'/Fixtures/test.gif'),
209 null
210 );
211
212 $this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
213
214 $file = new UploadedFile(
215 __DIR__.'/Fixtures/test',
216 'original.gif',
217 'image/gif'
218 );
219
220 $this->assertEquals(filesize(__DIR__.'/Fixtures/test'), $file->getSize());
221 }
222
223 public function testGetExtension()
224 {
225 $file = new UploadedFile(
226 __DIR__.'/Fixtures/test.gif',
227 'original.gif',
228 null
229 );
230
231 $this->assertEquals('gif', $file->getExtension());
232 }
233
234 public function testIsValid()
235 {
236 $file = new UploadedFile(
237 __DIR__.'/Fixtures/test.gif',
238 'original.gif',
239 null,
240 filesize(__DIR__.'/Fixtures/test.gif'),
241 \UPLOAD_ERR_OK,
242 true
243 );
244
245 $this->assertTrue($file->isValid());
246 }
247
248 /**
249 * @dataProvider uploadedFileErrorProvider
250 */
251 public function testIsInvalidOnUploadError($error)
252 {
253 $file = new UploadedFile(
254 __DIR__.'/Fixtures/test.gif',
255 'original.gif',
256 null,
257 filesize(__DIR__.'/Fixtures/test.gif'),
258 $error
259 );
260
261 $this->assertFalse($file->isValid());
262 }
263
264 public function uploadedFileErrorProvider()
265 {
266 return [
267 [\UPLOAD_ERR_INI_SIZE],
268 [\UPLOAD_ERR_FORM_SIZE],
269 [\UPLOAD_ERR_PARTIAL],
270 [\UPLOAD_ERR_NO_TMP_DIR],
271 [\UPLOAD_ERR_EXTENSION],
272 ];
273 }
274
275 public function testIsInvalidIfNotHttpUpload()
276 {
277 $file = new UploadedFile(
278 __DIR__.'/Fixtures/test.gif',
279 'original.gif',
280 null,
281 filesize(__DIR__.'/Fixtures/test.gif'),
282 \UPLOAD_ERR_OK
283 );
284
285 $this->assertFalse($file->isValid());
286 }
287
288 public function testGetMaxFilesize()
289 {
290 $size = UploadedFile::getMaxFilesize();
291
292 $this->assertIsInt($size);
293 $this->assertGreaterThan(0, $size);
294
295 if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) {
296 $this->assertSame(\PHP_INT_MAX, $size);
297 } else {
298 $this->assertLessThan(\PHP_INT_MAX, $size);
299 }
300 }
301 }
302