FilesystemTest.php
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
use Roots\Acorn\Filesystem\Filesystem;
use Roots\Acorn\Tests\Test\TestCase;
uses(TestCase::class);
it('should support basic globs', function () {
expect((new Filesystem())->glob($this->fixture('closest/*.txt')))
->toEqual([$this->fixture('closest/kjo.txt')]);
});
it('should normalize paths with multiple separators', function () {
expect((new Filesystem())->normalizePath('/a//b///c/d//e'))
->toEqual('/a/b/c/d/e');
});
it('should normalize paths separated by backslashes', function () {
expect((new Filesystem())->normalizePath('/a\\\\b\\\\c/d//e'))
->toEqual('/a/b/c/d/e');
});
it('should normalize paths to arbitrary separator', function () {
expect((new Filesystem())->normalizePath('/a\\\\b\\\\c/d//e', '|'))
->toEqual('|a|b|c|d|e');
});
it('should find the closest path within the filesystem', function () {
expect((new Filesystem())->closest($this->fixture('closest/a/b'), 'kjo.txt'))
->toEqual($this->fixture('closest/kjo.txt'));
expect((new Filesystem())->closest($this->fixture('closest/a/b'), 'bdubs.txt'))
->toEqual($this->fixture('closest/a/b/bdubs.txt'));
expect((new Filesystem())->closest($this->fixture('closest/a/b'), 'apray.txt'))
->toBeNull();
});
it('should determine the relative path between two absolute paths', function () {
expect((new Filesystem())->getRelativePath('/dir_a/dir_b/', '/dir_a/dir_b/dir_c/file_d'))
->toEqual('dir_c/file_d');
expect((new Filesystem())->getRelativePath('/dir_a/dir_b/dir_c/dir_d/', '/dir_a/dir_b/'))
->toEqual('../../');
expect((new Filesystem())->getRelativePath('/dir_a/dir_b/', '/dir_a/file_kjo'))
->toEqual('../file_kjo');
expect((new Filesystem())->getRelativePath('/dir_a/dir_b/', '/dir_a/dir_b/'))
->toEqual('');
});