3 class QueryStringTest
extends PHPUnit_Framework_TestCase
{
5 protected $s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=01&1=2";
6 protected $e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B0%5D%5B1%5D=01&1=2";
9 $this->q
= new http\
QueryString($this->s
);
12 function testSimple() {
13 $this->assertEquals($this->e
, (string) $this->q
);
14 $this->assertEquals($this->e
, $this->q
->get());
17 function testGetDefval() {
18 $this->assertEquals("nonexistant", $this->q
->get("unknown", "s", "nonexistant"));
19 $this->assertEquals(null, $this->q
->get("unknown"));
23 $this->assertEquals("b", $this->q
->get("a"));
24 $this->assertEquals(0, $this->q
->get("a", "i"));
25 $this->assertEquals(array("b"), $this->q
->get("a", "a"));
26 $this->assertEquals((object)array("scalar" => "b"), $this->q
->get("a", "o"));
30 $this->assertEquals(array(0,1,2), $this->q
->get("r"));
33 function testGetRR() {
34 $this->assertEquals(array(array("00","01")), $this->q
->get("rr"));
38 $this->assertEquals(2, $this->q
->get(1));
39 $this->assertEquals("2", $this->q
->get(1, "s"));
40 $this->assertEquals(2.0, $this->q
->get(1, "f"));
41 $this->assertTrue($this->q
->get(1, "b"));
45 $this->assertEquals("b", $this->q
->get("a", http\QueryString
::TYPE_STRING
, null, true));
46 $this->assertEquals(null, $this->q
->get("a"));
49 function testDelAll() {
50 $this->q
->set(array("a" => null, "r" => null, "rr" => null, 1 => null));
51 $this->assertEquals("", $this->q
->toString());
55 $this->assertEquals($this->e
, (string) new http\
QueryString($this->q
));
56 $this->assertEquals(http_build_query(array("e"=>$this->q
->toArray())), (string) new http\
QueryString(array("e" => $this->q
)));
59 function testIterator() {
60 $this->assertEquals($this->q
->toArray(), iterator_to_array($this->q
));
63 function testSerialize() {
64 $this->assertEquals($this->e
, (string) unserialize(serialize($this->q
)));