1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_paths\ArrayPath; |
8
|
|
|
use kalanis\kw_paths\Path; |
9
|
|
|
use kalanis\kw_paths\PathsException; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class PathTest extends CommonTestClass |
13
|
|
|
{ |
14
|
|
|
public function testBasic(): void |
15
|
|
|
{ |
16
|
|
|
$path = new Path(); |
17
|
|
|
$path->setData(['user'=>'def','module'=>'jkl','mno'=>'pqr',]); |
|
|
|
|
18
|
|
|
$path->setDocumentRoot('/abc/def/ghi/jkl'); |
19
|
|
|
$path->setPathToSystemRoot('../mno/pqr'); |
20
|
|
|
$this->assertEquals(implode(DIRECTORY_SEPARATOR, ['', 'abc', 'def', 'ghi', 'jkl']), $path->getDocumentRoot()); |
21
|
|
|
$this->assertEquals(implode(DIRECTORY_SEPARATOR, ['..', 'mno', 'pqr']), $path->getPathToSystemRoot()); |
22
|
|
|
$this->assertEmpty($path->getStaticalPath()); |
|
|
|
|
23
|
|
|
$this->assertEmpty($path->getVirtualPrefix()); |
|
|
|
|
24
|
|
|
$this->assertEquals('def', $path->getUser()); |
|
|
|
|
25
|
|
|
$this->assertEmpty($path->getLang()); |
|
|
|
|
26
|
|
|
$this->assertEmpty($path->getPath()); |
|
|
|
|
27
|
|
|
$this->assertEquals('jkl', $path->getModule()); |
|
|
|
|
28
|
|
|
$this->assertEmpty($path->isSingle()); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws PathsException |
33
|
|
|
*/ |
34
|
|
|
public function testArrayPath1(): void |
35
|
|
|
{ |
36
|
|
|
$path = new ArrayPath(); |
37
|
|
|
$path->setString(implode(DIRECTORY_SEPARATOR, ['', 'abc', '..', 'def.ghi', '.', 'jkl', '', 'mno.pqr'])); |
38
|
|
|
$this->assertEquals(implode(DIRECTORY_SEPARATOR, ['abc', 'def.ghi', 'jkl', 'mno.pqr']), (string) $path); |
39
|
|
|
$this->assertEquals('mno.pqr', $path->getFileName()); |
40
|
|
|
$this->assertEquals(implode(DIRECTORY_SEPARATOR, ['abc', 'def.ghi', 'jkl']), $path->getStringDirectory()); |
41
|
|
|
$this->assertEquals(implode(DIRECTORY_SEPARATOR, ['abc', 'def.ghi', 'jkl', 'mno.pqr']), $path->getString()); |
42
|
|
|
$this->assertEquals(['abc', 'def.ghi', 'jkl'], $path->getArrayDirectory()); |
43
|
|
|
$this->assertEquals(['abc', 'def.ghi', 'jkl', 'mno.pqr'], $path->getArray()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @throws PathsException |
48
|
|
|
*/ |
49
|
|
|
public function testArrayPath2(): void |
50
|
|
|
{ |
51
|
|
|
$path = new ArrayPath(); |
52
|
|
|
$path->setArray(['', '.', '..', '.', '']); // content NOPE! |
53
|
|
|
$this->assertEquals('', (string) $path); |
54
|
|
|
$this->assertEquals('', $path->getFileName()); |
55
|
|
|
$this->assertEquals('', $path->getStringDirectory()); |
56
|
|
|
$this->assertEquals('', $path->getString()); |
57
|
|
|
$this->assertEquals([], $path->getArrayDirectory()); |
58
|
|
|
$this->assertEquals([], $path->getArray()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws PathsException |
63
|
|
|
*/ |
64
|
|
|
public function testArrayPath3(): void |
65
|
|
|
{ |
66
|
|
|
$path = new ArrayPath(); |
67
|
|
|
$path->setString('abcdef'); |
68
|
|
|
$this->assertEquals('abcdef', (string) $path); |
69
|
|
|
$this->assertEquals('abcdef', $path->getFileName()); |
70
|
|
|
$this->assertEquals('', $path->getStringDirectory()); |
71
|
|
|
$this->assertEquals('abcdef', $path->getString()); |
72
|
|
|
$this->assertEquals([], $path->getArrayDirectory()); |
73
|
|
|
$this->assertEquals(['abcdef'], $path->getArray()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.