X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=phpunit%2FQueryStringTest.php;fp=phpunit%2FQueryStringTest.php;h=fb2eb4741f253dba81be89fa13e2f7627135d07e;hb=87db9817d428282792c8146d9c2ae9748ebf6f1e;hp=0000000000000000000000000000000000000000;hpb=7a5c865f6faf8b1b6c91735e9d3b040449ea74ba;p=m6w6%2Fext-http diff --git a/phpunit/QueryStringTest.php b/phpunit/QueryStringTest.php new file mode 100644 index 0000000..fb2eb47 --- /dev/null +++ b/phpunit/QueryStringTest.php @@ -0,0 +1,66 @@ +q = new http\QueryString($this->s); + } + + function testSimple() { + $this->assertEquals($this->e, (string) $this->q); + $this->assertEquals($this->e, $this->q->get()); + } + + function testGetDefval() { + $this->assertEquals("nonexistant", $this->q->get("unknown", "s", "nonexistant")); + $this->assertEquals(null, $this->q->get("unknown")); + } + + function testGetA() { + $this->assertEquals("b", $this->q->get("a")); + $this->assertEquals(0, $this->q->get("a", "i")); + $this->assertEquals(array("b"), $this->q->get("a", "a")); + $this->assertEquals((object)array("scalar" => "b"), $this->q->get("a", "o")); + } + + function testGetR() { + $this->assertEquals(array(0,1,2), $this->q->get("r")); + } + + function testGetRR() { + $this->assertEquals(array(array("00","01")), $this->q->get("rr")); + } + + function testGet1() { + $this->assertEquals(2, $this->q->get(1)); + $this->assertEquals("2", $this->q->get(1, "s")); + $this->assertEquals(2.0, $this->q->get(1, "f")); + $this->assertTrue($this->q->get(1, "b")); + } + + function testDelA() { + $this->assertEquals("b", $this->q->get("a", http\QueryString::TYPE_STRING, null, true)); + $this->assertEquals(null, $this->q->get("a")); + } + + function testDelAll() { + $this->q->set(array("a" => null, "r" => null, "rr" => null, 1 => null)); + $this->assertEquals("", $this->q->toString()); + } + + function testQSO() { + $this->assertEquals($this->e, (string) new http\QueryString($this->q)); + $this->assertEquals(http_build_query(array("e"=>$this->q->toArray())), (string) new http\QueryString(array("e" => $this->q))); + } + + function testIterator() { + $this->assertEquals($this->q->toArray(), iterator_to_array($this->q)); + } + + function testSerialize() { + $this->assertEquals($this->e, (string) unserialize(serialize($this->q))); + } +}