From: Raghubansh Kumar Date: Tue, 9 Oct 2007 12:47:00 +0000 (+0000) Subject: New testcases for strip_tags() function X-Git-Tag: php-5.2.5RC1~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a078d14c9af8f3feeec270cda4c1a4e879bea73;p=php New testcases for strip_tags() function --- diff --git a/ext/standard/tests/strings/strip_tags_basic1.phpt b/ext/standard/tests/strings/strip_tags_basic1.phpt new file mode 100644 index 0000000000..f151b7791b --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_basic1.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test strip_tags() function : basic functionality - with default arguments +--INI-- +set short_open_tag = on +--FILE-- +hello", + 'hello', + "", + '', + "", + '', + "<% echo hello %>", + '<% echo hello %>', + "", + '', + "hello

world

", + 'hello

world

', + "", + '' +); + + +// Calling strip_tags() with default arguments +// loop through the $string_array to test strip_tags on various inputs +$iteration = 1; +foreach($string_array as $string) +{ + echo "-- Iteration $iteration --\n"; + var_dump( strip_tags($string) ); + $iteration++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : basic functionality *** +-- Iteration 1 -- +string(5) "hello" +-- Iteration 2 -- +string(5) "hello" +-- Iteration 3 -- +string(0) "" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(0) "" +-- Iteration 6 -- +string(0) "" +-- Iteration 7 -- +string(0) "" +-- Iteration 8 -- +string(0) "" +-- Iteration 9 -- +string(12) " echo hello " +-- Iteration 10 -- +string(12) " echo hello " +-- Iteration 11 -- +string(10) "helloworld" +-- Iteration 12 -- +string(10) "helloworld" +-- Iteration 13 -- +string(0) "" +-- Iteration 14 -- +string(0) "" +Done diff --git a/ext/standard/tests/strings/strip_tags_basic2.phpt b/ext/standard/tests/strings/strip_tags_basic2.phpt new file mode 100644 index 0000000000..0ca5f6df39 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_basic2.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test strip_tags() function : basic functionality - with all arguments +--INI-- +set short_open_tag = on +--FILE-- +

hello

worldOther text"; + +$allowed_tags_array=array( + "", + '', + "

", + '

', + "", + '', + "

+--EXPECTF-- +*** Testing strip_tags() : basic functionality *** +-- Iteration 1 -- +string(33) "helloworldOther text" +-- Iteration 2 -- +string(33) "helloworldOther text" +-- Iteration 3 -- +string(27) "

hello

worldOther text" +-- Iteration 4 -- +string(27) "

hello

worldOther text" +-- Iteration 5 -- +string(44) "helloworld
Other text" +-- Iteration 6 -- +string(44) "helloworldOther text" +-- Iteration 7 -- +string(20) "helloworldOther text" +-- Iteration 8 -- +string(20) "helloworldOther text" +-- Iteration 9 -- +string(64) "

hello

