16 $this->assertEquals(
'', (
string) $url);
21 $this->assertEquals(80,
Url::factory(
'http://www.test.com/')->getPort());
22 $this->assertEquals(443,
Url::factory(
'https://www.test.com/')->getPort());
23 $this->assertEquals(
null,
Url::factory(
'ftp://www.test.com/')->getPort());
24 $this->assertEquals(8192,
Url::factory(
'http://www.test.com:8192/')->getPort());
31 $this->assertNotSame($u1->getQuery(), $u2->getQuery());
37 $this->assertEquals(
'/index.php', (
string) $url);
38 $this->assertFalse($url->isAbsolute());
40 $url =
'http://michael:test@test.com:80/path/123?q=abc#test';
42 $this->assertEquals(
'http://michael:test@test.com/path/123?q=abc#test', (
string) $u);
43 $this->assertTrue($u->isAbsolute());
49 $this->assertSame(
'0', $url->getHost());
50 $this->assertEquals(50, $url->getPort());
51 $this->assertSame(
'/0', $url->getPath());
52 $this->assertEquals(
'0', (
string) $url->getQuery());
53 $this->assertSame(
'0', $url->getFragment());
54 $this->assertEquals(
'http://0:50/0?0#0', (
string) $url);
57 $this->assertSame(
'', (
string) $url);
60 $this->assertSame(
'0', (
string) $url);
70 $this->assertSame(
'//0/0', $url);
75 $this->assertSame(
'0', $url);
80 $url =
Url::factory(
'http://test:pass@www.test.com:8081/path/path2/?a=1&b=2#fragment');
81 $this->assertEquals(
'http', $url->getScheme());
82 $this->assertEquals(
'test', $url->getUsername());
83 $this->assertEquals(
'pass', $url->getPassword());
84 $this->assertEquals(
'www.test.com', $url->getHost());
85 $this->assertEquals(8081, $url->getPort());
86 $this->assertEquals(
'/path/path2/', $url->getPath());
87 $this->assertEquals(
'fragment', $url->getFragment());
88 $this->assertEquals(
'a=1&b=2', (
string) $url->getQuery());
90 $this->assertEquals(array(
91 'fragment' =>
'fragment',
92 'host' =>
'www.test.com',
94 'path' =>
'/path/path2/',
105 $this->assertEquals(
'', $url->getPath());
106 $url->setPath(
'test');
107 $this->assertEquals(
'test', $url->getPath());
109 $url->setPath(
'/test/123/abc');
110 $this->assertEquals(array(
'test',
'123',
'abc'), $url->getPathSegments());
112 $parts = parse_url(
'http://www.test.com/test');
114 $this->assertEquals(
'http://www.test.com',
Url::buildUrl($parts));
115 $parts[
'path'] =
'test';
116 $this->assertEquals(
'http://www.test.com/test',
Url::buildUrl($parts));
129 $this->assertEquals(
'http://e.com/base?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
false));
130 $this->assertEquals(
'http://e.com/base?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
null));
131 $this->assertEquals(
'http://e.com/base?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(array()));
132 $this->assertEquals(
'http://e.com/base?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
new \stdClass()));
133 $this->assertEquals(
'http://e.com/base?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
''));
134 $this->assertEquals(
'http://e.com/base?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
'/'));
135 $this->assertEquals(
'http://e.com/baz/foo', (
string)
Url::factory(
'http://e.com/baz/')->addPath(
'foo'));
136 $this->assertEquals(
'http://e.com/base/relative?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
'relative'));
137 $this->assertEquals(
'http://e.com/base/relative?a=1', (
string)
Url::factory(
'http://e.com/base?a=1')->addPath(
'/relative'));
138 $this->assertEquals(
'http://e.com/base/0', (
string)
Url::factory(
'http://e.com/base')->addPath(
'0'));
139 $this->assertEquals(
'http://e.com/base/0/1', (
string)
Url::factory(
'http://e.com/base')->addPath(
'0')->addPath(
'1'));
150 array(
'http://www.example.com/',
'http://www.example.com/',
'http://www.example.com/'),
151 array(
'http://www.example.com/path',
'/absolute',
'http://www.example.com/absolute'),
152 array(
'http://www.example.com/path',
'/absolute?q=2',
'http://www.example.com/absolute?q=2'),
153 array(
'http://www.example.com/path',
'more',
'http://www.example.com/path/more'),
154 array(
'http://www.example.com/path',
'more?q=1',
'http://www.example.com/path/more?q=1'),
155 array(
'http://www.example.com/',
'?q=1',
'http://www.example.com/?q=1'),
156 array(
'http://www.example.com/path',
'http://test.com',
'http://test.com'),
157 array(
'http://www.example.com:8080/path',
'http://test.com',
'http://test.com'),
158 array(
'http://www.example.com:8080/path',
'?q=2#abc',
'http://www.example.com:8080/path?q=2#abc'),
159 array(
'http://u:a@www.example.com/path',
'test',
'http://u:a@www.example.com/path/test'),
160 array(
'http://www.example.com/path',
'http://u:a@www.example.com/',
'http://u:a@www.example.com/'),
161 array(
'/path?q=2',
'http://www.test.com/',
'http://www.test.com/path?q=2'),
162 array(
'http://api.flickr.com/services/',
'http://www.flickr.com/services/oauth/access_token',
'http://www.flickr.com/services/oauth/access_token'),
163 array(
'http://www.example.com/?foo=bar',
'some/path',
'http://www.example.com/some/path?foo=bar'),
164 array(
'http://www.example.com/?foo=bar',
'some/path?boo=moo',
'http://www.example.com/some/path?boo=moo&foo=bar'),
165 array(
'http://www.example.com/some/',
'path?foo=bar&foo=baz',
'http://www.example.com/some/path?foo=bar&foo=baz'),
174 $this->assertEquals($c, (
string)
Url::factory($a)->combine($b));
180 $this->assertEquals(
'example.com', $url->setHost(
'example.com')->getHost());
181 $this->assertEquals(
'8080', $url->setPort(8080)->getPort());
182 $this->assertEquals(
'/foo/bar', $url->setPath(array(
'foo',
'bar'))->getPath());
183 $this->assertEquals(
'a', $url->setPassword(
'a')->getPassword());
184 $this->assertEquals(
'b', $url->setUsername(
'b')->getUsername());
185 $this->assertEquals(
'abc', $url->setFragment(
'abc')->getFragment());
186 $this->assertEquals(
'https', $url->setScheme(
'https')->getScheme());
187 $this->assertEquals(
'a=123', (
string) $url->setQuery(
'a=123')->getQuery());
188 $this->assertEquals(
'https://b:a@example.com:8080/foo/bar?a=123#abc', (
string) $url);
189 $this->assertEquals(
'b=boo', (
string) $url->setQuery(
new QueryString(array(
192 $this->assertEquals(
'https://b:a@example.com:8080/foo/bar?b=boo#abc', (
string) $url);
198 $url->setQuery(array(
'a' =>
'b'));
199 $this->assertEquals(
'http://www.test.com?a=b', (
string) $url);
205 array(
'/foo/..',
'/'),
206 array(
'//foo//..',
'/'),
207 array(
'/foo/../..',
'/'),
208 array(
'/foo/../.',
'/'),
209 array(
'/./foo/..',
'/'),
210 array(
'/./foo',
'/foo'),
211 array(
'/./foo/',
'/foo/'),
212 array(
'/./foo/bar/baz/pho/../..',
'/foo/bar'),
214 array(
'/foo',
'/foo'),
215 array(
'/abc/123/../foo/',
'/abc/foo/'),
216 array(
'/a/b/c/./../../g',
'/a/g'),
217 array(
'/b/c/./../../g',
'/g'),
218 array(
'/b/c/./../../g',
'/g'),
219 array(
'/c/./../../g',
'/g'),
220 array(
'/./../../g',
'/g'),
230 $url->setPath($path)->normalizePath();
231 $this->assertEquals($result, $url->getPath());
237 $url->setHost(
'foo:8983');
238 $this->assertEquals(
'foo', $url->getHost());
239 $this->assertEquals(8983, $url->getPort());
254 $this->assertEquals(
'http://foo.com/baz%20bar/%3F?a=b', (
string) $url);
263 array(
'g',
'http://a/b/c/g'),
264 array(
'./g',
'http://a/b/c/g'),
265 array(
'g/',
'http://a/b/c/g/'),
266 array(
'/g',
'http://a/g'),
267 array(
'?y',
'http://a/b/c/d;p?y'),
268 array(
'g?y',
'http://a/b/c/g?y'),
269 array(
'#s',
'http://a/b/c/d;p?q#s'),
270 array(
'g#s',
'http://a/b/c/g#s'),
271 array(
'g?y#s',
'http://a/b/c/g?y#s'),
272 array(
';x',
'http://a/b/c/;x'),
273 array(
'g;x',
'http://a/b/c/g;x'),
274 array(
'g;x?y#s',
'http://a/b/c/g;x?y#s'),
275 array(
'',
'http://a/b/c/d;p?q'),
276 array(
'.',
'http://a/b/c'),
277 array(
'./',
'http://a/b/c/'),
278 array(
'..',
'http://a/b'),
279 array(
'../',
'http://a/b/'),
280 array(
'../g',
'http://a/b/g'),
281 array(
'../..',
'http://a/'),
282 array(
'../../',
'http://a/'),
283 array(
'../../g',
'http://a/g')
287 if (version_compare(PHP_VERSION,
'5.4.7',
'>=')) {
288 $result[] = array(
'//g',
'http://g');
301 $this->assertEquals($result, trim((
string) $a->combine($b,
true),
'='));