123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <?php
- use Grav\Framework\Filesystem\Filesystem;
- class FilesystemTest extends \Codeception\TestCase\Test
- {
- protected $class;
- protected $tests = [
- '' => [
- 'parent' => '',
- 'normalize' => '',
- 'dirname' => '',
- 'pathinfo' => [
- 'basename' => '',
- 'filename' => '',
- ]
- ],
- '.' => [
- 'parent' => '',
- 'normalize' => '',
- 'dirname' => '.',
- 'pathinfo' => [
- 'dirname' => '.',
- 'basename' => '.',
- 'extension' => '',
- 'filename' => '',
- ]
- ],
- './' => [
- 'parent' => '',
- 'normalize' => '',
- 'dirname' => '.',
- 'pathinfo' => [
- 'dirname' => '.',
- 'basename' => '.',
- 'extension' => '',
- 'filename' => '',
- ]
- ],
- '././.' => [
- 'parent' => '',
- 'normalize' => '',
- 'dirname' => './.',
- 'pathinfo' => [
- 'dirname' => './.',
- 'basename' => '.',
- 'extension' => '',
- 'filename' => '',
- ]
- ],
- '.file' => [
- 'parent' => '.',
- 'normalize' => '.file',
- 'dirname' => '.',
- 'pathinfo' => [
- 'dirname' => '.',
- 'basename' => '.file',
- 'extension' => 'file',
- 'filename' => '',
- ]
- ],
- '/' => [
- 'parent' => '',
- 'normalize' => '/',
- 'dirname' => '/',
- 'pathinfo' => [
- 'dirname' => '/',
- 'basename' => '',
- 'filename' => '',
- ]
- ],
- '/absolute' => [
- 'parent' => '/',
- 'normalize' => '/absolute',
- 'dirname' => '/',
- 'pathinfo' => [
- 'dirname' => '/',
- 'basename' => 'absolute',
- 'filename' => 'absolute',
- ]
- ],
- '/absolute/' => [
- 'parent' => '/',
- 'normalize' => '/absolute',
- 'dirname' => '/',
- 'pathinfo' => [
- 'dirname' => '/',
- 'basename' => 'absolute',
- 'filename' => 'absolute',
- ]
- ],
- '/very/long/absolute/path' => [
- 'parent' => '/very/long/absolute',
- 'normalize' => '/very/long/absolute/path',
- 'dirname' => '/very/long/absolute',
- 'pathinfo' => [
- 'dirname' => '/very/long/absolute',
- 'basename' => 'path',
- 'filename' => 'path',
- ]
- ],
- 'relative' => [
- 'parent' => '.',
- 'normalize' => 'relative',
- 'dirname' => '.',
- 'pathinfo' => [
- 'dirname' => '.',
- 'basename' => 'relative',
- 'filename' => 'relative',
- ]
- ],
- 'very/long/relative/path' => [
- 'parent' => 'very/long/relative',
- 'normalize' => 'very/long/relative/path',
- 'dirname' => 'very/long/relative',
- 'pathinfo' => [
- 'dirname' => 'very/long/relative',
- 'basename' => 'path',
- 'filename' => 'path',
- ]
- ],
- 'path/to/file.jpg' => [
- 'parent' => 'path/to',
- 'normalize' => 'path/to/file.jpg',
- 'dirname' => 'path/to',
- 'pathinfo' => [
- 'dirname' => 'path/to',
- 'basename' => 'file.jpg',
- 'extension' => 'jpg',
- 'filename' => 'file',
- ]
- ],
- 'user://' => [
- 'parent' => '',
- 'normalize' => 'user://',
- 'dirname' => 'user://',
- 'pathinfo' => [
- 'dirname' => 'user://',
- 'basename' => '',
- 'filename' => '',
- 'scheme' => 'user',
- ]
- ],
- 'user://.' => [
- 'parent' => '',
- 'normalize' => 'user://',
- 'dirname' => 'user://',
- 'pathinfo' => [
- 'dirname' => 'user://',
- 'basename' => '',
- 'filename' => '',
- 'scheme' => 'user',
- ]
- ],
- 'user://././.' => [
- 'parent' => '',
- 'normalize' => 'user://',
- 'dirname' => 'user://',
- 'pathinfo' => [
- 'dirname' => 'user://',
- 'basename' => '',
- 'filename' => '',
- 'scheme' => 'user',
- ]
- ],
- 'user://./././file' => [
- 'parent' => 'user://',
- 'normalize' => 'user://file',
- 'dirname' => 'user://',
- 'pathinfo' => [
- 'dirname' => 'user://',
- 'basename' => 'file',
- 'filename' => 'file',
- 'scheme' => 'user',
- ]
- ],
- 'user://./././folder/file' => [
- 'parent' => 'user://folder',
- 'normalize' => 'user://folder/file',
- 'dirname' => 'user://folder',
- 'pathinfo' => [
- 'dirname' => 'user://folder',
- 'basename' => 'file',
- 'filename' => 'file',
- 'scheme' => 'user',
- ]
- ],
- 'user://.file' => [
- 'parent' => 'user://',
- 'normalize' => 'user://.file',
- 'dirname' => 'user://',
- 'pathinfo' => [
- 'dirname' => 'user://',
- 'basename' => '.file',
- 'extension' => 'file',
- 'filename' => '',
- 'scheme' => 'user',
- ]
- ],
- 'user:///' => [
- 'parent' => '',
- 'normalize' => 'user:///',
- 'dirname' => 'user:///',
- 'pathinfo' => [
- 'dirname' => 'user:///',
- 'basename' => '',
- 'filename' => '',
- 'scheme' => 'user',
- ]
- ],
- 'user:///absolute' => [
- 'parent' => 'user:///',
- 'normalize' => 'user:///absolute',
- 'dirname' => 'user:///',
- 'pathinfo' => [
- 'dirname' => 'user:///',
- 'basename' => 'absolute',
- 'filename' => 'absolute',
- 'scheme' => 'user',
- ]
- ],
- 'user:///very/long/absolute/path' => [
- 'parent' => 'user:///very/long/absolute',
- 'normalize' => 'user:///very/long/absolute/path',
- 'dirname' => 'user:///very/long/absolute',
- 'pathinfo' => [
- 'dirname' => 'user:///very/long/absolute',
- 'basename' => 'path',
- 'filename' => 'path',
- 'scheme' => 'user',
- ]
- ],
- 'user://relative' => [
- 'parent' => 'user://',
- 'normalize' => 'user://relative',
- 'dirname' => 'user://',
- 'pathinfo' => [
- 'dirname' => 'user://',
- 'basename' => 'relative',
- 'filename' => 'relative',
- 'scheme' => 'user',
- ]
- ],
- 'user://very/long/relative/path' => [
- 'parent' => 'user://very/long/relative',
- 'normalize' => 'user://very/long/relative/path',
- 'dirname' => 'user://very/long/relative',
- 'pathinfo' => [
- 'dirname' => 'user://very/long/relative',
- 'basename' => 'path',
- 'filename' => 'path',
- 'scheme' => 'user',
- ]
- ],
- 'user://path/to/file.jpg' => [
- 'parent' => 'user://path/to',
- 'normalize' => 'user://path/to/file.jpg',
- 'dirname' => 'user://path/to',
- 'pathinfo' => [
- 'dirname' => 'user://path/to',
- 'basename' => 'file.jpg',
- 'extension' => 'jpg',
- 'filename' => 'file',
- 'scheme' => 'user',
- ]
- ],
- ];
- protected function _before()
- {
- $this->class = Filesystem::getInstance();
- }
- protected function _after()
- {
- unset($this->class);
- }
- protected function runTestSet(array $tests, $method)
- {
- $class = $this->class;
- foreach ($tests as $path => $candidates) {
- if (!array_key_exists($method, $candidates)) {
- continue;
- }
- $expected = $candidates[$method];
- $result = $class->{$method}($path);
- $this->assertSame($expected, $result, "Test {$method}('{$path}')");
- if (function_exists($method) && !strpos($path, '://')) {
- $cmp_result = $method($path);
- $this->assertSame($cmp_result, $result, "Compare to original {$method}('{$path}')");
- }
- }
- }
- public function testParent()
- {
- $this->runTestSet($this->tests, 'parent');
- }
- public function testNormalize()
- {
- $this->runTestSet($this->tests, 'normalize');
- }
- public function testDirname()
- {
- $this->runTestSet($this->tests, 'dirname');
- }
- public function testPathinfo()
- {
- $this->runTestSet($this->tests, 'pathinfo');
- }
- }
|