From: Antony Dovgal Date: Tue, 6 Dec 2005 15:18:56 +0000 (+0000) Subject: add tests X-Git-Tag: RELEASE_1_0~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cebabed0a117f2e1f4981552e41773bcd9cfd52;p=php add tests Code covered: 91.3 % --- diff --git a/ext/filter/tests/004.phpt b/ext/filter/tests/004.phpt index afadd2639f..05ea952145 100644 --- a/ext/filter/tests/004.phpt +++ b/ext/filter/tests/004.phpt @@ -1,7 +1,7 @@ --TEST-- GET/POST/REQUEST Test with filtered data --INI-- -filter.default=notags +filter.default=special_chars --POST-- d="quotes"&e=\slash --GET-- diff --git a/ext/filter/tests/005.phpt b/ext/filter/tests/005.phpt index 07f7c5945c..b97baa4f5f 100644 --- a/ext/filter/tests/005.phpt +++ b/ext/filter/tests/005.phpt @@ -1,7 +1,7 @@ --TEST-- GET/REQUEST Test with fifa example data --INI-- -filter.default=notags +filter.default=stripped --POST-- --GET-- id=f03_photos&pgurl=http%3A//fifaworldcup.yahoo.com/03/en/photozone/index.html diff --git a/ext/filter/tests/007.phpt b/ext/filter/tests/007.phpt new file mode 100644 index 0000000000..ffc727801d --- /dev/null +++ b/ext/filter/tests/007.phpt @@ -0,0 +1,68 @@ +--TEST-- +input_has_variable() +--GET-- +a=qwe&abc=href +--POST-- +b=qwe&bbc=href +--FILE-- + +--EXPECTF-- +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +PHP Warning: input_has_variable() expects parameter 2 to be string, array given in %s on line %d + +Warning: input_has_variable() expects parameter 2 to be string, array given in %s on line %d +NULL +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +PHP Warning: input_has_variable() expects parameter 2 to be string, array given in %s on line %d + +Warning: input_has_variable() expects parameter 2 to be string, array given in %s on line %d +NULL +bool(false) +PHP Warning: input_has_variable() expects parameter 1 to be long, string given in %s on line %d + +Warning: input_has_variable() expects parameter 1 to be long, string given in %s on line %d +NULL +PHP Warning: input_has_variable() expects parameter 1 to be long, array given in %s on line %d + +Warning: input_has_variable() expects parameter 1 to be long, array given in %s on line %d +NULL +PHP Warning: input_has_variable() expects parameter 1 to be long, array given in %s on line %d + +Warning: input_has_variable() expects parameter 1 to be long, array given in %s on line %d +NULL +PHP Warning: input_has_variable() expects parameter 1 to be long, string given in %s on line %d + +Warning: input_has_variable() expects parameter 1 to be long, string given in %s on line %d +NULL +Done diff --git a/ext/filter/tests/008.phpt b/ext/filter/tests/008.phpt new file mode 100644 index 0000000000..62b41004c0 --- /dev/null +++ b/ext/filter/tests/008.phpt @@ -0,0 +1,90 @@ +--TEST-- +input_filters_list() +--GET-- + +--FILE-- + +--EXPECTF-- +array(18) { + [0]=> + string(3) "int" + [1]=> + string(7) "boolean" + [2]=> + string(5) "float" + [3]=> + string(15) "validate_regexp" + [4]=> + string(12) "validate_url" + [5]=> + string(14) "validate_email" + [6]=> + string(11) "validate_ip" + [7]=> + string(6) "string" + [8]=> + string(8) "stripped" + [9]=> + string(7) "encoded" + [10]=> + string(13) "special_chars" + [11]=> + string(10) "unsafe_raw" + [12]=> + string(5) "email" + [13]=> + string(3) "url" + [14]=> + string(10) "number_int" + [15]=> + string(12) "number_float" + [16]=> + string(12) "magic_quotes" + [17]=> + string(8) "callback" +} +array(18) { + [0]=> + string(3) "int" + [1]=> + string(7) "boolean" + [2]=> + string(5) "float" + [3]=> + string(15) "validate_regexp" + [4]=> + string(12) "validate_url" + [5]=> + string(14) "validate_email" + [6]=> + string(11) "validate_ip" + [7]=> + string(6) "string" + [8]=> + string(8) "stripped" + [9]=> + string(7) "encoded" + [10]=> + string(13) "special_chars" + [11]=> + string(10) "unsafe_raw" + [12]=> + string(5) "email" + [13]=> + string(3) "url" + [14]=> + string(10) "number_int" + [15]=> + string(12) "number_float" + [16]=> + string(12) "magic_quotes" + [17]=> + string(8) "callback" +} +Done diff --git a/ext/filter/tests/009.phpt b/ext/filter/tests/009.phpt new file mode 100644 index 0000000000..130c5b3e9d --- /dev/null +++ b/ext/filter/tests/009.phpt @@ -0,0 +1,34 @@ +--TEST-- +input_name_to_filter() +--GET-- + +--FILE-- + +--EXPECTF-- +int(513) +int(513) +int(518) +int(257) +NULL +PHP Warning: input_name_to_filter() expects parameter 1 to be string, array given in %s on line %d + +Warning: input_name_to_filter() expects parameter 1 to be string, array given in %s on line %d +NULL +NULL +PHP Warning: input_name_to_filter() expects exactly 1 parameter, 3 given in %s on line %d + +Warning: input_name_to_filter() expects exactly 1 parameter, 3 given in %s on line %d +NULL +Done diff --git a/ext/filter/tests/010.phpt b/ext/filter/tests/010.phpt new file mode 100644 index 0000000000..d58223168a --- /dev/null +++ b/ext/filter/tests/010.phpt @@ -0,0 +1,63 @@ +--TEST-- +filter_data() +--GET-- + +--FILE-- + +--EXPECTF-- +array(7) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(0) + [3]=> + int(-23234) + [4]=> + NULL + [5]=> + NULL + [6]=> + array(0) { + } +} +array(7) { + [0]=> + float(1.2) + [1]=> + float(1.7) + [2]=> + float(0) + [3]=> + float(-23234.123) + [4]=> + NULL + [5]=> + NULL + [6]=> + array(0) { + } +} +PHP Warning: filter_data() expects parameter 2 to be long, array given in %s on line %d + +Warning: filter_data() expects parameter 2 to be long, array given in %s on line %d +NULL +string(1) "1" +string(1) "1" +string(1) "1" +string(1) "1" +string(1) "1" +Done diff --git a/ext/filter/tests/011.phpt b/ext/filter/tests/011.phpt new file mode 100644 index 0000000000..a2e4b5b62c --- /dev/null +++ b/ext/filter/tests/011.phpt @@ -0,0 +1,49 @@ +--TEST-- +input_get() +--GET-- +a=test&b=http://example.com +--POST-- +c=

