1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_paths\PathsException; |
8
|
|
|
use kalanis\kw_routed_paths\Linking\Link; |
9
|
|
|
use kalanis\kw_routed_paths\RoutedPath; |
10
|
|
|
use kalanis\kw_routed_paths\Sources\Request; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class ThereAndBackTest extends CommonTestClass |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param string[] $path |
17
|
|
|
* @param string[] $module |
18
|
|
|
* @param bool $asSingle |
19
|
|
|
* @param string $user |
20
|
|
|
* @throws PathsException |
21
|
|
|
* @dataProvider linkMakeProvider |
22
|
|
|
*/ |
23
|
|
|
public function testLinkMake(array $path, array $module, bool $asSingle, string $user): void |
24
|
|
|
{ |
25
|
|
|
$link = new Link(); |
26
|
|
|
$routed = new RoutedPath(new Request($link->link($path, $module, $asSingle, $user), '')); |
27
|
|
|
$this->assertEquals('', $routed->getStaticPath()); |
28
|
|
|
$this->assertEquals('', $routed->getVirtualPrefix()); |
29
|
|
|
$this->assertEquals($module, $routed->getModule()); |
30
|
|
|
$this->assertEquals($asSingle, $routed->isSingle()); |
31
|
|
|
$this->assertEquals($user, $routed->getUser()); |
32
|
|
|
$this->assertEquals($path, $routed->getPath()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string[] $path |
37
|
|
|
* @param string[] $module |
38
|
|
|
* @param bool $asSingle |
39
|
|
|
* @param string $user |
40
|
|
|
* @throws PathsException |
41
|
|
|
* @dataProvider linkMakeProvider |
42
|
|
|
*/ |
43
|
|
|
public function testLinkPrefix(array $path, array $module, bool $asSingle, string $user): void |
44
|
|
|
{ |
45
|
|
|
$link = new Link('somewhere/'); |
46
|
|
|
$routed = new RoutedPath(new Request($link->link($path, $module, $asSingle, $user), 'somewhere/')); |
47
|
|
|
$this->assertEquals('', $routed->getStaticPath()); |
48
|
|
|
$this->assertEquals('somewhere/', $routed->getVirtualPrefix()); |
49
|
|
|
$this->assertEquals($module, $routed->getModule()); |
50
|
|
|
$this->assertEquals($asSingle, $routed->isSingle()); |
51
|
|
|
$this->assertEquals($user, $routed->getUser()); |
52
|
|
|
$this->assertEquals($path, $routed->getPath()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function linkMakeProvider(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
[[], [], false, ''], |
59
|
|
|
[['FooBar', 'Baz'], [], false, ''], |
60
|
|
|
[[], ['FooBar', 'Baz'], false, '',], |
61
|
|
|
[[], [], false, 'anyone'], |
62
|
|
|
[['FooBar', 'Baz'], ['FooBar', 'Baz'], false, 'anyone'], |
63
|
|
|
[['FooBar', 'Baz'], ['FooBar', 'Baz'], true, 'anyone'], |
64
|
|
|
|
65
|
|
|
// [[], [], true, '', ''], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $link |
71
|
|
|
* @dataProvider linkReverseProvider |
72
|
|
|
* @throws PathsException |
73
|
|
|
*/ |
74
|
|
|
public function testLinkReverse(string $link): void |
75
|
|
|
{ |
76
|
|
|
$routed = new RoutedPath(new Request($link, '')); |
77
|
|
|
$lib = new Link(); |
78
|
|
|
$this->assertEquals($link, $lib->link( |
79
|
|
|
$routed->getPath(), |
80
|
|
|
$routed->getModule(), |
81
|
|
|
$routed->isSingle(), |
82
|
|
|
$routed->getUser() |
83
|
|
|
)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function linkReverseProvider(): array |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
['FooBar/Baz'], |
90
|
|
|
['ms:foo-bar--baz'], |
91
|
|
|
['u:anyone'], |
92
|
|
|
['m:foo-bar--baz/u:anyone/FooBar/Baz'], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|