|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* League.Uri (https://uri.thephpleague.com) |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Ignace Nyamagana Butera <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LeagueTest\Uri; |
|
13
|
|
|
|
|
14
|
|
|
use League\Uri\Exceptions\SyntaxError; |
|
15
|
|
|
use League\Uri\Uri; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @group file |
|
20
|
|
|
* @group uri |
|
21
|
|
|
* @coversDefaultClass League\Uri\Uri |
|
22
|
|
|
*/ |
|
23
|
|
|
class FileTest extends TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @covers ::formatHost |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testDefaultConstructor(): void |
|
29
|
|
|
{ |
|
30
|
|
|
self::assertSame('', (string) Uri::createFromString()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @covers ::formatHost |
|
35
|
|
|
* @covers ::formatFilePath |
|
36
|
|
|
* @covers ::assertValidState |
|
37
|
|
|
* @covers ::isUriWithSchemeHostAndPathOnly |
|
38
|
|
|
* |
|
39
|
|
|
* @dataProvider validUrlProvider |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testCreateFromString(string $uri, string $expected): void |
|
42
|
|
|
{ |
|
43
|
|
|
self::assertSame($expected, (string) Uri::createFromString($uri)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function validUrlProvider(): array |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'relative path' => [ |
|
50
|
|
|
'.././path/../is/./relative', |
|
51
|
|
|
'.././path/../is/./relative', |
|
52
|
|
|
], |
|
53
|
|
|
'absolute path' => [ |
|
54
|
|
|
'/path/is/absolute', |
|
55
|
|
|
'/path/is/absolute', |
|
56
|
|
|
], |
|
57
|
|
|
'empty path' => [ |
|
58
|
|
|
'', |
|
59
|
|
|
'', |
|
60
|
|
|
], |
|
61
|
|
|
'with host' => [ |
|
62
|
|
|
'//example.com/path', |
|
63
|
|
|
'//example.com/path', |
|
64
|
|
|
], |
|
65
|
|
|
'with normalized host' => [ |
|
66
|
|
|
'//ExAmpLe.CoM/path', |
|
67
|
|
|
'//example.com/path', |
|
68
|
|
|
], |
|
69
|
|
|
'with empty host' => [ |
|
70
|
|
|
'///path', |
|
71
|
|
|
'///path', |
|
72
|
|
|
], |
|
73
|
|
|
'with scheme' => [ |
|
74
|
|
|
'file://localhost/path', |
|
75
|
|
|
'file://localhost/path', |
|
76
|
|
|
], |
|
77
|
|
|
'with normalized scheme' => [ |
|
78
|
|
|
'FiLe://localhost/path', |
|
79
|
|
|
'file://localhost/path', |
|
80
|
|
|
], |
|
81
|
|
|
'with empty host and scheme' => [ |
|
82
|
|
|
'FiLe:///path', |
|
83
|
|
|
'file:///path', |
|
84
|
|
|
], |
|
85
|
|
|
'with windows path' => [ |
|
86
|
|
|
'file:///C|/demo', |
|
87
|
|
|
'file:///C:/demo', |
|
88
|
|
|
], |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @dataProvider invalidUrlProvider |
|
94
|
|
|
* @covers ::assertValidState |
|
95
|
|
|
* @covers ::isUriWithSchemeHostAndPathOnly |
|
96
|
|
|
*/ |
|
97
|
|
|
public function testConstructorThrowsException(string $uri): void |
|
98
|
|
|
{ |
|
99
|
|
|
self::expectException(SyntaxError::class); |
|
100
|
|
|
Uri::createFromString($uri); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function invalidUrlProvider(): array |
|
104
|
|
|
{ |
|
105
|
|
|
return [ |
|
106
|
|
|
'no authority 1' => ['file:example.com'], |
|
107
|
|
|
'no authority 2' => ['file:/example.com'], |
|
108
|
|
|
'query string' => ['file://example.com?'], |
|
109
|
|
|
'fragment' => ['file://example.com#'], |
|
110
|
|
|
'user info' => ['file://user:[email protected]'], |
|
111
|
|
|
'port' => ['file://example.com:42'], |
|
112
|
|
|
]; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|