--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : basic functionality
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+echo "*** Testing htmlspecialchars_decode() : basic functionality ***\n";
+
+
+// Initialise arguments
+//value initialized = Roy's height > 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
--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : error conditions
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+echo "*** Testing htmlspecialchars_decode() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing htmlspecialchars_decode() function with Zero arguments --\n";
+var_dump( htmlspecialchars_decode() );
+
+//Test htmlspecialchars_decode with one more than the expected number of arguments
+echo "\n-- Testing htmlspecialchars_decode() function with more than expected no. of arguments --\n";
+$string = "<html>hello & > < " ' world</html>";
+$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
--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : usage variations - unexpected values for 'string' argument
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+/*
+ * testing htmlspecialchars_decode() with unexpected input values for $string argument
+*/
+
+echo "*** Testing htmlspecialchars_decode() : usage variations ***\n";
+
+//get a class
+class classA
+{
+ function __toString() {
+ return "ClassAObject";
+ }
+}
+
+//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(
+
+ // 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
+ $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
--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : usage variations - unexpected values for 'quote_style' argument
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+/*
+ * testing htmlspecialchars_decode() by giving unexpected input values for $quote_style argument
+*/
+
+echo "*** Testing htmlspecialchars_decode() : usage variations ***\n";
+
+// Initialise function arguments
+// value initialized = Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "
+$string = "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>";
+
+//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) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 2 --
+string(104) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 3 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 4 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 5 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- 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) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 12 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 13 --
+string(104) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 14 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 15 --
+string(104) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 16 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- 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) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 23 --
+string(114) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 24 --
+
+Warning: htmlspecialchars_decode() expects parameter 2 to be long, resource given in %s on line %d
+NULL
+Done
--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : usage variations - heredoc strings for 'string' argument
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+/*
+ * testing htmlspecialchars_decode() with various heredoc strings as argument for $string
+*/
+
+echo "*** Testing htmlspecialchars_decode() : usage variations ***\n";
+
+// empty heredoc string
+$empty_string = <<<EOT
+EOT;
+
+// Heredoc string with blank line
+$blank_line = <<<EOT
+
+EOT;
+
+// heredoc with multiline string
+$multiline_string = <<<EOT
+<html>Roy's height > Sam's height
+13 < 25
+1111 & 0000 = 0000
+"This is a double quoted string"
+EOT;
+
+// heredoc with diferent whitespaces
+$diff_whitespaces = <<<EOT
+<html>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 = <<<EOT
+<html>11 < 12. 123 string 4567
+"string" 1111\t & 0000\t = 0000\n;
+EOT;
+
+// heredoc with quote chars & slash
+$quote_char_string = <<<EOT
+<html>< This's a string with quotes:
+"strings in double quote" &
+'strings in single quote' "
+this\line is 'single quoted' /with\slashes </html>
+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) "<html>Roy's height > Sam's height
+13 < 25
+1111 & 0000 = 0000
+"This is a double quoted string""
+-- Iteration 4 --
+string(130) "<html>Roy's height
+ > Sam 's height
+1111 & 0000\v\v = \f0000
+" heredoc
+double quoted string. with\vdifferent\fwhite\vspaces""
+-- Iteration 5 --
+string(62) "<html>11 < 12. 123 string 4567
+"string" 1111 & 0000 = 0000
+;"
+-- Iteration 6 --
+string(153) "<html>< This's a string with quotes:
+"strings in double quote" &
+'strings in single quote' "
+this\line is 'single quoted' /with\slashes </html>"
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : usage variations - single quoted strings for 'string' argument
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+/*
+ * Testing htmlspecialchars_decode() with various single quoted strings as argument for $string
+*/
+
+echo "*** Testing htmlspecialchars_decode() : usage variations ***\n";
+
+//single quoted strings
+$values = array (
+ 'Roy's height > Sam's \$height... 1111 ≈ 0000 = 0000... " double quote string "',
+ 'Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string "',
+ '\nRoy's height >\t; Sam's\v height\f',
+ '\r\tRoy's height >\r; Sam\t's height',
+ '\n 1\t3 &\tgt; 11 but 11 &\tlt; 12',
+);
+
+// loop through each element of the values array to check htmlspecialchars_decode() function with all possible arguments
+$iterator = 1;
+foreach($values as $value) {
+ echo "-- Iteration $iterator --\n";
+ var_dump( htmlspecialchars_decode($value) );
+ var_dump( htmlspecialchars_decode($value, ENT_COMPAT) );
+ var_dump( htmlspecialchars_decode($value, ENT_NOQUOTES) );
+ var_dump( htmlspecialchars_decode($value, ENT_QUOTES) );
+ $iterator++;
+}
+
+echo "Done";
+?>
+--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
--- /dev/null
+--TEST--
+Test htmlspecialchars_decode() function : usage variations - double quoted strings for 'string' argument
+--FILE--
+<?php
+/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style])
+ * Description: Convert special HTML entities back to characters
+ * Source code: ext/standard/html.c
+*/
+
+/*
+ * testing htmlspecialchars_decode() for various double quoted strings as argument for $string
+*/
+echo "*** Testing htmlspecialchars_decode() : usage variations ***\n";
+
+//double quoted strings
+$strings = array (
+ "Roy's height > Sam's \$height... 1111 ≈ 0000 = 0000... " double quote string "",
+ "Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string "",
+ "\nRoy's height >\t; Sam's\v height\f",
+ "\r\tRoy's height >\r; Sam\t's height",
+ "\n 1\t3 &\tgt; 11 but 11 &\tlt; 12",
+);
+
+// loop through each element of the array to check htmlspecialchars_decode() function with all possible arguments
+$iterator = 1;
+foreach($strings as $value) {
+ echo "-- Iteration $iterator --\n";
+ var_dump( htmlspecialchars_decode($value) );
+ var_dump( htmlspecialchars_decode($value, ENT_COMPAT) );
+ var_dump( htmlspecialchars_decode($value, ENT_NOQUOTES) );
+ var_dump( htmlspecialchars_decode($value, ENT_QUOTES) );
+ $iterator++;
+}
+
+echo "Done";
+?>
+--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\f\v string ""
+string(82) "Roy's height > Sam's height... 13 < 15...
+
+ " double quote\f\v string ""
+string(92) "Roy's height > Sam's height... 13 < 15...
+
+ " double quote\f\v string ""
+string(72) "Roy's height > Sam's height... 13 < 15...
+
+ " double quote\f\v string ""
+-- Iteration 3 --
+string(44) "
+Roy's height > ; Sam's\v height\f"
+string(44) "
+Roy's height > ; Sam's\v height\f"
+string(44) "
+Roy's height > ; Sam's\v height\f"
+string(34) "
+Roy's height > ; Sam's\v height\f"
+-- 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