Merge branch 'DEV_2' into HEAD
[m6w6/ext-http] / phpunit / UrlTest.php
index ebd020fc74b8ba4d8305bea196e437b7c0721ba7..dcf3b4fdd2533db26be145c3c874fdd1b9b2ab15 100644 (file)
@@ -5,7 +5,7 @@ class UrlTest extends PHPUnit_Framework_TestCase {
        function setUp() {
                $this->url = "http://user:pass@www.example.com:8080/path/file.ext".
                        "?foo=bar&more[]=1&more[]=2#hash";
-       }
+    }
 
        function testStandard() {
                $this->assertEquals($this->url, (string) new http\Url($this->url));
@@ -24,7 +24,26 @@ class UrlTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals("www.example.com", $url->host);
                $this->assertEquals(8080, $url->port);
                $this->assertEquals("/path/changed", $url->path);
-               $this->assertEquals("foo=&more%5B0%5D=1&more%5B1%5D=2&added=this", $url->query);
-               $this->assertEmpty($url->fragment);
-       }
+               $this->assertEquals("more%5B0%5D=1&more%5B1%5D=2&added=this", $url->query);
+        $this->assertEmpty($url->fragment);
+    }
+
+    function testMod() {
+        $tmp = new http\Url($this->url);
+        $mod = $tmp->mod(array("query" => "set=1"), http\Url::REPLACE);
+        $this->assertNotEquals($tmp->toArray(), $mod->toArray());
+        $this->assertEquals("set=1", $mod->query);
+        $this->assertEquals("new_fragment", $tmp->mod("#new_fragment")->fragment);
+    }
+
+    function testStrings() {
+        $url = new http\Url($this->url);
+        $this->assertEquals((string) $url, (string) new http\Url((string) $url));
+    }
+
+    function testArrays() {
+        $url = new http\Url($this->url);
+               $url2 = new http\Url($url->toArray());
+        $this->assertEquals($url->toArray(), $url2->toArray());
+    }
 }