port querystring tests
authorMichael Wallner <mike@php.net>
Wed, 9 Jul 2014 15:40:14 +0000 (17:40 +0200)
committerMichael Wallner <mike@php.net>
Wed, 9 Jul 2014 15:40:14 +0000 (17:40 +0200)
phpunit/QueryStringTest.php [deleted file]
tests/querystring001.phpt [new file with mode: 0644]
tests/querystring002.phpt [new file with mode: 0644]
tests/querystring_001.phpt [deleted file]

diff --git a/phpunit/QueryStringTest.php b/phpunit/QueryStringTest.php
deleted file mode 100644 (file)
index fb2eb47..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-class QueryStringTest extends PHPUnit_Framework_TestCase {
-    protected $q;
-    protected $s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=01&1=2";
-    protected $e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B0%5D%5B1%5D=01&1=2";
-
-    function setUp() {
-        $this->q = new http\QueryString($this->s);
-    }
-
-    function testSimple() {
-        $this->assertEquals($this->e, (string) $this->q);
-        $this->assertEquals($this->e, $this->q->get());
-    }
-
-    function testGetDefval() {
-        $this->assertEquals("nonexistant", $this->q->get("unknown", "s", "nonexistant"));
-        $this->assertEquals(null, $this->q->get("unknown"));
-    }
-
-    function testGetA() {
-        $this->assertEquals("b", $this->q->get("a"));
-        $this->assertEquals(0, $this->q->get("a", "i"));
-        $this->assertEquals(array("b"), $this->q->get("a", "a"));
-        $this->assertEquals((object)array("scalar" => "b"), $this->q->get("a", "o"));
-    }
-
-    function testGetR() {
-        $this->assertEquals(array(0,1,2), $this->q->get("r"));
-    }
-
-    function testGetRR() {
-        $this->assertEquals(array(array("00","01")), $this->q->get("rr"));
-    }
-
-    function testGet1() {
-        $this->assertEquals(2, $this->q->get(1));
-        $this->assertEquals("2", $this->q->get(1, "s"));
-        $this->assertEquals(2.0, $this->q->get(1, "f"));
-        $this->assertTrue($this->q->get(1, "b"));
-    }
-
-    function testDelA() {
-        $this->assertEquals("b", $this->q->get("a", http\QueryString::TYPE_STRING, null, true));
-        $this->assertEquals(null, $this->q->get("a"));
-    }
-
-    function testDelAll() {
-        $this->q->set(array("a" => null, "r" => null, "rr" => null, 1 => null));
-        $this->assertEquals("", $this->q->toString());
-    }
-
-    function testQSO() {
-        $this->assertEquals($this->e, (string) new http\QueryString($this->q));
-        $this->assertEquals(http_build_query(array("e"=>$this->q->toArray())), (string) new http\QueryString(array("e" => $this->q)));
-    }
-
-    function testIterator() {
-        $this->assertEquals($this->q->toArray(), iterator_to_array($this->q));
-    }
-
-    function testSerialize() {
-        $this->assertEquals($this->e, (string) unserialize(serialize($this->q)));
-    }
-}
diff --git a/tests/querystring001.phpt b/tests/querystring001.phpt
new file mode 100644 (file)
index 0000000..203be33
--- /dev/null
@@ -0,0 +1,179 @@
+--TEST--
+query string
+--SKIPIF--
+<?php
+include("skipif.inc");
+?>
+--GET--
+str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
+--FILE--
+<?php
+echo "Test\n";
+
+printf("\nGlobal instance:\n");
+$q = http\QueryString::getGlobalInstance();
+printf("%s\n", $q);
+
+printf("\nStandard getters:\n");
+var_dump($q->getString("str"));
+var_dump($q->getInt("num"));
+var_dump($q->getFloat("dec"));
+var_dump($q->getInt("dec"));
+var_dump($q->getFloat("dec"));
+var_dump($q->getBool("bool"));
+var_dump($q->getInt("bool"));
+var_dump($q->getBool("num"));
+var_dump($q->getInt("num"));
+var_dump($q->getArray("arr"));
+var_dump($q->getArray("ma"));
+var_dump($q->getObject("arr"));
+var_dump($q->getObject("ma"));
+
+$s = $q->toString();
+
+printf("\nClone modifications do not alter global instance:\n");
+$q->mod(array("arr" => array(3 => 3)));
+printf("%s\n", $q);
+
+printf("\nClone modifications do not alter standard instance:\n");
+$q2 = new http\QueryString($s);
+$q3 = $q2->mod(array("arr" => array(3 => 3)));
+printf("%s\n%s\n", $q2, $q3);
+#var_dump($q2, $q3);
+
+printf("\nIterator:\n");
+$it = new RecursiveIteratorIterator($q2, RecursiveIteratorIterator::SELF_FIRST);
+foreach ($it as $k => $v) {
+       $i = $it->getDepth()*8;
+       @printf("%{$i}s: %s\n", $k, $v); 
+}
+
+printf("\nReplace a multi dimensional key:\n");
+printf("%s\n", $q2->mod(array("ma" => null))->set(array("ma" => array("l1" => false))));
+
+printf("\nXlate:\n");
+$qu = new http\QueryString("ü=ö");
+printf("utf8:   %s\n", $qu);
+printf("latin1: %s\n", method_exists($qu, "xlate") ? $qu->xlate("utf-8", "latin1") : "%FC=%F6");
+
+printf("\nOffsets:\n");
+var_dump($q2["ma"]);
+$q2["ma"] = array("bye");
+var_dump($q2["ma"]);
+var_dump(isset($q2["ma"]));
+unset($q2["ma"]);
+var_dump(isset($q2["ma"]));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Test
+
+Global instance:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+
+Standard getters:
+string(3) "abc"
+int(-123)
+float(123.123)
+int(123)
+float(123.123)
+bool(true)
+int(1)
+bool(true)
+int(-123)
+array(2) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(1) "2"
+}
+array(2) {
+  ["l1"]=>
+  array(1) {
+    ["l2"]=>
+    string(1) "2"
+  }
+  ["l2"]=>
+  array(1) {
+    ["l3"]=>
+    array(1) {
+      ["l4"]=>
+      string(1) "3"
+    }
+  }
+}
+object(stdClass)#%d (2) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(1) "2"
+}
+object(stdClass)#%d (2) {
+  ["l1"]=>
+  array(1) {
+    ["l2"]=>
+    string(1) "2"
+  }
+  ["l2"]=>
+  array(1) {
+    ["l3"]=>
+    array(1) {
+      ["l4"]=>
+      string(1) "3"
+    }
+  }
+}
+
+Clone modifications do not alter global instance:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+
+Clone modifications do not alter standard instance:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&arr%5B3%5D=3&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+
+Iterator:
+str: abc
+num: -123
+dec: 123.123
+bool: 1
+arr: Array
+       0: 1
+       1: 2
+ma: Array
+      l1: Array
+              l2: 2
+      l2: Array
+              l3: Array
+                      l4: 3
+
+Replace a multi dimensional key:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D=
+
+Xlate:
+utf8:   %C3%BC=%C3%B6
+latin1: %FC=%F6
+
+Offsets:
+array(2) {
+  ["l1"]=>
+  array(1) {
+    ["l2"]=>
+    string(1) "2"
+  }
+  ["l2"]=>
+  array(1) {
+    ["l3"]=>
+    array(1) {
+      ["l4"]=>
+      string(1) "3"
+    }
+  }
+}
+array(1) {
+  [0]=>
+  string(3) "bye"
+}
+bool(true)
+bool(false)
+Done
diff --git a/tests/querystring002.phpt b/tests/querystring002.phpt
new file mode 100644 (file)
index 0000000..ab82672
--- /dev/null
@@ -0,0 +1,95 @@
+--TEST--
+query string
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=01&1=2";
+$e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B0%5D%5B1%5D=01&1=2";
+$q = new http\QueryString($s);
+
+var_dump($e === (string) $q);
+var_dump($e === $q->get());
+
+printf("Get defval\n");
+var_dump("nonexistant" === $q->get("unknown", "s", "nonexistant"));
+var_dump(null === $q->get("unknown"));
+
+printf("Get 'a'\n");
+var_dump("b" === $q->get("a"));
+var_dump(0 === $q->get("a", "i"));
+var_dump(array("b") === $q->get("a", "a"));
+var_dump((object)array("scalar" => "b") == $q->get("a", "o"));
+
+printf("Get 'r'\n");
+var_dump(array("0","1","2") === $q->get("r"));
+
+printf("Get 'rr'\n");
+var_dump(array(array("00","01")) === $q->get("rr"));
+
+printf("Get 1\n");
+var_dump(2 == $q->get(1));
+var_dump("2" === $q->get(1, "s"));
+var_dump(2.0 === $q->get(1, "f"));
+var_dump($q->get(1, "b"));
+
+printf("Del 'a'\n");
+var_dump("b" === $q->get("a", http\QueryString::TYPE_STRING, null, true));
+var_dump(null === $q->get("a"));
+
+printf("Del all\n");
+$q->set(array("a" => null, "r" => null, "rr" => null, 1 => null));
+var_dump("" === $q->toString());
+
+$q = new http\QueryString($s);
+
+printf("QSO\n");
+var_dump($e === (string) new http\QueryString($q));
+var_dump(http_build_query(array("e"=>$q->toArray())) === (string) new http\QueryString(array("e" => $q)));
+
+printf("Iterator\n");
+var_dump($q->toArray() === iterator_to_array($q));
+
+printf("Serialize\n");
+var_dump($e === (string) unserialize(serialize($q)));
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Get defval
+bool(true)
+bool(true)
+Get 'a'
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Get 'r'
+bool(true)
+Get 'rr'
+bool(true)
+Get 1
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Del 'a'
+bool(true)
+bool(true)
+Del all
+bool(true)
+QSO
+bool(true)
+bool(true)
+Iterator
+bool(true)
+Serialize
+bool(true)
+DONE
diff --git a/tests/querystring_001.phpt b/tests/querystring_001.phpt
deleted file mode 100644 (file)
index 203be33..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
---TEST--
-query string
---SKIPIF--
-<?php
-include("skipif.inc");
-?>
---GET--
-str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
---FILE--
-<?php
-echo "Test\n";
-
-printf("\nGlobal instance:\n");
-$q = http\QueryString::getGlobalInstance();
-printf("%s\n", $q);
-
-printf("\nStandard getters:\n");
-var_dump($q->getString("str"));
-var_dump($q->getInt("num"));
-var_dump($q->getFloat("dec"));
-var_dump($q->getInt("dec"));
-var_dump($q->getFloat("dec"));
-var_dump($q->getBool("bool"));
-var_dump($q->getInt("bool"));
-var_dump($q->getBool("num"));
-var_dump($q->getInt("num"));
-var_dump($q->getArray("arr"));
-var_dump($q->getArray("ma"));
-var_dump($q->getObject("arr"));
-var_dump($q->getObject("ma"));
-
-$s = $q->toString();
-
-printf("\nClone modifications do not alter global instance:\n");
-$q->mod(array("arr" => array(3 => 3)));
-printf("%s\n", $q);
-
-printf("\nClone modifications do not alter standard instance:\n");
-$q2 = new http\QueryString($s);
-$q3 = $q2->mod(array("arr" => array(3 => 3)));
-printf("%s\n%s\n", $q2, $q3);
-#var_dump($q2, $q3);
-
-printf("\nIterator:\n");
-$it = new RecursiveIteratorIterator($q2, RecursiveIteratorIterator::SELF_FIRST);
-foreach ($it as $k => $v) {
-       $i = $it->getDepth()*8;
-       @printf("%{$i}s: %s\n", $k, $v); 
-}
-
-printf("\nReplace a multi dimensional key:\n");
-printf("%s\n", $q2->mod(array("ma" => null))->set(array("ma" => array("l1" => false))));
-
-printf("\nXlate:\n");
-$qu = new http\QueryString("ü=ö");
-printf("utf8:   %s\n", $qu);
-printf("latin1: %s\n", method_exists($qu, "xlate") ? $qu->xlate("utf-8", "latin1") : "%FC=%F6");
-
-printf("\nOffsets:\n");
-var_dump($q2["ma"]);
-$q2["ma"] = array("bye");
-var_dump($q2["ma"]);
-var_dump(isset($q2["ma"]));
-unset($q2["ma"]);
-var_dump(isset($q2["ma"]));
-
-echo "Done\n";
-?>
---EXPECTF--
-Test
-
-Global instance:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-
-Standard getters:
-string(3) "abc"
-int(-123)
-float(123.123)
-int(123)
-float(123.123)
-bool(true)
-int(1)
-bool(true)
-int(-123)
-array(2) {
-  [0]=>
-  string(1) "1"
-  [1]=>
-  string(1) "2"
-}
-array(2) {
-  ["l1"]=>
-  array(1) {
-    ["l2"]=>
-    string(1) "2"
-  }
-  ["l2"]=>
-  array(1) {
-    ["l3"]=>
-    array(1) {
-      ["l4"]=>
-      string(1) "3"
-    }
-  }
-}
-object(stdClass)#%d (2) {
-  [0]=>
-  string(1) "1"
-  [1]=>
-  string(1) "2"
-}
-object(stdClass)#%d (2) {
-  ["l1"]=>
-  array(1) {
-    ["l2"]=>
-    string(1) "2"
-  }
-  ["l2"]=>
-  array(1) {
-    ["l3"]=>
-    array(1) {
-      ["l4"]=>
-      string(1) "3"
-    }
-  }
-}
-
-Clone modifications do not alter global instance:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-
-Clone modifications do not alter standard instance:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&arr%5B3%5D=3&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-
-Iterator:
-str: abc
-num: -123
-dec: 123.123
-bool: 1
-arr: Array
-       0: 1
-       1: 2
-ma: Array
-      l1: Array
-              l2: 2
-      l2: Array
-              l3: Array
-                      l4: 3
-
-Replace a multi dimensional key:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D=
-
-Xlate:
-utf8:   %C3%BC=%C3%B6
-latin1: %FC=%F6
-
-Offsets:
-array(2) {
-  ["l1"]=>
-  array(1) {
-    ["l2"]=>
-    string(1) "2"
-  }
-  ["l2"]=>
-  array(1) {
-    ["l3"]=>
-    array(1) {
-      ["l4"]=>
-      string(1) "3"
-    }
-  }
-}
-array(1) {
-  [0]=>
-  string(3) "bye"
-}
-bool(true)
-bool(false)
-Done