From c329d4dabccd5caff9869d88be4e14f477e028b6 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 9 Jul 2014 16:27:52 +0200 Subject: [PATCH] unfold param tests --- phpunit/ParamsTest.php | 186 ----------------------------------------- tests/params001.phpt | 5 +- tests/params003.phpt | 97 +++++++++++++++++++++ tests/params004.phpt | 97 +++++++++++++++++++++ tests/params005.phpt | 28 +++++++ tests/params006.phpt | 29 +++++++ tests/params007.phpt | 35 ++++++++ tests/params008.phpt | 37 ++++++++ tests/params009.phpt | 17 ++++ tests/params010.phpt | 21 +++++ tests/params011.phpt | 23 +++++ tests/params012.phpt | 22 +++++ 12 files changed, 409 insertions(+), 188 deletions(-) delete mode 100644 phpunit/ParamsTest.php create mode 100644 tests/params003.phpt create mode 100644 tests/params004.phpt create mode 100644 tests/params005.phpt create mode 100644 tests/params006.phpt create mode 100644 tests/params007.phpt create mode 100644 tests/params008.phpt create mode 100644 tests/params009.phpt create mode 100644 tests/params010.phpt create mode 100644 tests/params011.phpt create mode 100644 tests/params012.phpt diff --git a/phpunit/ParamsTest.php b/phpunit/ParamsTest.php deleted file mode 100644 index 71bfcf4..0000000 --- a/phpunit/ParamsTest.php +++ /dev/null @@ -1,186 +0,0 @@ -runAssertions( - new http\Params($s), - str_replace(" ", "", $s) - ); - } - - function testCustom() { - $s = "foo bar.arg:0.bla gotit:0.now"; - $this->runAssertions( - new http\Params($s, " ", ".", ":"), - $s - ); - } - - function testQuoted() { - $p = new http\Params("multipart/form-data; boundary=\"--123\""); - $this->assertEquals( - array( - "multipart/form-data" => array( - "value" => true, - "arguments" => array( - "boundary" => "--123" - ) - ) - ), - $p->params - ); - $this->assertEquals("multipart/form-data;boundary=--123", (string) $p); - } - - function testEscaped() { - $p = new http\Params("form-data; name=\"upload\"; filename=\"trick\\\"\0\\\"ed\""); - $this->assertEquals( - array( - "form-data" => array( - "value" => true, - "arguments" => array( - "name" => "upload", - "filename" => "trick\"\0\"ed" - ) - ) - ), - $p->params - ); - $this->assertEquals("form-data;name=upload;filename=\"trick\\\"\\0\\\"ed\"", (string) $p); - } - - function testUrlencoded() { - $s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1"; - $p = new http\Params($s, "&", "", "=", http\Params::PARSE_URLENCODED); - $this->assertEquals( - array( - "foo" => array( - "value" => "b\"r", - "arguments" => array(), - ), - "bar" => array( - "value" => "b\"z", - "arguments" => array(), - ), - "a[][]" => array( - "value" => "1", - "arguments" => array(), - ), - ), - $p->params - ); - $this->assertEquals("foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1", (string) $p); - } - - function testQuery() { - $s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1"; - $p = new http\Params($s, "&", "", "=", http\Params::PARSE_QUERY); - $this->assertEquals( - array( - "foo" => array( - "value" => "b\"r", - "arguments" => array(), - ), - "bar" => array( - "value" => "b\"z", - "arguments" => array(), - ), - "a" => array( - "value" => array( - array("1") - ), - "arguments" => array(), - ), - ), - $p->params - ); - $this->assertEquals("foo=b%22r&bar=b%22z&a%5B0%5D%5B0%5D=1", (string) $p); - } - - - function testEmpty() { - $p = new http\Params(NULL); - $this->assertEquals(array(), $p->params); - } - - function testErrorOfToArrayWithArgs() { - $this->setExpectedException("PHPUnit_Framework_Error_Warning"); - $p = new http\Params(); - $p->toArray("dummy"); - } - - function testIntegerKeys() { - $p = new http\Params("0=nothing;1=yes"); - $this->assertEquals(array("0" => array("value" => "nothing", "arguments" => array(1=>"yes"))), $p->params); - $this->assertEquals("0=nothing;1=yes", $p->toString()); - } - - function testBoolParamArguments() { - $p = new http\Params; - $container = array("value" => false, "arguments" => array("wrong" => false, "correct" => true)); - $p["container"] = $container; - $this->assertEquals("container=0;wrong=0;correct", $p->toString()); - $this->assertEquals(array("container" => $container), $p->toArray()); - } - - function testNoArgsForParam() { - $p = new http\Params; - $p["param"] = true; - $this->assertEquals("param", $p->toString()); - $p["param"] = false; - $this->assertEquals("param=0", $p->toString()); - } - - protected function runAssertions($p, $s) { - $this->assertCount(3, $p->params); - $this->assertArrayHasKey("foo", $p->params); - $this->assertArrayHasKey("bar", $p->params); - $this->assertArrayHasKEy("gotit", $p->params); - - $this->assertTrue($p["foo"]["value"]); - $this->assertTrue($p["bar"]["value"]); - $this->assertEmpty($p["gotit"]["value"]); - - $this->assertEmpty($p["foo"]["arguments"]); - $this->assertCount(2, $p["bar"]["arguments"]); - $this->assertCount(1, $p["gotit"]["arguments"]); - - $this->assertEmpty($p["bar"]["arguments"]["arg"]); - $this->assertTrue($p["bar"]["arguments"]["bla"]); - $this->assertTrue($p["gotit"]["arguments"]["now"]); - - $this->assertEquals($s, (string) $p); - - $comp = array ( - 'foo' => - array ( - 'value' => true, - 'arguments' => - array ( - ), - ), - 'bar' => - array ( - 'value' => true, - 'arguments' => - array ( - 'arg' => '0', - 'bla' => true, - ), - ), - 'gotit' => - array ( - 'value' => '0', - 'arguments' => - array ( - 'now' => true, - ), - ), - ); - - $this->assertEquals($comp, $p->params); - $a = new http\Params($p->params); - $this->assertEquals($comp, $a->toArray()); - } -} diff --git a/tests/params001.phpt b/tests/params001.phpt index ac52bf7..40b5e15 100644 --- a/tests/params001.phpt +++ b/tests/params001.phpt @@ -27,7 +27,8 @@ var_dump( var_dump((string) $ct); -echo "Done\n"; +?> +DONE --EXPECTF-- Test bool(true) @@ -37,4 +38,4 @@ bool(false) bool(true) string(10) "iso-8859-1" string(%d) "text/json;charset=iso-8859-1" -Done +DONE diff --git a/tests/params003.phpt b/tests/params003.phpt new file mode 100644 index 0000000..11e2759 --- /dev/null +++ b/tests/params003.phpt @@ -0,0 +1,97 @@ +--TEST-- +default params +--SKIPIF-- + +--FILE-- +"arg", "bar"=>"bla", "gotit"=>"now"); +$r = array ( + 'foo' => + array ( + 'value' => true, + 'arguments' => + array ( + ), + ), + 'bar' => + array ( + 'value' => true, + 'arguments' => + array ( + 'arg' => '0', + 'bla' => true, + ), + ), + 'gotit' => + array ( + 'value' => '0', + 'arguments' => + array ( + 'now' => true, + ), + ), +); + +# --- + +var_dump(count($p->params)); + +echo "key exists\n"; +foreach ($k as $key) { + var_dump(array_key_exists($key, $p->params)); +} + +echo "values\n"; +foreach ($k as $key) { + var_dump($p[$key]["value"]); +} + +echo "args\n"; +foreach ($k as $key) { + var_dump(count($p[$key]["arguments"])); +} + +echo "arg values\n"; +foreach ($k as $key) { + var_dump(@$p[$key]["arguments"][$a[$key]]); +} + +echo "equals\n"; +var_dump($c === (string) $p); +var_dump($r === $p->params); +$x = new http\Params($p->params); +var_dump($r === $x->toArray()); +?> +DONE +--EXPECT-- +Test +int(3) +key exists +bool(true) +bool(true) +bool(true) +values +bool(true) +bool(true) +string(1) "0" +args +int(0) +int(2) +int(1) +arg values +NULL +bool(true) +bool(true) +equals +bool(true) +bool(true) +bool(true) +DONE diff --git a/tests/params004.phpt b/tests/params004.phpt new file mode 100644 index 0000000..69075ea --- /dev/null +++ b/tests/params004.phpt @@ -0,0 +1,97 @@ +--TEST-- +custom params +--SKIPIF-- + +--FILE-- +"arg", "bar"=>"bla", "gotit"=>"now"); +$r = array ( + 'foo' => + array ( + 'value' => true, + 'arguments' => + array ( + ), + ), + 'bar' => + array ( + 'value' => true, + 'arguments' => + array ( + 'arg' => '0', + 'bla' => true, + ), + ), + 'gotit' => + array ( + 'value' => '0', + 'arguments' => + array ( + 'now' => true, + ), + ), +); + +# --- + +var_dump(count($p->params)); + +echo "key exists\n"; +foreach ($k as $key) { + var_dump(array_key_exists($key, $p->params)); +} + +echo "values\n"; +foreach ($k as $key) { + var_dump($p[$key]["value"]); +} + +echo "args\n"; +foreach ($k as $key) { + var_dump(count($p[$key]["arguments"])); +} + +echo "arg values\n"; +foreach ($k as $key) { + var_dump(@$p[$key]["arguments"][$a[$key]]); +} + +echo "equals\n"; +var_dump($c === (string) $p); +var_dump($r === $p->params); +$x = new http\Params($p->params); +var_dump($r === $x->toArray()); +?> +DONE +--EXPECT-- +Test +int(3) +key exists +bool(true) +bool(true) +bool(true) +values +bool(true) +bool(true) +string(1) "0" +args +int(0) +int(2) +int(1) +arg values +NULL +bool(true) +bool(true) +equals +bool(true) +bool(true) +bool(true) +DONE diff --git a/tests/params005.phpt b/tests/params005.phpt new file mode 100644 index 0000000..7c64a31 --- /dev/null +++ b/tests/params005.phpt @@ -0,0 +1,28 @@ +--TEST-- +quoted params +--SKIPIF-- + +--FILE-- + array( + "value" => true, + "arguments" => array( + "boundary" => "--123" + ) + ) +); +var_dump($c === $p->params); +var_dump("multipart/form-data;boundary=--123" === (string) $p); +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE diff --git a/tests/params006.phpt b/tests/params006.phpt new file mode 100644 index 0000000..5c6455c --- /dev/null +++ b/tests/params006.phpt @@ -0,0 +1,29 @@ +--TEST-- +escaped params +--SKIPIF-- + +--FILE-- + array( + "value" => true, + "arguments" => array( + "name" => "upload", + "filename" => "trick\"\0\"ed" + ) + ) +); +var_dump($c === $p->params); +var_dump("form-data;name=upload;filename=\"trick\\\"\\0\\\"ed\"" === (string) $p); +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE diff --git a/tests/params007.phpt b/tests/params007.phpt new file mode 100644 index 0000000..c56e2fa --- /dev/null +++ b/tests/params007.phpt @@ -0,0 +1,35 @@ +--TEST-- +urlencoded params +--SKIPIF-- + +--FILE-- + array( + "value" => "b\"r", + "arguments" => array(), + ), + "bar" => array( + "value" => "b\"z", + "arguments" => array(), + ), + "a[][]" => array( + "value" => "1", + "arguments" => array(), + ), +); +var_dump($c === $p->params); +var_dump("foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1" === (string) $p); +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE diff --git a/tests/params008.phpt b/tests/params008.phpt new file mode 100644 index 0000000..463a96c --- /dev/null +++ b/tests/params008.phpt @@ -0,0 +1,37 @@ +--TEST-- +querystring params +--SKIPIF-- + +--FILE-- + array( + "value" => "b\"r", + "arguments" => array(), + ), + "bar" => array( + "value" => "b\"z", + "arguments" => array(), + ), + "a" => array( + "value" => array( + array("1") + ), + "arguments" => array(), + ), +); +var_dump($c === $p->params); +var_dump("foo=b%22r&bar=b%22z&a%5B0%5D%5B0%5D=1" === (string) $p); +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE diff --git a/tests/params009.phpt b/tests/params009.phpt new file mode 100644 index 0000000..07c58c7 --- /dev/null +++ b/tests/params009.phpt @@ -0,0 +1,17 @@ +--TEST-- +empty params +--SKIPIF-- + +--FILE-- +params); +?> +DONE +--EXPECT-- +Test +bool(true) +DONE diff --git a/tests/params010.phpt b/tests/params010.phpt new file mode 100644 index 0000000..ced5e92 --- /dev/null +++ b/tests/params010.phpt @@ -0,0 +1,21 @@ +--TEST-- +int key params +--SKIPIF-- + +--FILE-- + array("value" => "nothing", "arguments" => array(1=>"yes"))) === $p->params); +var_dump("0=nothing;1=yes" === $p->toString()); + +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE diff --git a/tests/params011.phpt b/tests/params011.phpt new file mode 100644 index 0000000..1f9ecf7 --- /dev/null +++ b/tests/params011.phpt @@ -0,0 +1,23 @@ +--TEST-- +bool args params +--SKIPIF-- + +--FILE-- + false, "arguments" => array("wrong" => false, "correct" => true)); +$p["container"] = $container; +var_dump("container=0;wrong=0;correct" === $p->toString()); +var_dump(array("container" => $container) === $p->toArray()); + +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE diff --git a/tests/params012.phpt b/tests/params012.phpt new file mode 100644 index 0000000..f5a33ca --- /dev/null +++ b/tests/params012.phpt @@ -0,0 +1,22 @@ +--TEST-- +no args params +--SKIPIF-- + +--FILE-- +toString()); +$p["param"] = false; +var_dump("param=0" === $p->toString()); +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE -- 2.30.2