-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUriTest.php
More file actions
186 lines (162 loc) · 5.25 KB
/
UriTest.php
File metadata and controls
186 lines (162 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
declare(strict_types=1);
namespace Tests\Codeception\Util;
use Codeception\Util\Uri;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class UriTest extends TestCase
{
public function testUrlMerge()
{
$this->assertSame(
'https://codeception.com/quickstart',
Uri::mergeUrls('https://codeception.com/hello', '/quickstart'),
'merge paths'
);
$this->assertSame(
'https://codeception.com/hello/davert',
Uri::mergeUrls('https://codeception.com/hello/world', 'davert'),
'merge relative urls'
);
$this->assertSame(
'https://github.com/codeception/codeception',
Uri::mergeUrls('https://codeception.com/hello/world', 'https://github.com/codeception/codeception'),
'merge absolute urls'
);
}
/**
* @Issue https://github.com/Codeception/Codeception/pull/2141
*/
public function testMergingScheme()
{
$this->assertSame(
'https://google.com/account/',
Uri::mergeUrls('http://google.com/', 'https://google.com/account/')
);
$this->assertSame('https://facebook.com/', Uri::mergeUrls('https://google.com/test/', '//facebook.com/'));
$this->assertSame(
'https://facebook.com/#anchor2',
Uri::mergeUrls('https://google.com/?param=1#anchor', '//facebook.com/#anchor2')
);
}
/**
* @Issue https://github.com/Codeception/Codeception/pull/2841
*/
public function testMergingPath()
{
$this->assertSame('/form/?param=1#anchor', Uri::mergeUrls('/form/?param=1', '#anchor'));
$this->assertSame('/form/?param=1#anchor2', Uri::mergeUrls('/form/?param=1#anchor1', '#anchor2'));
$this->assertSame('/form/?param=2', Uri::mergeUrls('/form/?param=1#anchor', '?param=2'));
$this->assertSame('/page/', Uri::mergeUrls('/form/?param=1#anchor', '/page/'));
}
/**
* @Issue https://github.com/Codeception/Codeception/pull/4847
*/
public function testMergingNonParsingPath()
{
$this->assertSame('/3.0/en/index/page:5', Uri::mergeUrls('https://cakephp.org/', '/3.0/en/index/page:5'));
}
/**
* @Issue https://github.com/Codeception/Codeception/pull/2499
*/
public function testAppendAnchor()
{
$this->assertSame(
'https://codeception.com/quickstart#anchor',
Uri::appendPath('https://codeception.com/quickstart', '#anchor')
);
$this->assertSame(
'https://codeception.com/quickstart#anchor',
Uri::appendPath('https://codeception.com/quickstart#first', '#anchor')
);
}
public function testAppendPath()
{
$this->assertSame(
'https://codeception.com/quickstart/path',
Uri::appendPath('https://codeception.com/quickstart', 'path')
);
$this->assertSame(
'https://codeception.com/quickstart/path',
Uri::appendPath('https://codeception.com/quickstart', '/path')
);
}
public function testAppendEmptyPath()
{
$this->assertSame(
'https://codeception.com/quickstart',
Uri::appendPath('https://codeception.com/quickstart', '')
);
}
public function testAppendPathRemovesQueryStringAndAnchor()
{
$this->assertSame(
'https://codeception.com/quickstart',
Uri::appendPath('https://codeception.com/quickstart?a=b#c', '')
);
}
public function testMergeUrlsWhenBaseUriHasNoTrailingSlashAndUriPathHasNoLeadingSlash()
{
$this->assertSame(
'https://codeception.com/test',
Uri::mergeUrls('https://codeception.com', 'test')
);
}
public function testMergeUrlsWhenBaseUriEndsWithSlashButUriPathHasNoLeadingSlash()
{
$this->assertSame(
'https://codeception.com/test',
Uri::mergeUrls('https://codeception.com/', 'test')
);
}
#[DataProvider('phpUrlPartsProvider')]
public function testPhpUrlPartsToString(array $parts, string $expected): void
{
$this->assertSame($expected, Uri::phpUrlPartsToString($parts));
}
public static function phpUrlPartsProvider(): iterable
{
yield [
[
'path' => '/test',
],
'/test'
];
yield [
[
'query' => 'test=a',
],
'?test=a'
];
yield [
[
'scheme' => 'https',
'host' => 'codeception.com',
'path' => '/test',
],
'https://codeception.com/test'
];
yield [
[
'scheme' => 'https',
'host' => 'codeception.com',
],
'https://codeception.com'
];
yield [
[
'scheme' => 'https',
'host' => 'codeception.com',
],
'https://codeception.com'
];
yield [
[
'scheme' => 'https',
'host' => 'codeception.com',
'port' => 8080,
],
'https://codeception.com:8080'
];
}
}