string

&d=12345.7 +--FILE-- + +--EXPECTF-- +string(4) "test" +string(18) "http://example.com" +string(27) "<b>test</b>" +NULL +string(6) "string" +float(12345.7) +string(29) "<p>string</p>" +NULL +PHP Warning: input_get() expects parameter 1 to be long, object given in %s on line %d + +Warning: input_get() expects parameter 1 to be long, object given in %s on line %d +NULL +PHP Warning: input_get() expects parameter 3 to be long, string given in %s on line %d + +Warning: input_get() expects parameter 3 to be long, string given in %s on line %d +NULL +PHP Warning: input_get() expects parameter 1 to be long, string given in %s on line %d + +Warning: input_get() expects parameter 1 to be long, string given in %s on line %d +NULL +bool(false) +Done diff --git a/ext/filter/tests/012.phpt b/ext/filter/tests/012.phpt new file mode 100644 index 0000000000..99b218de0a --- /dev/null +++ b/ext/filter/tests/012.phpt @@ -0,0 +1,18 @@ +--TEST-- +input_get() +--GET-- + +--FILE-- + +--EXPECT-- +bool(false) +bool(false) +bool(false) +Done diff --git a/ext/filter/tests/013.phpt b/ext/filter/tests/013.phpt new file mode 100644 index 0000000000..6aad0c8946 --- /dev/null +++ b/ext/filter/tests/013.phpt @@ -0,0 +1,42 @@ +--TEST-- +filter_data() and flags +--GET-- + +--FILE-- +FILTER_FLAG_ALLOW_HEX))); +var_dump(filter_data("07", FL_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))); +var_dump(filter_data("0xff0000", FL_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))); +var_dump(filter_data("0666", FL_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))); + +var_dump(filter_data("6", FL_INT, array("min_range"=>1, "max_range"=>7))); +var_dump(filter_data("6", FL_INT, array("min_range"=>0, "max_range"=>5))); +var_dump(filter_data(-1, FL_INT, array("min_range"=>1, "max_range"=>7))); +var_dump(filter_data(-1, FL_INT, array("min_range"=>-4, "max_range"=>7))); + +var_dump(filter_data("", FL_INT, array("min_range"=>-4, "max_range"=>7))); +var_dump(filter_data("", FL_INT, array("min_range"=>2, "max_range"=>7))); +var_dump(filter_data("", FL_INT, array("min_range"=>-5, "max_range"=>-3))); +var_dump(filter_data(345, FL_INT, array("min_range"=>500, "max_range"=>100))); +var_dump(filter_data("0ff", FL_INT)); +var_dump(filter_data("010", FL_INT)); + +echo "Done\n"; +?> +--EXPECT-- +int(255) +int(7) +int(16711680) +int(438) +int(6) +NULL +NULL +int(-1) +int(0) +NULL +NULL +NULL +NULL +NULL +Done diff --git a/ext/filter/tests/014.phpt b/ext/filter/tests/014.phpt new file mode 100644 index 0000000000..49f0edfefa --- /dev/null +++ b/ext/filter/tests/014.phpt @@ -0,0 +1,44 @@ +--TEST-- +filter_data() and FL_BOOLEAN +--GET-- + +--FILE-- + +--EXPECTF-- +bool(false) +PHP Notice: Object of class stdClass to string conversion in %s on line %d + +Notice: Object of class stdClass to string conversion in %s on line %d +NULL +bool(true) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) +bool(true) +NULL +bool(false) +NULL +NULL +NULL +Done diff --git a/ext/filter/tests/015.phpt b/ext/filter/tests/015.phpt new file mode 100644 index 0000000000..7fef6b0bb2 --- /dev/null +++ b/ext/filter/tests/015.phpt @@ -0,0 +1,74 @@ +--TEST-- +filter_data() and FL_URL +--GET-- + +--FILE-- + +--EXPECTF-- +string(29) "http://example.com/index.html" +string(32) "http://www.example.com/index.php" +string(31) "http://www.example/img/test.png" +string(27) "http://www.example/img/dir/" +string(26) "http://www.example/img/dir" +string(28) "http//www.example/wrong/url/" +string(17) "http:/www.example" +string(18) "file:///tmp/test.c" +string(26) "ftp://ftp.example.com/tmp/" +string(11) "/tmp/test.c" +string(1) "/" +NULL +string(6) "http:/" +string(5) "http:" +string(4) "http" +string(0) "" +string(2) "-1" +array(0) { +} +NULL +string(10) "http://qwe" +NULL +NULL +string(22) "http://www.example.com" +NULL +string(42) "http://www.example.com/path/at/the/server/" +NULL +string(40) "http://www.example.com/index.php?a=b&c=d" +Done diff --git a/ext/filter/tests/016.phpt b/ext/filter/tests/016.phpt new file mode 100644 index 0000000000..66f85e1957 --- /dev/null +++ b/ext/filter/tests/016.phpt @@ -0,0 +1,34 @@ +--TEST-- +filter_data() and FL_EMAIL +--GET-- + +--FILE-- + +--EXPECT-- +string(5) "a@b.c" +string(17) "abuse@example.com" +NULL +NULL +NULL +NULL +NULL +NULL +string(57) "QWERTYUIOPASDFGHJKLZXCVBNM@QWERTYUIOPASDFGHJKLZXCVBNM.NET" +Done diff --git a/ext/filter/tests/017.phpt b/ext/filter/tests/017.phpt new file mode 100644 index 0000000000..bc2aae2030 --- /dev/null +++ b/ext/filter/tests/017.phpt @@ -0,0 +1,27 @@ +--TEST-- +filter_data() and FL_REGEXP +--GET-- + +--FILE-- +'/.*/'))); +var_dump(filter_data("data", FL_REGEXP, array("regexp"=>'/^b(.*)/'))); +var_dump(filter_data("data", FL_REGEXP, array("regexp"=>'/^d(.*)/'))); +var_dump(filter_data("data", FL_REGEXP, array("regexp"=>'blah'))); +var_dump(filter_data("data", FL_REGEXP, array("regexp"=>'['))); +var_dump(filter_data("data", FL_REGEXP)); + +echo "Done\n"; +?> +--EXPECTF-- +string(4) "data" +NULL +string(4) "data" +NULL +NULL +PHP Warning: filter_data(): 'regexp' option missing in %s on line %d + +Warning: filter_data(): 'regexp' option missing in %s on line %d +NULL +Done diff --git a/ext/filter/tests/018.phpt b/ext/filter/tests/018.phpt new file mode 100644 index 0000000000..39960287dc --- /dev/null +++ b/ext/filter/tests/018.phpt @@ -0,0 +1,57 @@ +--TEST-- +filter_data() and FL_IP +--GET-- + +--FILE-- + +--EXPECT-- +string(11) "192.168.0.1" +NULL +string(3) "::1" +string(7) "fe00::0" +NULL +NULL +string(9) "127.0.0.1" +NULL +string(12) "192.0.34.166" +string(9) "127.0.0.1" +string(9) "192.0.0.1" +string(12) "192.0.34.166" +NULL +string(15) "255.255.255.255" +NULL +NULL +NULL +NULL +NULL +string(3) "::1" +string(9) "127.0.0.1" +Done diff --git a/ext/filter/tests/019.phpt b/ext/filter/tests/019.phpt new file mode 100644 index 0000000000..505f783bcb --- /dev/null +++ b/ext/filter/tests/019.phpt @@ -0,0 +1,22 @@ +--TEST-- +filter_data() & FL_IP and weird data +--GET-- + +--FILE-- + +--EXPECTF-- +NULL +NULL +NULL +NULL +string(7) "1.1.1.1" +Done diff --git a/ext/filter/tests/020.phpt b/ext/filter/tests/020.phpt new file mode 100644 index 0000000000..cbd525c8ed --- /dev/null +++ b/ext/filter/tests/020.phpt @@ -0,0 +1,20 @@ +--TEST-- +filter_data() and FS_MAGIC_QUOTES +--GET-- + +--FILE-- + +--EXPECT-- +string(36) "test\'asd\'asd\'\' asd\\\'\"asdfasdf" +string(2) "\'" +string(0) "" +string(2) "-1" +Done diff --git a/ext/filter/tests/021.phpt b/ext/filter/tests/021.phpt new file mode 100644 index 0000000000..e27005fadb --- /dev/null +++ b/ext/filter/tests/021.phpt @@ -0,0 +1,46 @@ +--TEST-- +filter_data() and FS_NUMBER_* +--GET-- + +--FILE-- + +--EXPECT-- +string(6) "123456" +string(11) "12312312323" +string(5) "12323" +string(0) "" +string(1) "0" +string(4) "1232" +string(0) "" +string(5) "123.4" +string(4) "1234" +string(4) "1234" +string(5) "123,4" +string(5) "1234e" +string(5) "1234E" +string(4) "1234" +string(8) "65456.34" +string(6) "234.56" +string(0) "" +Done diff --git a/ext/filter/tests/022.phpt b/ext/filter/tests/022.phpt new file mode 100644 index 0000000000..aa1d85f834 --- /dev/null +++ b/ext/filter/tests/022.phpt @@ -0,0 +1,22 @@ +--TEST-- +filter_data() and FS_EMAIL +--GET-- + +--FILE-- + +--EXPECTF-- +string(5) "a@b.c" +string(30) "a[!@#$%^&*@a@#$%^&*.com@#$%^&*" +string(21) "whitespaceheresommore" +string(0) "" +string(15) "123456789000000" +Done diff --git a/ext/filter/tests/023.phpt b/ext/filter/tests/023.phpt new file mode 100644 index 0000000000..122e27ea39 --- /dev/null +++ b/ext/filter/tests/023.phpt @@ -0,0 +1,22 @@ +--TEST-- +filter_data() and FS_UNSAFE_RAW +--GET-- + +--FILE-- +test para

