diff options
| author | andy wharmby <wharmby@php.net> | 2009-06-23 22:39:44 +0000 |
|---|---|---|
| committer | andy wharmby <wharmby@php.net> | 2009-06-23 22:39:44 +0000 |
| commit | e6f4ec2f07f4de67be25d9f4b62c10a9238b1a31 (patch) | |
| tree | f4861351c3cd1eef7db89c8670b61562d072bd33 /ext | |
| parent | 0fa4242464e8dc2c605a92831e285afb18de44a2 (diff) | |
| download | php-git-e6f4ec2f07f4de67be25d9f4b62c10a9238b1a31.tar.gz | |
New basic parse_str() tests. Tested on Windows,Linux and Lnux 64 bit. Some tests fail on PHP 6 (tagged with XFAIL) due to bug 48658
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/standard/tests/strings/parse_str_basic1.phpt | 76 | ||||
| -rw-r--r-- | ext/standard/tests/strings/parse_str_basic2.phpt | 26 | ||||
| -rw-r--r-- | ext/standard/tests/strings/parse_str_basic3.phpt | 266 | ||||
| -rw-r--r-- | ext/standard/tests/strings/parse_str_basic4.phpt | 76 | ||||
| -rw-r--r-- | ext/standard/tests/strings/parse_str_error1.phpt | 32 |
5 files changed, 476 insertions, 0 deletions
diff --git a/ext/standard/tests/strings/parse_str_basic1.phpt b/ext/standard/tests/strings/parse_str_basic1.phpt new file mode 100644 index 0000000000..7a8fda80db --- /dev/null +++ b/ext/standard/tests/strings/parse_str_basic1.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test parse_str() function : basic functionality +--FILE-- +<?php + +/* Prototype : void parse_str ( string $str [, array &$arr ] ) + * Description: Parses the string into variables + * Source code: ext/standard/string.c +*/ + +echo "*** Testing parse_str() : basic functionality ***\n"; + +echo "Basic test WITHOUT result arg\n"; +$s1 = "first=val1&second=val2&third=val3"; +var_dump(parse_str($s1)); +var_dump($first, $second, $third); + +echo "\nBasic test WITH undefined var for result arg\n"; +$s1 = "first=val1&second=val2&third=val3"; +var_dump(parse_str($s1, $res1)); +var_dump($res1); + +echo "\nBasic test WITH existing non-array var for result arg\n"; +$res2 =99; +$s1 = "first=val1&second=val2&third=val3"; +var_dump(parse_str($s1, $res2)); +var_dump($res2); + +echo "\nBasic test with an existing array as results array\n"; +$res3_array = array(1,2,3,4); +var_dump(parse_str($s1, $res3_array)); +var_dump($res3_array); + +?> +===DONE=== +--EXPECTF-- +*** Testing parse_str() : basic functionality *** +Basic test WITHOUT result arg +NULL +string(4) "val1" +string(4) "val2" +string(4) "val3" + +Basic test WITH undefined var for result arg +NULL +array(3) { + ["first"]=> + string(4) "val1" + ["second"]=> + string(4) "val2" + ["third"]=> + string(4) "val3" +} + +Basic test WITH existing non-array var for result arg +NULL +array(3) { + ["first"]=> + string(4) "val1" + ["second"]=> + string(4) "val2" + ["third"]=> + string(4) "val3" +} + +Basic test with an existing array as results array +NULL +array(3) { + ["first"]=> + string(4) "val1" + ["second"]=> + string(4) "val2" + ["third"]=> + string(4) "val3" +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/parse_str_basic2.phpt b/ext/standard/tests/strings/parse_str_basic2.phpt new file mode 100644 index 0000000000..e42c9caaa4 --- /dev/null +++ b/ext/standard/tests/strings/parse_str_basic2.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test parse_str() function : non-default arg_separator.input specified +--INI-- +arg_separator.input = "/" +--FILE-- +<?php +/* Prototype : void parse_str ( string $str [, array &$arr ] ) + * Description: Parses the string into variables + * Source code: ext/standard/string.c +*/ + +echo "*** Testing parse_str() : non-default arg_separator.input specified ***\n"; + +$s1 = "first=val1/second=val2/third=val3"; +var_dump(parse_str($s1)); +var_dump($first, $second, $third); + +?> +===DONE=== +--EXPECTF-- +*** Testing parse_str() : non-default arg_separator.input specified *** +NULL +string(4) "val1" +string(4) "val2" +string(4) "val3" +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/parse_str_basic3.phpt b/ext/standard/tests/strings/parse_str_basic3.phpt new file mode 100644 index 0000000000..a600fe01e1 --- /dev/null +++ b/ext/standard/tests/strings/parse_str_basic3.phpt @@ -0,0 +1,266 @@ +--TEST-- +Test parse_str() function : basic functionality +--FILE-- +<?php +/* Prototype : void parse_str ( string $str [, array &$arr ] ) + * Description: Parses the string into variables + * Source code: ext/standard/string.c +*/ +echo "*** Testing parse_str() : basic functionality ***\n"; + +echo "\nTest string with array values\n"; +$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last"; +var_dump(parse_str($s1)); +var_dump($first, $a, $b, $c); + +echo "\nTest string with array values and results array\n"; +$s1 = "first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last"; +var_dump(parse_str($s1, $res3_array)); +var_dump($res3_array); + +echo "\nTest string containing numerical array keys\n"; +$str = "arr[1]=sid&arr[4]=bill"; +var_dump(parse_str($str, $res)); +var_dump($res); + +echo "\nTest string containing associative keys\n"; +$str = "arr[first]=sid&arr[forth]=bill"; +var_dump(parse_str($str, $res)); +var_dump($res); + +echo "\nTest string with array values with same name as existing variable\n"; +$a = 9999; +$s1 = "a[]=123&a[]=false&a[]=last"; +var_dump(parse_str($s1)); +var_dump($a); + +echo "\nTest string with non-array value with same name as existing array variable\n"; +$a = array(10,11,12,13); +$s1 = "a=999"; +parse_str($s1); +var_dump($a); + +echo "\nTest string with encoded data\n"; +$s1 = "a=%3c%3d%3d%20%20foo+bar++%3d%3d%3e&b=%23%23%23Hello+World%23%23%23"; +parse_str($s1); +var_dump($a, $b); + +echo "\nTest string with single quotes characters\n"; +$s1 = "firstname=Bill&surname=O%27Reilly"; +var_dump(parse_str($s1)); +var_dump($firstname, $surname); + +echo "\nTest string with backslash characters\n"; +$s1 = "sum=10%5c2%3d5"; +var_dump(parse_str($s1)); +var_dump($sum); + +echo "\nTest string with double quotes data\n"; +$s1 = "str=A+string+with+%22quoted%22+strings"; +var_dump(parse_str($s1)); +var_dump($str); + +echo "\nTest string with nulls\n"; +$s1 = "str=A%20string%20with%20containing%20%00%00%00%20nulls"; +var_dump(parse_str($s1)); +var_dump($str); + +echo "\nTest string with 2-dim array with numeric keys\n"; +$str = "arr[3][4]=sid&arr[3][6]=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +echo "\nTest string with 2-dim array with null keys\n"; +$str = "arr[][]=sid&arr[][]=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +echo "\nTest string with 2-dim array with non-numeric keys\n"; +$str = "arr[one][four]=sid&arr[three][six]=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +echo "\nTest string with 3-dim array with numeric keys\n"; +$str = "arr[1][2][3]=sid&arr[1][2][6]=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +?> +===DONE=== +--EXPECTF-- +*** Testing parse_str() : basic functionality *** + +Test string with array values +NULL +string(3) "abc" +array(3) { + [0]=> + string(3) "123" + [1]=> + string(5) "false" + [2]=> + string(4) "last" +} +array(1) { + [0]=> + string(3) "str" +} +array(1) { + [0]=> + string(3) "3.5" +} + +Test string with array values and results array +NULL +array(4) { + ["first"]=> + string(3) "abc" + ["a"]=> + array(3) { + [0]=> + string(3) "123" + [1]=> + string(5) "false" + [2]=> + string(4) "last" + } + ["b"]=> + array(1) { + [0]=> + string(3) "str" + } + ["c"]=> + array(1) { + [0]=> + string(3) "3.5" + } +} + +Test string containing numerical array keys +NULL +array(1) { + ["arr"]=> + array(2) { + [1]=> + string(3) "sid" + [4]=> + string(4) "bill" + } +} + +Test string containing associative keys +NULL +array(1) { + ["arr"]=> + array(2) { + ["first"]=> + string(3) "sid" + ["forth"]=> + string(4) "bill" + } +} + +Test string with array values with same name as existing variable +NULL +array(3) { + [0]=> + string(3) "123" + [1]=> + string(5) "false" + [2]=> + string(4) "last" +} + +Test string with non-array value with same name as existing array variable +string(3) "999" + +Test string with encoded data +string(17) "<== foo bar ==>" +string(17) "###Hello World###" + +Test string with single quotes characters +NULL +string(4) "Bill" +string(9) "O\'Reilly" + +Test string with backslash characters +NULL +string(7) "10\\2=5" + +Test string with double quotes data +NULL +string(32) "A string with \"quoted\" strings" + +Test string with nulls +NULL +string(37) "A string with containing \0\0\0 nulls" + +Test string with 2-dim array with numeric keys +NULL +array(1) { + ["arr"]=> + array(1) { + [3]=> + array(2) { + [4]=> + string(3) "sid" + [6]=> + string(4) "fred" + } + } +} + +Test string with 2-dim array with null keys +NULL +array(1) { + ["arr"]=> + array(2) { + [0]=> + array(1) { + [0]=> + string(3) "sid" + } + [1]=> + array(1) { + [0]=> + string(4) "fred" + } + } +} + +Test string with 2-dim array with non-numeric keys +NULL +array(1) { + ["arr"]=> + array(2) { + ["one"]=> + array(1) { + ["four"]=> + string(3) "sid" + } + ["three"]=> + array(1) { + ["six"]=> + string(4) "fred" + } + } +} + +Test string with 3-dim array with numeric keys +NULL +array(1) { + ["arr"]=> + array(1) { + [1]=> + array(1) { + [2]=> + array(2) { + [3]=> + string(3) "sid" + [6]=> + string(4) "fred" + } + } + } +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/parse_str_basic4.phpt b/ext/standard/tests/strings/parse_str_basic4.phpt new file mode 100644 index 0000000000..0e4baf8d7a --- /dev/null +++ b/ext/standard/tests/strings/parse_str_basic4.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test parse_str() function : test with badly formed strings +--FILE-- +<?php +/* Prototype : void parse_str ( string $str [, array &$arr ] ) + * Description: Parses the string into variables + * Source code: ext/standard/string.c +*/ + +echo "\nTest string with badly formed strings\n"; +$str = "arr[1=sid&arr[4][2=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +$str = "arr1]=sid&arr[4]2]=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +$str = "arr[one=sid&arr[4][two=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); + +echo "\nTest string with non-binary safe name\n"; +$str = "arr.test[1]=sid&arr test[4][two]=fred"; +var_dump(parse_str($str, $res)); +var_dump($res); +?> +===DONE=== +--EXPECTF-- +Test string with badly formed strings +NULL +array(2) { + ["arr_1"]=> + string(3) "sid" + ["arr"]=> + array(1) { + [4]=> + string(4) "fred" + } +} +NULL +array(2) { + ["arr1]"]=> + string(3) "sid" + ["arr"]=> + array(1) { + [4]=> + string(4) "fred" + } +} +NULL +array(2) { + ["arr_one"]=> + string(3) "sid" + ["arr"]=> + array(1) { + [4]=> + string(4) "fred" + } +} + +Test string with non-binary safe name +NULL +array(1) { + ["arr_test"]=> + array(2) { + [1]=> + string(3) "sid" + [4]=> + array(1) { + ["two"]=> + string(4) "fred" + } + } +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/parse_str_error1.phpt b/ext/standard/tests/strings/parse_str_error1.phpt new file mode 100644 index 0000000000..a9c902e807 --- /dev/null +++ b/ext/standard/tests/strings/parse_str_error1.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test parse_str() function : non-default arg_separator.input specified +--INI-- +arg_separator.input = "/" +--FILE-- +<?php +/* Prototype : void parse_str ( string $str [, array &$arr ] ) + * Description: Parses the string into variables + * Source code: ext/standard/string.c +*/ + +echo "*** Testing parse_str() : error conditions ***\n"; + +echo "\n-- Testing htmlentities() function with less than expected no. of arguments --\n"; +parse_str(); +echo "\n-- Testing htmlentities() function with more than expected no. of arguments --\n"; +$s1 = "first=val1&second=val2&third=val3"; +parse_str($s1, $res_array, true); + +?> +===DONE=== +--EXPECTF-- +*** Testing parse_str() : error conditions *** + +-- Testing htmlentities() function with less than expected no. of arguments -- + +Warning: parse_str() expects at least 1 parameter, 0 given in %s on line %d + +-- Testing htmlentities() function with more than expected no. of arguments -- + +Warning: parse_str() expects at most 2 parameters, 3 given in %s on line %d +===DONE===
\ No newline at end of file |
