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 testEmpty() {
21 $p = new http\
Params(NULL);
22 $this->assertEquals(array(), $p->params
);
25 function testErrorOfToArrayWithArgs() {
26 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
27 $p = new http\
Params();
31 function testIntegerKeys() {
32 $p = new http\
Params("0=nothing;1=yes");
33 $this->assertEquals(array("0" => array("value" => "nothing", "arguments" => array(1=>"yes"))), $p->params
);
34 $this->assertEquals("0=nothing;1=yes", $p->toString());
37 function testBoolParamArguments() {
39 $container = array("value" => false, "arguments" => array("wrong" => false, "correct" => true));
40 $p["container"] = $container;
41 $this->assertEquals("container=0;wrong=0;correct", $p->toString());
42 $this->assertEquals(array("container" => $container), $p->toArray());
45 function testNoArgsForParam() {
48 $this->assertEquals("param", $p->toString());
50 $this->assertEquals("param=0", $p->toString());
53 protected function runAssertions($p, $s) {
54 $this->assertCount(3, $p->params
);
55 $this->assertArrayHasKey("foo", $p->params
);
56 $this->assertArrayHasKey("bar", $p->params
);
57 $this->assertArrayHasKEy("gotit", $p->params
);
59 $this->assertTrue($p["foo"]["value"]);
60 $this->assertTrue($p["bar"]["value"]);
61 $this->assertEmpty($p["gotit"]["value"]);
63 $this->assertEmpty($p["foo"]["arguments"]);
64 $this->assertCount(2, $p["bar"]["arguments"]);
65 $this->assertCount(1, $p["gotit"]["arguments"]);
67 $this->assertEmpty($p["bar"]["arguments"]["arg"]);
68 $this->assertTrue($p["bar"]["arguments"]["bla"]);
69 $this->assertTrue($p["gotit"]["arguments"]["now"]);
71 $this->assertEquals($s, (string) $p);
100 $this->assertEquals($comp, $p->params
);
101 $a = new http\
Params($p->params
);
102 $this->assertEquals($comp, $a->toArray());