worldOther text" +Done diff --git a/ext/standard/tests/strings/strip_tags_error.phpt b/ext/standard/tests/strings/strip_tags_error.phpt new file mode 100644 index 0000000000..fcd3963fe2 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test strip_tags() function : error conditions +--INI-- +set short_open_tag = on +--FILE-- +hello"; +$allowable_tags = ""; +$extra_arg = 10; +var_dump( strip_tags($str, $allowable_tags, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : error conditions *** + +-- Testing strip_tags() function with Zero arguments -- + +Warning: Wrong parameter count for strip_tags() in %s on line %d +NULL + +-- Testing strip_tags() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for strip_tags() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/strings/strip_tags_variation1.phpt b/ext/standard/tests/strings/strip_tags_variation1.phpt new file mode 100644 index 0000000000..b312fb24e1 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation1.phpt @@ -0,0 +1,157 @@ +--TEST-- +Test strip_tags() function : usage variations - unexpected values for 'str' argument +--INI-- +set short_open_tag = on +--FILE-- + 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable + $fp + +); + +// loop through each element of the array for allowable_tags +$iterator = 1; +foreach($values as $value) { + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(1) "0" +-- Iteration 2 -- +string(1) "1" +-- Iteration 3 -- +string(5) "12345" +-- Iteration 4 -- +string(5) "-2345" +-- Iteration 5 -- +string(4) "10.5" +-- Iteration 6 -- +string(5) "-10.5" +-- Iteration 7 -- +string(12) "105000000000" +-- Iteration 8 -- +string(7) "1.06E-9" +-- Iteration 9 -- +string(3) "0.5" +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 15 -- +string(0) "" +-- Iteration 16 -- +string(0) "" +-- Iteration 17 -- +string(1) "1" +-- Iteration 18 -- +string(0) "" +-- Iteration 19 -- +string(1) "1" +-- Iteration 20 -- +string(0) "" +-- Iteration 21 -- +string(0) "" +-- Iteration 22 -- +string(0) "" +-- Iteration 23 -- +string(14) "Class A object" +-- Iteration 24 -- +string(0) "" +-- Iteration 25 -- +string(0) "" +-- Iteration 26 -- +string(%d) "Resource id #%d" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation10.phpt b/ext/standard/tests/strings/strip_tags_variation10.phpt new file mode 100644 index 0000000000..a9c3f64668 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation10.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test strip_tags() function : usage variations - single quoted strings +--INI-- +set short_open_tag = on +--FILE-- + \$ -> This represents the dollar sign', + '\t\r\v The quick brown fo\fx jumped over the lazy dog

', + 'This is a hyper text tag', + 'hello world\\t?>', + '

This is a paragraph

', + 'This is \ta text in bold letters\r\s\malong with slashes\n' +); + +$quotes = "

+--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(51) " \$ -> This represents the dollar sign" +-- Iteration 2 -- +string(63) "\t\r\v The quick brown fo\fx jumped over the lazy dog

" +-- Iteration 3 -- +string(31) "
This is a hyper text tag" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(26) "

This is a paragraph

" +-- Iteration 6 -- +string(65) "This is \ta text in bold letters\r\s\malong with slashes\n" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation2.phpt b/ext/standard/tests/strings/strip_tags_variation2.phpt new file mode 100644 index 0000000000..5e0df80292 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation2.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test strip_tags() function : usage variations - unexpected values for 'allowable_tags' +--INI-- +set short_open_tag = on +--FILE-- +hello

world

"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA{ + public function __toString(){ + return "Class A Object"; + } +} + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable + $fp +); + +// loop through each element of the array for allowable_tags +$iterator = 1; +foreach($values as $value) { + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($string, $value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(10) "helloworld" +-- Iteration 2 -- +string(10) "helloworld" +-- Iteration 3 -- +string(10) "helloworld" +-- Iteration 4 -- +string(10) "helloworld" +-- Iteration 5 -- +string(10) "helloworld" +-- Iteration 6 -- +string(10) "helloworld" +-- Iteration 7 -- +string(10) "helloworld" +-- Iteration 8 -- +string(10) "helloworld" +-- Iteration 9 -- +string(10) "helloworld" +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d +string(10) "helloworld" +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d +string(10) "helloworld" +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d +string(10) "helloworld" +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d +string(10) "helloworld" +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d +string(10) "helloworld" +-- Iteration 15 -- +string(10) "helloworld" +-- Iteration 16 -- +string(10) "helloworld" +-- Iteration 17 -- +string(10) "helloworld" +-- Iteration 18 -- +string(10) "helloworld" +-- Iteration 19 -- +string(10) "helloworld" +-- Iteration 20 -- +string(10) "helloworld" +-- Iteration 21 -- +string(10) "helloworld" +-- Iteration 22 -- +string(10) "helloworld" +-- Iteration 23 -- +string(10) "helloworld" +-- Iteration 24 -- +string(10) "helloworld" +-- Iteration 25 -- +string(10) "helloworld" +-- Iteration 26 -- +string(10) "helloworld" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation3.phpt b/ext/standard/tests/strings/strip_tags_variation3.phpt new file mode 100644 index 0000000000..1e1ed9efb7 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation3.phpt @@ -0,0 +1,167 @@ +--TEST-- +Test strip_tags() function : usage variations - unexpected values for both 'str' and 'allowable_tags' +--INI-- +set short_open_tag = on +--FILE-- + 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable + $fp + +); + +// loop through each element of the array for allowable_tags +$iterator = 1; +foreach($values as $value) { + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($value, $value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(1) "0" +-- Iteration 2 -- +string(1) "1" +-- Iteration 3 -- +string(5) "12345" +-- Iteration 4 -- +string(5) "-2345" +-- Iteration 5 -- +string(4) "10.5" +-- Iteration 6 -- +string(5) "-10.5" +-- Iteration 7 -- +string(12) "105000000000" +-- Iteration 8 -- +string(7) "1.06E-9" +-- Iteration 9 -- +string(3) "0.5" +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 15 -- +string(0) "" +-- Iteration 16 -- +string(0) "" +-- Iteration 17 -- +string(1) "1" +-- Iteration 18 -- +string(0) "" +-- Iteration 19 -- +string(1) "1" +-- Iteration 20 -- +string(0) "" +-- Iteration 21 -- +string(0) "" +-- Iteration 22 -- +string(0) "" +-- Iteration 23 -- +string(14) "Class A object" +-- Iteration 24 -- +string(0) "" +-- Iteration 25 -- +string(0) "" +-- Iteration 26 -- +string(%d) "Resource id #%d" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation4.phpt b/ext/standard/tests/strings/strip_tags_variation4.phpt new file mode 100644 index 0000000000..b6fd404227 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation4.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test strip_tags() function : usage variations - invalid values for 'str' and valid 'allowable_tags' +--INI-- +set short_open_tag = on +--FILE-- +hello \t\tworld... strip_tags_test", + 'hello \t\tworld... strip_tags_test', + "<%?php hello\t world?%>", + '<%?php hello\t world?%>', + "<>hello<>", + '<>hello<>', + "HtMl text", + 'HtMl text', + "I am not a valid html text", + 'I am not a valid html text', + "I am a quoted (\") string with special chars like \$,\!,\@,\%,\&", + 'I am a quoted (\") string with special chars like \$,\!,\@,\%,\&', +); + +//valid html and php tags +$quotes = "

"; + +//loop through the various elements of strings array to test strip_tags() functionality +$iterator = 1; +foreach($strings as $string_value) +{ + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($string_value, $quotes) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(32) "hello world... strip_tags_test" +-- Iteration 2 -- +string(34) "hello \t\tworld... strip_tags_test" +-- Iteration 3 -- +string(0) "" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(18) "hello" +-- Iteration 6 -- +string(18) "hello" +-- Iteration 7 -- +string(9) "HtMl text" +-- Iteration 8 -- +string(9) "HtMl text" +-- Iteration 9 -- +string(26) "I am not a valid html text" +-- Iteration 10 -- +string(26) "I am not a valid html text" +-- Iteration 11 -- +string(62) "I am a quoted (") string with special chars like $,\!,\@,\%,\&" +-- Iteration 12 -- +string(64) "I am a quoted (\") string with special chars like \$,\!,\@,\%,\&" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation5.phpt b/ext/standard/tests/strings/strip_tags_variation5.phpt new file mode 100644 index 0000000000..ae7c4f748f --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation5.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test strip_tags() function : usage variations - heredoc strings +--INI-- +set short_open_tag = on +--FILE-- +hello world +

13 < 25

+ +This is a double quoted string +EOT; + +// here doc with diferent whitespaces +$diff_whitespaces = <<hello\r world\t +1111\t\t != 2222\v\v + +EOT; + +// here doc with numeric values +$numeric_string = <<11 < 12. 123 >22 +

string

1111\t 0000\t = 0000\n +EOT; + +// heredoc with quote chars & slash +$quote_char_string = <<This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes +EOT; + +$res_heredoc_strings = array( + //heredoc strings + $null_string, + $blank_line, + $multiline_string, + $diff_whitespaces, + $numeric_string, + $quote_char_string +); + +// initialize the second argument +$quotes = "
+--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(0) "" +-- Iteration 2 -- +string(0) "" +-- Iteration 3 -- +string(67) "hello world +13 < 25 + +This is a double quoted string" +-- Iteration 4 -- +string(44) "hello + world +1111 != 2222 +" +-- Iteration 5 -- +string(56) "11 < 12. 123 >22 +string 1111 0000 = 0000 +" +-- Iteration 6 -- +string(150) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes " +Done \ No newline at end of file diff --git a/ext/standard/tests/strings/strip_tags_variation6.phpt b/ext/standard/tests/strings/strip_tags_variation6.phpt new file mode 100644 index 0000000000..ff21906365 --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation6.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test strip_tags() function : usage variations - binary safe checking +--INI-- +set short_open_tag = on +--FILE-- + I am html string ".chr(0)."", + " I am html string\0 ", + b"I am html string", + "I am html string".decbin(65)."" +); + +//loop through the strings array to check if strip_tags() is binary safe +$iterator = 1; +foreach($strings as $value) +{ + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($value) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(18) " I am html string " +-- Iteration 2 -- +string(18) " I am html string " +-- Iteration 3 -- +string(16) "I am html string" +-- Iteration 4 -- +string(23) "I am html string1000001" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation7.phpt b/ext/standard/tests/strings/strip_tags_variation7.phpt new file mode 100644 index 0000000000..1c76940b8f --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation7.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test strip_tags() function : usage variations - invalid values for 'str' and 'allowable_tags' +--INI-- +set short_open_tag = on +--FILE-- +hello \t\tworld... strip_tags_test", + 'hello \t\tworld... strip_tags_test', + "<%?php hello\t world?%>", + '<%?php hello\t world?%>', + "<>hello<>", + '<>hello<>', + "HtMl text", + 'HtMl text', + "I am not a valid html text", + 'I am not a valid html text', + "I am a quoted (\") string with special chars like \$,\!,\@,\%,\&", + 'I am a quoted (\") string with special chars like \$,\!,\@,\%,\&', +); + +$quotes = "<%?<>"; + +//loop through the various elements of strings array to test strip_tags() functionality +$iterator = 1; +foreach($strings as $string_value) +{ + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($string_value, $quotes) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(43) "hello world... strip_tags_test" +-- Iteration 2 -- +string(45) "hello \t\tworld... strip_tags_test" +-- Iteration 3 -- +string(0) "" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(18) "hello" +-- Iteration 6 -- +string(18) "hello" +-- Iteration 7 -- +string(9) "HtMl text" +-- Iteration 8 -- +string(9) "HtMl text" +-- Iteration 9 -- +string(37) "I am not a valid html text" +-- Iteration 10 -- +string(37) "I am not a valid html text" +-- Iteration 11 -- +string(73) "I am a quoted (") string with special chars like $,\!,\@,\%,\&" +-- Iteration 12 -- +string(75) "I am a quoted (\") string with special chars like \$,\!,\@,\%,\&" +Done diff --git a/ext/standard/tests/strings/strip_tags_variation8.phpt b/ext/standard/tests/strings/strip_tags_variation8.phpt new file mode 100644 index 0000000000..a8b45c1a2a --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation8.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test strip_tags() function : usage variations - valid value for 'str' and invalid values for 'allowable_tags' +--INI-- +set short_open_tag = on +--FILE-- +hello \tworld...

strip_tags_test\v\f

"; + +$quotes = array ( + "", + '', + "", + '', + "<%?php", + '<%?php', + "<>", + '<>' +); + +//loop through the various elements of strings array to test strip_tags() functionality +$iterator = 1; +foreach($quotes as $string_value) +{ + echo "-- Iteration $iterator --\n"; + var_dump( strip_tags($strings, $string_value) ); + $iterator++; +} + +echo "Done"; +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(33) "hello world... strip_tags_test " +-- Iteration 2 -- +string(33) "hello world... strip_tags_test " +-- Iteration 3 -- +string(33) "hello world... strip_tags_test " +-- Iteration 4 -- +string(33) "hello world... strip_tags_test " +-- Iteration 5 -- +string(33) "hello world... strip_tags_test " +-- Iteration 6 -- +string(33) "hello world... strip_tags_test " +-- Iteration 7 -- +string(46) "hello world... strip_tags_test " +-- Iteration 8 -- +string(46) "hello world... strip_tags_test " +Done diff --git a/ext/standard/tests/strings/strip_tags_variation9.phpt b/ext/standard/tests/strings/strip_tags_variation9.phpt new file mode 100644 index 0000000000..b133fb356b --- /dev/null +++ b/ext/standard/tests/strings/strip_tags_variation9.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test strip_tags() function : usage variations - double quoted strings +--INI-- +set short_open_tag = on +--FILE-- + \$ -> This represents the dollar sign", + "\t\r\v The quick brown fo\fx jumped over the lazy dog

", + "This is a hyper text tag", + "hello world\\t?>", + "

This is a paragraph

", + "This is \ta text in bold letters\r\s\malong with slashes\n" +); + +$quotes = "

$ -> This represents the dollar sign" +-- Iteration 2 -- +string(59) " + The quick brown fo x jumped over the lazy dog

" +-- Iteration 3 -- +string(31) "
This is a hyper text tag" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(26) "

This is a paragraph

" +-- Iteration 6 -- +string(62) "This is a text in bold letters +\s\malong with slashes +" +Done