|
| 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