From: Raghubansh Kumar Date: Sat, 29 Sep 2007 16:51:42 +0000 (+0000) Subject: New testcases for htmlspecialchars_decode() function X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND_IN_5_3~55 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3253c3b6dda18df165f3ebf61085a6347d09c163;p=php New testcases for htmlspecialchars_decode() function --- diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_basic.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_basic.phpt new file mode 100644 index 0000000000..dc027398d5 --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_basic.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test htmlspecialchars_decode() function : basic functionality +--FILE-- + Sam's height. 13 < 25. 1111 & 0000 = 0000. "double quoted string" +$single_quote_string = "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string ""; +$double_quote_string = "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string ""; + +// Calling htmlspecialchars_decode() with default arguments +var_dump( htmlspecialchars_decode($single_quote_string) ); +var_dump( htmlspecialchars_decode($double_quote_string) ); + +// Calling htmlspecialchars_decode() with optional 'quote_style' argument +var_dump( htmlspecialchars_decode($single_quote_string, ENT_COMPAT) ); +var_dump( htmlspecialchars_decode($double_quote_string, ENT_COMPAT) ); +var_dump( htmlspecialchars_decode($single_quote_string, ENT_NOQUOTES) ); +var_dump( htmlspecialchars_decode($double_quote_string, ENT_NOQUOTES) ); +var_dump( htmlspecialchars_decode($single_quote_string, ENT_QUOTES) ); +var_dump( htmlspecialchars_decode($double_quote_string, ENT_QUOTES) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing htmlspecialchars_decode() : basic functionality *** +string(92) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(92) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(92) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(92) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(102) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(102) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(82) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +string(82) "Roy's height > Sam's height. 13 < 25. 1111 & 0000 = 0000. " double quoted string "" +Done diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_error.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_error.phpt new file mode 100644 index 0000000000..f4201d2842 --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_error.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test htmlspecialchars_decode() function : error conditions +--FILE-- +hello & > < " ' world"; +$quote_style = ENT_COMPAT; +$extra_arg = 10; +var_dump( htmlspecialchars_decode($string, $quote_style, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing htmlspecialchars_decode() : error conditions *** + +-- Testing htmlspecialchars_decode() function with Zero arguments -- + +Warning: htmlspecialchars_decode() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing htmlspecialchars_decode() function with more than expected no. of arguments -- + +Warning: htmlspecialchars_decode() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt new file mode 100644 index 0000000000..5f0582d51e --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test htmlspecialchars_decode() function : usage variations - unexpected values for 'string' argument +--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 + $file_handle +); + +// loop through each element of the array for string +$iterator = 1; +foreach($values as $value) { + echo "-- Iterator $iterator --\n"; + var_dump( htmlspecialchars_decode($value) ); + $iterator++; +}; + +// close the file resource used +fclose($file_handle); + +echo "Done"; +?> +--EXPECTF-- +*** Testing htmlspecialchars_decode() : usage variations *** +-- Iterator 1 -- +string(1) "0" +-- Iterator 2 -- +string(1) "1" +-- Iterator 3 -- +string(5) "12345" +-- Iterator 4 -- +string(5) "-2345" +-- Iterator 5 -- +string(4) "10.5" +-- Iterator 6 -- +string(5) "-10.5" +-- Iterator 7 -- +string(12) "105000000000" +-- Iterator 8 -- +string(7) "1.06E-9" +-- Iterator 9 -- +string(3) "0.5" +-- Iterator 10 -- + +Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iterator 11 -- + +Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iterator 12 -- + +Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iterator 13 -- + +Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iterator 14 -- + +Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iterator 15 -- +string(0) "" +-- Iterator 16 -- +string(0) "" +-- Iterator 17 -- +string(1) "1" +-- Iterator 18 -- +string(0) "" +-- Iterator 19 -- +string(1) "1" +-- Iterator 20 -- +string(0) "" +-- Iterator 21 -- +string(0) "" +-- Iterator 22 -- +string(0) "" +-- Iterator 23 -- +string(12) "ClassAObject" +-- Iterator 24 -- +string(0) "" +-- Iterator 25 -- +string(0) "" +-- Iterator 26 -- + +Warning: htmlspecialchars_decode() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt new file mode 100644 index 0000000000..2ef7dd1bb8 --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test htmlspecialchars_decode() function : usage variations - unexpected values for 'quote_style' argument +--FILE-- + Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string " +$string = "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string ""; + +//get a class +class classA { + function __toString() { + return "Class A Object"; + } +} + +//get a resource variable +$file_handle = fopen(__FILE__, "r"); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +//array of values to iterate over +$values = array( + + // 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 + "", + '', + + // string data + "string", + 'string', + + // object data + new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + //resource + $file_handle +); + +// loop through each element of the array for quote_style +$iterator = 1; +foreach($values as $value) { + echo "\n-- Iteration $iterator --\n"; + var_dump( htmlspecialchars_decode($string, $value) ); + $iterator++; +} + +// close the file resource used +fclose($file_handle); + +echo "Done"; +?> +--EXPECTF-- +*** Testing htmlspecialchars_decode() : usage variations *** + +-- Iteration 1 -- +string(104) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 2 -- +string(104) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 3 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 4 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 5 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 6 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 11 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 12 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 13 -- +string(104) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 14 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 15 -- +string(104) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 16 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 17 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 22 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 23 -- +string(114) "Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "" + +-- Iteration 24 -- + +Warning: htmlspecialchars_decode() expects parameter 2 to be long, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation3.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation3.phpt new file mode 100644 index 0000000000..83cb1c7ca8 --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_variation3.phpt @@ -0,0 +1,100 @@ +--TEST-- +Test htmlspecialchars_decode() function : usage variations - heredoc strings for 'string' argument +--FILE-- +Roy's height > Sam's height +13 < 25 +1111 & 0000 = 0000 +"This is a double quoted string" +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<Roy's height\r > Sam\t's height +1111\t\t & 0000\v\v = \f0000 +" heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces" +EOT; + +// heredoc with numeric values +$numeric_string = <<11 < 12. 123 string 4567 +"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 + $empty_string, + $blank_line, + $multiline_string, + $diff_whitespaces, + $numeric_string, + $quote_char_string +); + +// loop through $res_heredoc_strings array and check the working on htmlspecialchars_decode() +$count = 1; +for($index =0; $index < count($res_heredoc_strings); $index ++) { + echo "-- Iteration $count --\n"; + var_dump( htmlspecialchars_decode($res_heredoc_strings[$index]) ); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing htmlspecialchars_decode() : usage variations *** +-- Iteration 1 -- +string(0) "" +-- Iteration 2 -- +string(0) "" +-- Iteration 3 -- +string(103) "Roy's height > Sam's height +13 < 25 +1111 & 0000 = 0000 +"This is a double quoted string"" +-- Iteration 4 -- +string(130) "Roy's height + > Sam 's height +1111 & 0000 = 0000 +" heredoc +double quoted string. with different white spaces"" +-- Iteration 5 -- +string(62) "11 < 12. 123 string 4567 +"string" 1111 & 0000 = 0000 +;" +-- Iteration 6 -- +string(153) "< 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/htmlspecialchars_decode_variation4.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation4.phpt new file mode 100644 index 0000000000..e51e904fea --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_variation4.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test htmlspecialchars_decode() function : usage variations - single quoted strings for 'string' argument +--FILE-- + +--EXPECTF-- +*** Testing htmlspecialchars_decode() : usage variations *** +-- Iteration 1 -- +string(90) "Roy's height > Sam's \$height... 1111 ≈ 0000 = 0000... " double quote string "" +string(90) "Roy's height > Sam's \$height... 1111 ≈ 0000 = 0000... " double quote string "" +string(100) "Roy's height > Sam's \$height... 1111 ≈ 0000 = 0000... " double quote string "" +string(85) "Roy's height > Sam's \$height... 1111 ≈ 0000 = 0000... " double quote string "" +-- Iteration 2 -- +string(88) "Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string "" +string(88) "Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string "" +string(98) "Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string "" +string(78) "Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string "" +-- Iteration 3 -- +string(48) "\nRoy's height >\t; Sam's\v height\f" +string(48) "\nRoy's height >\t; Sam's\v height\f" +string(48) "\nRoy's height >\t; Sam's\v height\f" +string(38) "\nRoy's height >\t; Sam's\v height\f" +-- Iteration 4 -- +string(48) "\r\tRoy's height >\r; Sam\t's height" +string(48) "\r\tRoy's height >\r; Sam\t's height" +string(48) "\r\tRoy's height >\r; Sam\t's height" +string(38) "\r\tRoy's height >\r; Sam\t's height" +-- Iteration 5 -- +string(34) "\n 1\t3 &\tgt; 11 but 11 &\tlt; 12" +string(34) "\n 1\t3 &\tgt; 11 but 11 &\tlt; 12" +string(34) "\n 1\t3 &\tgt; 11 but 11 &\tlt; 12" +string(34) "\n 1\t3 &\tgt; 11 but 11 &\tlt; 12" +Done diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation5.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation5.phpt new file mode 100644 index 0000000000..c2f0056d01 --- /dev/null +++ b/ext/standard/tests/strings/htmlspecialchars_decode_variation5.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test htmlspecialchars_decode() function : usage variations - double quoted strings for 'string' argument +--FILE-- + +--EXPECTF-- +*** Testing htmlspecialchars_decode() : usage variations *** +-- Iteration 1 -- +string(89) "Roy's height > Sam's $height... 1111 ≈ 0000 = 0000... " double quote string "" +string(89) "Roy's height > Sam's $height... 1111 ≈ 0000 = 0000... " double quote string "" +string(99) "Roy's height > Sam's $height... 1111 ≈ 0000 = 0000... " double quote string "" +string(84) "Roy's height > Sam's $height... 1111 ≈ 0000 = 0000... " double quote string "" +-- Iteration 2 -- +string(82) "Roy's height > Sam's height... 13 < 15... + + " double quote string "" +string(82) "Roy's height > Sam's height... 13 < 15... + + " double quote string "" +string(92) "Roy's height > Sam's height... 13 < 15... + + " double quote string "" +string(72) "Roy's height > Sam's height... 13 < 15... + + " double quote string "" +-- Iteration 3 -- +string(44) " +Roy's height > ; Sam's height " +string(44) " +Roy's height > ; Sam's height " +string(44) " +Roy's height > ; Sam's height " +string(34) " +Roy's height > ; Sam's height " +-- Iteration 4 -- +string(44) " + Roy's height > +; Sam 's height" +string(44) " + Roy's height > +; Sam 's height" +string(44) " + Roy's height > +; Sam 's height" +string(34) " + Roy's height > +; Sam 's height" +-- Iteration 5 -- +string(30) " + 1 3 & gt; 11 but 11 & lt; 12" +string(30) " + 1 3 & gt; 11 but 11 & lt; 12" +string(30) " + 1 3 & gt; 11 but 11 & lt; 12" +string(30) " + 1 3 & gt; 11 but 11 & lt; 12" +Done \ No newline at end of file diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt new file mode 100644 index 0000000000..d1636eb156 Binary files /dev/null and b/ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt differ