Skip to content

Commit 08f1f67

Browse files
committed
Test extension guessing
1 parent 3731166 commit 08f1f67

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

system/HTTP/Files/UploadedFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ public function getTempName(): string
342342
*
343343
* Is simply an alias for guessExtension for a safer method
344344
* than simply relying on the provided extension.
345-
* Additionaly it will return clientExtension in case if there are
346-
* other extensions withe the same mime type.
345+
* Additionally it will return clientExtension in case if there are
346+
* other extensions with the same mime type.
347347
*/
348348
public function getExtension(): string
349349
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
namespace CodeIgniter\HTTP\Files;
3+
4+
use org\bovigo\vfs\vfsStream;
5+
use CodeIgniter\HTTP\Exceptions\HTTPException;
6+
7+
class FileCollectionVFSTest extends \CIUnitTestCase
8+
{
9+
10+
public function setUp()
11+
{
12+
parent::setUp();
13+
14+
$this->root = vfsStream::setup();
15+
$this->path = '_support/HTTP/Files';
16+
vfsStream::copyFromFileSystem(TESTPATH . $this->path, $this->root);
17+
$this->start = $this->root->url() . '/';
18+
19+
$_FILES = [];
20+
}
21+
22+
public function tearDown()
23+
{
24+
parent::tearDown();
25+
$this->root = null;
26+
27+
// // cleanup folder being left behind (why?)
28+
// $leftover = WRITEPATH . 'uploads/vfs:';
29+
// if (is_dir($leftover))
30+
// {
31+
// rrmdir($leftover);
32+
// }
33+
}
34+
35+
//--------------------------------------------------------------------
36+
37+
public function testExtensionGuessing()
38+
{
39+
$_FILES = [
40+
'userfile1' => [
41+
'name' => 'fileA.txt',
42+
'type' => 'text/plain',
43+
'size' => 124,
44+
'tmp_name' => '/fileA.txt',
45+
'error' => 0,
46+
],
47+
'userfile2' => [
48+
'name' => 'fileB.txt',
49+
'type' => 'text/csv',
50+
'size' => 248,
51+
'tmp_name' => '/fileB.txt',
52+
'error' => 0,
53+
],
54+
];
55+
56+
$collection = new FileCollection();
57+
$files = $collection->all();
58+
59+
$file = array_shift($files);
60+
$this->assertInstanceOf(UploadedFile::class, $file);
61+
$this->assertEquals('txt', $file->getExtension());
62+
63+
$file = array_pop($files);
64+
$this->assertInstanceOf(UploadedFile::class, $file);
65+
$this->assertEquals('csv', $file->guessExtension());
66+
}
67+
68+
}

0 commit comments

Comments
 (0)