3 class ParamsTest
extends PHPUnit_Framework_TestCase
{
4 function testDefault() {
5 $s = "foo, bar;arg=0;bla, gotit=0;now";
8 str_replace(" ", "", $s)
12 function testCustom() {
13 $s = "foo bar.arg:0.bla gotit:0.now";
15 new http\
Params($s, " ", ".", ":"),
20 function testQuoted() {
21 $p = new http\
Params("multipart/form-data; boundary=\"--123\"");
24 "multipart/form-data" => array(
33 $this->assertEquals("multipart/form-data;boundary=--123", (string) $p);
36 function testEscaped() {
37 $p = new http\
Params("form-data; name=\"upload\"; filename=\"trick\\\"\0\\\"ed\"");
44 "filename" => "trick\"\0\"ed"
50 $this->assertEquals("form-data;name=upload;filename=\"trick\\\"\\0\\\"ed\"", (string) $p);
53 function testUrlencoded() {
54 $s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
55 $p = new http\
Params($s, "&", "", "=", http\Params
::PARSE_URLENCODED
);
60 "arguments" => array(),
64 "arguments" => array(),
68 "arguments" => array(),
73 $this->assertEquals("foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1", (string) $p);
76 function testQuery() {
77 $s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
78 $p = new http\
Params($s, "&", "", "=", http\Params
::PARSE_QUERY
);
83 "arguments" => array(),
87 "arguments" => array(),
93 "arguments" => array(),
98 $this->assertEquals("foo=b%22r&bar=b%22z&a%5B0%5D%5B0%5D=1", (string) $p);
102 function testEmpty() {
103 $p = new http\
Params(NULL);
104 $this->assertEquals(array(), $p->params
);
107 function testErrorOfToArrayWithArgs() {
108 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
109 $p = new http\
Params();
110 $p->toArray("dummy");
113 function testIntegerKeys() {
114 $p = new http\
Params("0=nothing;1=yes");
115 $this->assertEquals(array("0" => array("value" => "nothing", "arguments" => array(1=>"yes"))), $p->params
);
116 $this->assertEquals("0=nothing;1=yes", $p->toString());
119 function testBoolParamArguments() {
120 $p = new http\Params
;
121 $container = array("value" => false, "arguments" => array("wrong" => false, "correct" => true));
122 $p["container"] = $container;
123 $this->assertEquals("container=0;wrong=0;correct", $p->toString());
124 $this->assertEquals(array("container" => $container), $p->toArray());
127 function testNoArgsForParam() {
128 $p = new http\Params
;
130 $this->assertEquals("param", $p->toString());
132 $this->assertEquals("param=0", $p->toString());
135 protected function runAssertions($p, $s) {
136 $this->assertCount(3, $p->params
);
137 $this->assertArrayHasKey("foo", $p->params
);
138 $this->assertArrayHasKey("bar", $p->params
);
139 $this->assertArrayHasKEy("gotit", $p->params
);
141 $this->assertTrue($p["foo"]["value"]);
142 $this->assertTrue($p["bar"]["value"]);
143 $this->assertEmpty($p["gotit"]["value"]);
145 $this->assertEmpty($p["foo"]["arguments"]);
146 $this->assertCount(2, $p["bar"]["arguments"]);
147 $this->assertCount(1, $p["gotit"]["arguments"]);
149 $this->assertEmpty($p["bar"]["arguments"]["arg"]);
150 $this->assertTrue($p["bar"]["arguments"]["bla"]);
151 $this->assertTrue($p["gotit"]["arguments"]["now"]);
153 $this->assertEquals($s, (string) $p);
182 $this->assertEquals($comp, $p->params
);
183 $a = new http\
Params($p->params
);
184 $this->assertEquals($comp, $a->toArray());