", FS_UNSAFE_RAW, FILTER_FLAG_ENCODE_AMP)); +var_dump(filter_data("a[!@#$%^&*()@a@#$%^&*(.
com@#$%^&*(", FS_UNSAFE_RAW, FILTER_FLAG_ENCODE_AMP)); +var_dump(filter_data("white space here \ \ \" some more", FS_UNSAFE_RAW, FILTER_FLAG_ENCODE_AMP)); +var_dump(filter_data("", FS_UNSAFE_RAW, FILTER_FLAG_ENCODE_AMP)); +var_dump(filter_data(" 123456789000000 ", FS_UNSAFE_RAW, FILTER_FLAG_ENCODE_AMP)); + +echo "Done\n"; +?> +--EXPECT-- +string(18) "}"

test para

" +string(53) "a[!@#$%^&*()@a@#$%^&*(.
com@#$%^&*(" +string(32) "white space here \ \ " some more" +string(0) "" +string(48) " 123456789000000 " +Done diff --git a/ext/filter/tests/024.phpt b/ext/filter/tests/024.phpt new file mode 100644 index 0000000000..459572d194 --- /dev/null +++ b/ext/filter/tests/024.phpt @@ -0,0 +1,20 @@ +--TEST-- +filter_data() and FS_ENCODED +--GET-- + +--FILE-- +blah", FS_ENCODED)); +var_dump(filter_data("", FS_ENCODED)); +var_dump(filter_data(" text here ", FS_ENCODED)); +var_dump(filter_data("!@#$%^&*()QWERTYUIOP{ASDFGHJKL:\"ZXCVBNM<>?", FS_ENCODED)); + +echo "Done\n"; +?> +--EXPECT-- +string(26) "%22%3Cbr%3Eblah%3C%2Fph%3E" +string(0) "" +string(23) "%20%20text%20here%20%20" +string(74) "%21%40%23%24%25%5E%26%2A%28%29QWERTYUIOP%7BASDFGHJKL%3A%22ZXCVBNM%3C%3E%3F" +Done diff --git a/ext/filter/tests/025.phpt b/ext/filter/tests/025.phpt new file mode 100644 index 0000000000..b7bf94585e --- /dev/null +++ b/ext/filter/tests/025.phpt @@ -0,0 +1,26 @@ +--TEST-- +filter_data() and FS_STRING +--GET-- + +--FILE-- +", FS_STRING)); +var_dump(filter_data("<>!@#$%^&*()'\"", FS_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); +var_dump(filter_data("<>!@#$%^&*()'\"", FS_STRING, FILTER_FLAG_ENCODE_AMP)); +var_dump(filter_data("<>`1234567890", FS_STRING)); +var_dump(filter_data("`123`", FS_STRING)); +var_dump(filter_data(".", FS_STRING)); + +echo "Done\n"; +?> +--EXPECT-- +NULL +NULL +string(12) "!@#$%^&*()'"" +string(32) "!@#$%^&*()&#39;&#34;" +string(11) "`1234567890" +string(5) "`123`" +string(1) "." +Done diff --git a/ext/filter/tests/026.phpt b/ext/filter/tests/026.phpt new file mode 100644 index 0000000000..21aaba10cd --- /dev/null +++ b/ext/filter/tests/026.phpt @@ -0,0 +1,32 @@ +--TEST-- +filter_data() and FS_STRIPPED +--GET-- + +--FILE-- +Let me see you
Stripped down to the bone

", FS_STRIPPED)); +var_dump(filter_data("!@#$%^&*()><<>+_\"'

  • ", FS_STRIPPED)); +var_dump(filter_data("", FS_STRIPPED)); + +var_dump(filter_data("

    Let me see you
    Stripped down to the bone

    ", FS_STRIPPED, FILTER_FLAG_STRIP_LOW)); +var_dump(filter_data("!@#$%^&*()><<>+_\"'

  • ", FS_STRIPPED, FILTER_FLAG_STRIP_LOW)); +var_dump(filter_data("", FS_STRIPPED, FILTER_FLAG_STRIP_LOW)); + +var_dump(filter_data("

    Let me see you
    Stripped down to the bone

    ", FS_STRIPPED, FILTER_FLAG_STRIP_HIGH)); +var_dump(filter_data("!@#$%^&*()><<>+_\"'

  • ", FS_STRIPPED, FILTER_FLAG_STRIP_HIGH)); +var_dump(filter_data("", FS_STRIPPED, FILTER_FLAG_STRIP_HIGH)); + +echo "Done\n"; +?> +--EXPECTF-- +string(40) "Let me see you Stripped down to the bone" +string(11) "!@#$%^&*()>" +NULL +string(40) "Let me see you Stripped down to the bone" +string(11) "!@#$%^&*()>" +NULL +string(40) "Let me see you Stripped down to the bone" +string(11) "!@#$%^&*()>" +NULL +Done diff --git a/ext/filter/tests/027.phpt b/ext/filter/tests/027.phpt new file mode 100644 index 0000000000..2532f1e119 --- /dev/null +++ b/ext/filter/tests/027.phpt @@ -0,0 +1,32 @@ +--TEST-- +filter_data() and FS_ENCODED +--GET-- + +--FILE-- +", FS_ENCODED)); +var_dump(filter_data("", FS_ENCODED)); + +var_dump(filter_data("?>", FS_ENCODED, FILTER_FLAG_ENCODE_LOW)); +var_dump(filter_data("", FS_ENCODED, FILTER_FLAG_ENCODE_LOW)); + +var_dump(filter_data("?>", FS_ENCODED, FILTER_FLAG_ENCODE_HIGH)); +var_dump(filter_data("", FS_ENCODED, FILTER_FLAG_ENCODE_HIGH)); + +echo "Done\n"; +?> +--EXPECT-- +string(75) "%3F%3E%3C%21%40%23%24%25%5E%26%2A%28%29%7D%7B%7EQwertyuilfdsasdfgmnbvcxcvbn" +string(17) "%3Cdata%26sons%3E" +string(0) "" +string(75) "%3F%3E%3C%21%40%23%24%25%5E%26%2A%28%29%7D%7B%7EQwertyuilfdsasdfgmnbvcxcvbn" +string(17) "%3Cdata%26sons%3E" +string(0) "" +string(75) "%3F%3E%3C%21%40%23%24%25%5E%26%2A%28%29%7D%7B%7EQwertyuilfdsasdfgmnbvcxcvbn" +string(17) "%3Cdata%26sons%3E" +string(0) "" +Done diff --git a/ext/filter/tests/028.phpt b/ext/filter/tests/028.phpt new file mode 100644 index 0000000000..a96518afcf --- /dev/null +++ b/ext/filter/tests/028.phpt @@ -0,0 +1,37 @@ +--TEST-- +filter_data() and FS_SPECIAL_CHARS +--GET-- + +--FILE-- +", FS_SPECIAL_CHARS)); +var_dump(filter_data("", FS_SPECIAL_CHARS)); + +var_dump(filter_data("?>", FS_SPECIAL_CHARS, FILTER_FLAG_ENCODE_LOW)); +var_dump(filter_data("", FS_SPECIAL_CHARS, FILTER_FLAG_ENCODE_LOW)); + +var_dump(filter_data("?>", FS_SPECIAL_CHARS, FILTER_FLAG_ENCODE_HIGH)); +var_dump(filter_data("", FS_SPECIAL_CHARS, FILTER_FLAG_ENCODE_HIGH)); + +var_dump(filter_data("кириллица", FS_SPECIAL_CHARS, FILTER_FLAG_ENCODE_HIGH)); +var_dump(filter_data("кириллица", FS_SPECIAL_CHARS, FILTER_FLAG_ENCODE_LOW)); + +echo "Done\n"; +?> +--EXPECT-- +string(55) "?><!@#$%^&*()}{~Qwertyuilfdsasdfgmnbvcxcvbn" +string(23) "<data&sons>" +string(0) "" +string(55) "?><!@#$%^&*()}{~Qwertyuilfdsasdfgmnbvcxcvbn" +string(23) "<data&sons>" +string(0) "" +string(55) "?><!@#$%^&*()}{~Qwertyuilfdsasdfgmnbvcxcvbn" +string(23) "<data&sons>" +string(0) "" +string(108) "кириллица" +string(18) "кириллица" +Done diff --git a/ext/filter/tests/029.phpt b/ext/filter/tests/029.phpt new file mode 100644 index 0000000000..b3371757c2 --- /dev/null +++ b/ext/filter/tests/029.phpt @@ -0,0 +1,108 @@ +--TEST-- +filter_data() and FC_CALLBACK +--GET-- + +--FILE-- +>?\"}{:", FC_CALLBACK, "test")); +var_dump(filter_data("", FC_CALLBACK, "test")); +var_dump(filter_data("qwe", FC_CALLBACK, "no such func")); +var_dump(filter_data("qwe", FC_CALLBACK, "")); +var_dump(filter_data("qwe", FC_CALLBACK)); + +/* Simple class method callback */ +class test_class { + static function test ($var) { + return strtolower($var); + } +} + +var_dump(filter_data("dAtA", FC_CALLBACK, array("test_class", "test"))); +var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FC_CALLBACK, array("test_class","test"))); +var_dump(filter_data("", FC_CALLBACK, array("test_class","test"))); + +/* empty function without return value */ +function test1($var) { +} + +var_dump(filter_data("data", FC_CALLBACK, "test1")); +var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FC_CALLBACK, "test1")); +var_dump(filter_data("", FC_CALLBACK, "test1")); + +/* attempting to change data by reference */ +function test2(&$var) { + $var = 1; +} + +var_dump(filter_data("data", FC_CALLBACK, "test2")); +var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FC_CALLBACK, "test2")); +var_dump(filter_data("", FC_CALLBACK, "test2")); + +/* unsetting data */ +function test3(&$var) { + unset($var); +} + +var_dump(filter_data("data", FC_CALLBACK, "test3")); +var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FC_CALLBACK, "test3")); +var_dump(filter_data("", FC_CALLBACK, "test3")); + +/* unset data and return value */ +function test4(&$var) { + unset($var); + return 1; +} + +var_dump(filter_data("data", FC_CALLBACK, "test4")); + +/* thrown exception in the callback */ +function test5(&$var) { + throw new Exception("test"); +} + +try { + var_dump(filter_data("data", FC_CALLBACK, "test5")); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +echo "Done\n"; +?> +--EXPECTF-- +string(4) "DATA" +string(46) "~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?"}{:" +string(0) "" +PHP Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d + +Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d +NULL +PHP Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d + +Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d +NULL +PHP Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d + +Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d +NULL +string(4) "data" +string(46) "~!@#$%^&*()_qwertyuiopasdfghjklzxcvbnm<>>?"}{:" +string(0) "" +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +int(1) +string(4) "test" +Done