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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
<?php
namespace PicoFeed\Client;
use PHPUnit_Framework_TestCase;
class UrlTest extends PHPUnit_Framework_TestCase
{
public function testHasScheme()
{
$url = new Url('http://www.google.fr/');
$this->assertTrue($url->hasScheme());
$url = new Url('//www.google.fr/');
$this->assertFalse($url->hasScheme());
$url = new Url('/path');
$this->assertFalse($url->hasScheme());
$url = new Url('anything');
$this->assertFalse($url->hasScheme());
}
public function testHasPort()
{
$url = new Url('http://127.0.0.1:8000/');
$this->assertTrue($url->hasPort());
$url = new Url('http://127.0.0.1/');
$this->assertFalse($url->hasPort());
}
public function testIsProtocolRelative()
{
$url = new Url('http://www.google.fr/');
$this->assertFalse($url->isProtocolRelative());
$url = new Url('//www.google.fr/');
$this->assertTrue($url->isProtocolRelative());
$url = new Url('/path');
$this->assertFalse($url->isProtocolRelative());
$url = new Url('anything');
$this->assertFalse($url->isProtocolRelative());
}
public function testBaseUrl()
{
$url = new Url('../bla');
$this->assertEquals('', $url->getBaseUrl());
$url = new Url('github.com');
$this->assertEquals('', $url->getBaseUrl());
$url = new Url('http://127.0.0.1:8000');
$this->assertEquals('http://127.0.0.1:8000', $url->getBaseUrl());
$url = new Url('http://127.0.0.1:8000/test?123');
$this->assertEquals('http://127.0.0.1:8000', $url->getBaseUrl());
$url = new Url('http://localhost/test');
$this->assertEquals('http://localhost', $url->getBaseUrl());
$url = new Url('https://localhost/test');
$this->assertEquals('https://localhost', $url->getBaseUrl());
$url = new Url('//localhost/test?truc');
$this->assertEquals('http://localhost', $url->getBaseUrl());
$url = new Url('//localhost/test?truc');
$this->assertEquals('http://localhost', $url->getBaseUrl());
}
public function testIsRelativeUrl()
{
$url = new Url('http://www.google.fr/');
$this->assertFalse($url->isRelativeUrl());
$url = new Url('//www.google.fr/');
$this->assertFalse($url->isRelativeUrl());
$url = new Url('/path');
$this->assertTrue($url->isRelativeUrl());
$url = new Url('../../path');
$this->assertTrue($url->isRelativeUrl());
$url = new Url('anything');
$this->assertTrue($url->isRelativeUrl());
$url = new Url('/2014/08/03/4668-noisettes');
$this->assertTrue($url->isRelativeUrl());
$url = new Url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==');
$this->assertFalse($url->isRelativeUrl());
}
public function testGetFullPath()
{
$url = new Url('http://www.google.fr/');
$this->assertEquals('/', $url->getFullPath());
$url = new Url('//www.google.fr/search');
$this->assertEquals('/search', $url->getFullPath());
$url = new Url('/path');
$this->assertEquals('/path', $url->getFullPath());
$url = new Url('/path#test');
$this->assertEquals('/path#test', $url->getFullPath());
$url = new Url('anything');
$this->assertEquals('/anything', $url->getFullPath());
$url = new Url('foo/bar');
$this->assertEquals('/foo/bar', $url->getFullPath());
$url = new Url('index.php?foo=bar&test=1');
$this->assertEquals('/index.php?foo=bar&test=1', $url->getFullPath());
}
public function testAbsoluteUrl()
{
$url = new Url('http://google.fr/');
$this->assertEquals('http://google.fr/', $url->getAbsoluteUrl());
$url = new Url('http://google.ca');
$this->assertEquals('http://google.ca/', $url->getAbsoluteUrl());
$url = new Url('../bla');
$this->assertEquals('', $url->getAbsoluteUrl(''));
$url = new Url('/2014/08/03/4668-noisettes');
$this->assertEquals('http://www.la-grange.net/2014/08/03/4668-noisettes', $url->getAbsoluteUrl('http://www.la-grange.net/'));
$url = new Url('http://www.google.fr/../bla');
$this->assertEquals('http://www.google.fr/../bla', $url->getAbsoluteUrl('http://www.google.fr/'));
$url = new Url('http://www.google.fr/');
$this->assertEquals('http://www.google.fr/', $url->getAbsoluteUrl('http://www.google.fr/'));
$url = new Url('//www.google.fr/search');
$this->assertEquals('http://www.google.fr/search', $url->getAbsoluteUrl('//www.google.fr/'));
$url = new Url('//www.google.fr/search');
$this->assertEquals('http://www.google.fr/search', $url->getAbsoluteUrl());
$url = new Url('/path');
$this->assertEquals('http://www.google.fr/path', $url->getAbsoluteUrl('http://www.google.fr/'));
$url = new Url('/path#test');
$this->assertEquals('http://www.google.fr/path#test', $url->getAbsoluteUrl('http://www.google.fr/'));
$url = new Url('anything');
$this->assertEquals('http://www.google.fr/anything', $url->getAbsoluteUrl('http://www.google.fr/'));
$url = new Url('index.php?foo=bar&test=1');
$this->assertEquals('http://www.google.fr/index.php?foo=bar&test=1', $url->getAbsoluteUrl('http://www.google.fr/'));
$url = new Url('index.php?foo=bar&test=1');
$this->assertEquals('', $url->getAbsoluteUrl());
$url = new Url('https://127.0.0.1:8000/here/test?v=3');
$this->assertEquals('https://127.0.0.1:8000/here/test?v=3', $url->getAbsoluteUrl());
$url = new Url('http://www.lofibucket.com/articles/oscilloscope_quake.html');
$this->assertEquals('http://www.lofibucket.com/articles/oscilloscope_quake.html', $url->getAbsoluteUrl());
$url = new Url('test?v=3');
$this->assertEquals('https://127.0.0.1:8000/here/test?v=3', $url->getAbsoluteUrl('https://127.0.0.1:8000/here/'));
}
public function testIsRelativePath()
{
$url = new Url('');
$this->assertTrue($url->isRelativePath());
$url = new Url('http://google.fr');
$this->assertTrue($url->isRelativePath());
$url = new Url('filename.json');
$this->assertTrue($url->isRelativePath());
$url = new Url('folder/filename.json');
$this->assertTrue($url->isRelativePath());
$url = new Url('/filename.json');
$this->assertFalse($url->isRelativePath());
$url = new Url('/folder/filename.json');
$this->assertFalse($url->isRelativePath());
}
public function testGetBasePath()
{
$url = new Url('img/quakescope.jpg');
$this->assertEquals('/img/', $url->getBasePath());
$url = new Url('http://foo/img/quakescope.jpg');
$this->assertEquals('/img/', $url->getBasePath());
$url = new Url('http://foo/bar.html');
$this->assertEquals('/', $url->getBasePath());
$url = new Url('http://foo/bar');
$this->assertEquals('/', $url->getBasePath());
$url = new Url('http://foo/bar/');
$this->assertEquals('/bar/', $url->getBasePath());
$url = new Url('http://website/subfolder/img/foo.png');
$this->assertEquals('/subfolder/img/', $url->getBasePath());
}
public function testResolve()
{
// relative link
$this->assertEquals(
'http://miniflux.net/assets/img/favicon.png',
Url::resolve('assets/img/favicon.png', 'http://miniflux.net')
);
// relative link + HTTPS
$this->assertEquals(
'https://miniflux.net/assets/img/favicon.png',
Url::resolve('assets/img/favicon.png', 'https://miniflux.net')
);
// absolute link
$this->assertEquals(
'http://miniflux.net/assets/img/favicon.png',
Url::resolve('/assets/img/favicon.png', 'http://miniflux.net')
);
// absolute link + HTTPS
$this->assertEquals(
'https://miniflux.net/assets/img/favicon.png',
Url::resolve('/assets/img/favicon.png', 'https://miniflux.net')
);
// Protocol relative link
$this->assertEquals(
'http://google.com/assets/img/favicon.png',
Url::resolve('//google.com/assets/img/favicon.png', 'http://miniflux.net')
);
// Protocol relative link + HTTPS
$this->assertEquals(
'https://google.com/assets/img/favicon.png',
Url::resolve('//google.com/assets/img/favicon.png', 'https://miniflux.net')
);
// URL same fqdn
$this->assertEquals(
'http://miniflux.net/assets/img/favicon.png',
Url::resolve('http://miniflux.net/assets/img/favicon.png', 'https://miniflux.net')
);
// URL different fqdn
$this->assertEquals(
'https://www.google.com/assets/img/favicon.png',
Url::resolve('https://www.google.com/assets/img/favicon.png', 'https://miniflux.net')
);
// HTTPS URL
$this->assertEquals(
'https://miniflux.net/assets/img/favicon.png',
Url::resolve('https://miniflux.net/assets/img/favicon.png', 'https://miniflux.net')
);
// empty string on missing website parameter
$this->assertEquals(
'',
Url::resolve('favicon.png', '')
);
// website only on missing icon parameter
$this->assertEquals(
'ht
|