unfold param tests
authorMichael Wallner <mike@php.net>
Wed, 9 Jul 2014 14:27:52 +0000 (16:27 +0200)
committerMichael Wallner <mike@php.net>
Wed, 9 Jul 2014 14:27:52 +0000 (16:27 +0200)
12 files changed:
phpunit/ParamsTest.php [deleted file]
tests/params001.phpt
tests/params003.phpt [new file with mode: 0644]
tests/params004.phpt [new file with mode: 0644]
tests/params005.phpt [new file with mode: 0644]
tests/params006.phpt [new file with mode: 0644]
tests/params007.phpt [new file with mode: 0644]
tests/params008.phpt [new file with mode: 0644]
tests/params009.phpt [new file with mode: 0644]
tests/params010.phpt [new file with mode: 0644]
tests/params011.phpt [new file with mode: 0644]
tests/params012.phpt [new file with mode: 0644]

diff --git a/phpunit/ParamsTest.php b/phpunit/ParamsTest.php
deleted file mode 100644 (file)
index 71bfcf4..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-<?php
-
-class ParamsTest extends PHPUnit_Framework_TestCase {
-    function testDefault() {
-        $s = "foo, bar;arg=0;bla, gotit=0;now";
-        $this->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());
-       }
-}
index ac52bf7a940c049f7555a83f740551a400f73e2b..40b5e157583d43049d084b22f17ceb268b5fb676 100644 (file)
@@ -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 (file)
index 0000000..11e2759
--- /dev/null
@@ -0,0 +1,97 @@
+--TEST--
+default params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "foo, bar;arg=0;bla, gotit=0;now";
+$p = new http\Params($s);
+$c = str_replace(" ", "", $s);
+$k = array("foo", "bar", "gotit");
+$a = array("foo"=>"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 (file)
index 0000000..69075ea
--- /dev/null
@@ -0,0 +1,97 @@
+--TEST--
+custom params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "foo bar.arg:0.bla gotit:0.now";
+$p = new http\Params($s, " ", ".", ":");
+$c = $s;
+$k = array("foo", "bar", "gotit");
+$a = array("foo"=>"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 (file)
index 0000000..7c64a31
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+quoted params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params("multipart/form-data; boundary=\"--123\"");
+$c = array(
+       "multipart/form-data" => 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 (file)
index 0000000..5c6455c
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+escaped params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params("form-data; name=\"upload\"; filename=\"trick\\\"\0\\\"ed\"");
+$c = array(
+       "form-data" => 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 (file)
index 0000000..c56e2fa
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+urlencoded params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
+$p = new http\Params($s, "&", "", "=", http\Params::PARSE_URLENCODED);
+$c = array(
+       "foo" => 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 (file)
index 0000000..463a96c
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+querystring params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
+$p = new http\Params($s, "&", "", "=", http\Params::PARSE_QUERY);
+$c = array(
+       "foo" => 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 (file)
index 0000000..07c58c7
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+empty params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$p = new http\Params(NULL);
+var_dump(array() === $p->params);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
diff --git a/tests/params010.phpt b/tests/params010.phpt
new file mode 100644 (file)
index 0000000..ced5e92
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+int key params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params("0=nothing;1=yes");
+var_dump(array("0" => 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 (file)
index 0000000..1f9ecf7
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+bool args params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params;
+$container = array("value" => 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 (file)
index 0000000..f5a33ca
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+no args params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params;
+$p["param"] = true;
+var_dump("param" === $p->toString());
+$p["param"] = false;
+var_dump("param=0" === $p->toString());
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE