| 1 |
<?php |
| 2 |
|
| 3 |
namespace FileUtil\Tests; |
| 4 |
|
| 5 |
use PHPUnit\Framework\TestCase; |
| 6 |
use FileUtil\PathValidator; |
| 7 |
use org\bovigo\vfs\vfsStream; |
| 8 |
|
| 9 |
class PathValidatorTest extends TestCase |
| 10 |
{ |
| 11 |
public function testFilenameNotString() |
| 12 |
{ |
| 13 |
$this->expectException(\Exception::class); |
| 14 |
PathValidator::checkPath(10); |
| 15 |
//$this->mimeSniff(10); |
| 16 |
} |
| 17 |
|
| 18 |
public function testFilenameHasNULChar() |
| 19 |
{ |
| 20 |
$this->expectException(\Exception::class); |
| 21 |
PathValidator::checkPath("a\0"); |
| 22 |
} |
| 23 |
public function testFilenameHasControlChars() |
| 24 |
{ |
| 25 |
$this->expectException(\Exception::class); |
| 26 |
PathValidator::checkPath("..\1.."); |
| 27 |
} |
| 28 |
|
| 29 |
public function testFilenameIsEmpty() |
| 30 |
{ |
| 31 |
$this->expectException(\Exception::class); |
| 32 |
PathValidator::checkPath(""); |
| 33 |
} |
| 34 |
|
| 35 |
public function testFilenameIsPhar() |
| 36 |
{ |
| 37 |
$this->expectException(\Exception::class); |
| 38 |
PathValidator::checkPath('phar://aoeu'); |
| 39 |
} |
| 40 |
|
| 41 |
public function testFileNotFound() |
| 42 |
{ |
| 43 |
// why does this fail in PHP 7.2 ? (Uninitialized string offset: 0) |
| 44 |
$this->expectException(\Exception::class); |
| 45 |
PathValidator::checkFilePathIsRegularFile(__DIR__ . '/images/no-such-file.jpg'); |
| 46 |
} |
| 47 |
public function testFileIsDir() |
| 48 |
{ |
| 49 |
$this->expectException(\Exception::class); |
| 50 |
PathValidator::checkFilePathIsRegularFile(__DIR__ . '/images'); |
| 51 |
} |
| 52 |
|
| 53 |
public function testFileOnWebNotFound() |
| 54 |
{ |
| 55 |
// why does this fail in PHP 7.2 ? (Uninitialized string offset: 0) |
| 56 |
$this->expectException(\Exception::class); |
| 57 |
PathValidator::checkFilePathIsRegularFile('http://aoeuhtaoeu.eau'); |
| 58 |
} |
| 59 |
|
| 60 |
public function testPhPStreamWrapper() |
| 61 |
{ |
| 62 |
$this->expectException(\Exception::class); |
| 63 |
PathValidator::checkFilePathIsRegularFile('php://input'); |
| 64 |
} |
| 65 |
} |
| 66 |
|