1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_paths\PathsException; |
8
|
|
|
use kalanis\kw_paths\Stuff; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class StuffTest extends CommonTestClass |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param string $input |
15
|
|
|
* @param string $expected |
16
|
|
|
* @throws PathsException |
17
|
|
|
* @dataProvider sanitizeProvider |
18
|
|
|
*/ |
19
|
|
|
public function testSanitize(string $input, string $expected): void |
20
|
|
|
{ |
21
|
|
|
$this->assertEquals($expected, Stuff::sanitize($input)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function sanitizeProvider(): array |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
['/abc/def/ghi', 'abc/def/ghi'], |
28
|
|
|
['/abc/def//ghi', 'abc/def/ghi'], |
29
|
|
|
['abc/./def/../ghi', 'abc/def/ghi'], |
30
|
|
|
['', ''], |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $input |
36
|
|
|
* @param string $expected |
37
|
|
|
* @throws PathsException |
38
|
|
|
* @dataProvider linkProvider |
39
|
|
|
*/ |
40
|
|
|
public function testLink(string $input, string $expected): void |
41
|
|
|
{ |
42
|
|
|
$this->assertEquals($expected, Stuff::arrayToLink(Stuff::linkToArray($input))); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function linkProvider(): array |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
['/abc/def//ghi', '/abc/def//ghi'], |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $input |
54
|
|
|
* @param string $expected |
55
|
|
|
* @throws PathsException |
56
|
|
|
* @dataProvider pathProvider |
57
|
|
|
*/ |
58
|
|
|
public function testPath(string $input, string $expected): void |
59
|
|
|
{ |
60
|
|
|
$this->assertEquals($expected, Stuff::arrayToPath(Stuff::pathToArray($input))); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function pathProvider(): array |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
[implode(DIRECTORY_SEPARATOR, ['abc', 'def', '', 'ghi']), implode(DIRECTORY_SEPARATOR, ['abc', 'def', '', 'ghi'])], // OS-independent |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $input |
72
|
|
|
* @param string $expected |
73
|
|
|
* @dataProvider dirProvider |
74
|
|
|
*/ |
75
|
|
|
public function testDir(string $input, string $expected): void |
76
|
|
|
{ |
77
|
|
|
$this->assertEquals($expected, Stuff::directory($input)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function dirProvider(): array |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
['/abc/def/ghi', '/abc/def/'], |
84
|
|
|
['/abc/def//ghi', '/abc/def//'], |
85
|
|
|
['ghi', ''], |
86
|
|
|
['', ''], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $input |
92
|
|
|
* @param string $expected |
93
|
|
|
* @dataProvider fileProvider |
94
|
|
|
*/ |
95
|
|
|
public function testFile(string $input, string $expected): void |
96
|
|
|
{ |
97
|
|
|
$this->assertEquals($expected, Stuff::filename($input)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function fileProvider(): array |
101
|
|
|
{ |
102
|
|
|
return [ |
103
|
|
|
['/abc/def/ghi', 'ghi'], |
104
|
|
|
['/abc/def//ghi', 'ghi'], |
105
|
|
|
['ghi', 'ghi'], |
106
|
|
|
['', ''], |
107
|
|
|
]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $input |
112
|
|
|
* @param string $expected |
113
|
|
|
* @dataProvider baseProvider |
114
|
|
|
*/ |
115
|
|
|
public function testBase(string $input, string $expected): void |
116
|
|
|
{ |
117
|
|
|
$this->assertEquals($expected, Stuff::fileBase($input)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function baseProvider(): array |
121
|
|
|
{ |
122
|
|
|
return [ |
123
|
|
|
['/abc//def.ghi', '/abc//def'], |
124
|
|
|
['def.ghi', 'def'], |
125
|
|
|
['.ghi', '.ghi'], |
126
|
|
|
['', ''], |
127
|
|
|
]; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $input |
132
|
|
|
* @param string $expected |
133
|
|
|
* @dataProvider extProvider |
134
|
|
|
*/ |
135
|
|
|
public function testExt(string $input, string $expected): void |
136
|
|
|
{ |
137
|
|
|
$this->assertEquals($expected, Stuff::fileExt($input)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function extProvider(): array |
141
|
|
|
{ |
142
|
|
|
return [ |
143
|
|
|
['/abc//def.ghi', 'ghi'], |
144
|
|
|
['def.ghi', 'ghi'], |
145
|
|
|
['.ghi', ''], |
146
|
|
|
['', ''], |
147
|
|
|
]; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $input |
152
|
|
|
* @param string $expected |
153
|
|
|
* @dataProvider endSlashProvider |
154
|
|
|
*/ |
155
|
|
|
public function testEndSlash(string $input, string $expected): void |
156
|
|
|
{ |
157
|
|
|
$this->assertEquals($expected, Stuff::removeEndingSlash($input)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function endSlashProvider(): array |
161
|
|
|
{ |
162
|
|
|
return [ |
163
|
|
|
[implode(DIRECTORY_SEPARATOR, ['abc', 'def', '', 'ghi']), implode(DIRECTORY_SEPARATOR, ['abc', 'def', '', 'ghi'])], // OS-independent |
164
|
|
|
[implode(DIRECTORY_SEPARATOR, ['abc', 'def', '', 'ghi', '']), implode(DIRECTORY_SEPARATOR, ['abc', 'def', '', 'ghi'])], // OS-independent |
165
|
|
|
]; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param string $input |
170
|
|
|
* @param string $expected |
171
|
|
|
* @dataProvider canonizeProvider |
172
|
|
|
*/ |
173
|
|
|
public function testCanonize(string $input, string $expected): void |
174
|
|
|
{ |
175
|
|
|
$this->assertEquals($expected, Stuff::canonize($input)); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function canonizeProvider(): array |
179
|
|
|
{ |
180
|
|
|
return [ |
181
|
|
|
['abcdefghi', 'abcdefghi'], |
182
|
|
|
['a&0123;bcdef0123ghi', 'a0123bcdef0123ghi'], |
183
|
|
|
['abcde{fghi', 'abcdefghi'], |
184
|
|
|
['abcde©fghi', 'abcdefghi'], |
185
|
|
|
['a^bcd^e$f g hi', 'abcdef_g_hi'], |
186
|
|
|
['abcd^ef hi 0.xxx', 'abcdef_hi_0.xxx'], |
187
|
|
|
['abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789', 'abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrs'], |
188
|
|
|
['abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz.0123456789', 'abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghi.0123456789'], |
189
|
|
|
]; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|