|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ExtrasTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_paths\Extras\PathTransform; |
|
8
|
|
|
use kalanis\kw_paths\PathsException; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class PathTest extends CommonTestClass |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param array<string> $to |
|
15
|
|
|
* @param string $from |
|
16
|
|
|
* @throws PathsException |
|
17
|
|
|
* @dataProvider transformProvider |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testExpandFrom(array $to, string $from): void |
|
20
|
|
|
{ |
|
21
|
|
|
$lib = new PathTransform(); |
|
22
|
|
|
$this->assertEquals($to, $lib->expandName($from)); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function transformProvider(): array |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
[['okmijnuhb', ], 'okmijnuhb', ], |
|
29
|
|
|
// just dirs |
|
30
|
|
|
[['wsx', 'edc', 'rfv', ], 'wsx' . DIRECTORY_SEPARATOR . 'edc' . DIRECTORY_SEPARATOR . 'rfv', ], |
|
31
|
|
|
// dir slash |
|
32
|
|
|
[['wsx/', 'edc', 'r f v', ], 'wsx\/' . DIRECTORY_SEPARATOR . 'edc' . DIRECTORY_SEPARATOR . 'r f v', ], |
|
33
|
|
|
// too many slashes |
|
34
|
|
|
[['wsx\\', 'e-dc', 'r&f&v', ], 'wsx\\\\' . DIRECTORY_SEPARATOR . 'e-dc' . DIRECTORY_SEPARATOR . 'r&f&v', ], |
|
35
|
|
|
// empty path |
|
36
|
|
|
[['', ], '', ], |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @throws PathsException |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testEmptyCompact(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$lib = new PathTransform(); |
|
46
|
|
|
$this->expectException(PathsException::class); |
|
47
|
|
|
$lib->compactName(['any', 'where'], ''); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @throws PathsException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testEmptyExpand(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$lib = new PathTransform(); |
|
56
|
|
|
$this->expectException(PathsException::class); |
|
57
|
|
|
$lib->expandName('any/where', ''); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|