tests
[m6w6/ext-http] / phpunit / ParamsTest.php
1 <?php
2
3 class ParamsTest extends PHPUnit_Framework_TestCase {
4 function testDefault() {
5 $s = "foo, bar;arg=0;bla, gotit=0;now";
6 $this->runAssertions(
7 new http\Params($s),
8 str_replace(" ", "", $s)
9 );
10 }
11
12 function testCustom() {
13 $s = "foo bar.arg:0.bla gotit:0.now";
14 $this->runAssertions(
15 new http\Params($s, " ", ".", ":"),
16 $s
17 );
18 }
19
20 protected function runAssertions($p, $s) {
21 $this->assertCount(3, $p->params);
22 $this->assertArrayHasKey("foo", $p->params);
23 $this->assertArrayHasKey("bar", $p->params);
24 $this->assertArrayHasKEy("gotit", $p->params);
25
26 $this->assertTrue($p["foo"]["value"]);
27 $this->assertTrue($p["bar"]["value"]);
28 $this->assertEmpty($p["gotit"]["value"]);
29
30 $this->assertEmpty($p["foo"]["arguments"]);
31 $this->assertCount(2, $p["bar"]["arguments"]);
32 $this->assertCount(1, $p["gotit"]["arguments"]);
33
34 $this->assertEmpty($p["bar"]["arguments"]["arg"]);
35 $this->assertTrue($p["bar"]["arguments"]["bla"]);
36 $this->assertTrue($p["gotit"]["arguments"]["now"]);
37
38 $this->assertEquals($s, (string) $p);
39
40 $this->assertEquals(
41 array (
42 'foo' =>
43 array (
44 'value' => true,
45 'arguments' =>
46 array (
47 ),
48 ),
49 'bar' =>
50 array (
51 'value' => true,
52 'arguments' =>
53 array (
54 'arg' => '0',
55 'bla' => true,
56 ),
57 ),
58 'gotit' =>
59 array (
60 'value' => '0',
61 'arguments' =>
62 array (
63 'now' => true,
64 ),
65 ),
66 ),
67 $p->params
68 );
69 }
70 }