tests & bugfixes
[m6w6/ext-http] / phpunit / UrlTest.php
1 <?php
2
3 class UrlTest extends PHPUnit_Framework_TestCase {
4 protected $url;
5 function setUp() {
6 $this->url = "http://user:pass@www.example.com:8080/path/file.ext".
7 "?foo=bar&more[]=1&more[]=2#hash";
8 }
9
10 function testStandard() {
11 $this->assertEquals($this->url, (string) new http\Url($this->url));
12
13 $url = new http\Url($this->url,
14 array("path" => "changed", "query" => "foo=&added=this"),
15 http\Url::JOIN_PATH |
16 http\Url::JOIN_QUERY |
17 http\Url::STRIP_AUTH |
18 http\Url::STRIP_FRAGMENT
19 );
20
21 $this->assertEquals("http", $url->scheme);
22 $this->assertEmpty($url->user);
23 $this->assertEmpty($url->pass);
24 $this->assertEquals("www.example.com", $url->host);
25 $this->assertEquals(8080, $url->port);
26 $this->assertEquals("/path/changed", $url->path);
27 $this->assertEquals("foo=&more%5B0%5D=1&more%5B1%5D=2&added=this", $url->query);
28 $this->assertEmpty($url->fragment);
29 }
30
31 function testMod() {
32 $tmp = new http\Url($this->url);
33 $mod = $tmp->mod(array("query" => "set=1"), http\Url::REPLACE);
34 $this->assertNotEquals($tmp->toArray(), $mod->toArray());
35 $this->assertEquals("set=1", $mod->query);
36 $this->assertEquals("new_fragment", $tmp->mod("#new_fragment")->fragment);
37 }
38
39 function testStrings() {
40 $url = new http\Url($this->url);
41 $this->assertEquals((string) $url, (string) new http\Url((string) $url));
42 }
43
44 function testArrays() {
45 $url = new http\Url($this->url);
46 $this->assertEquals($url->toArray(), (new http\Url($url->toArray()))->toArray());
47 }
48 }