]> granicus.if.org Git - php/commitdiff
New testcases for htmlspecialchars_decode() function
authorRaghubansh Kumar <kraghuba@php.net>
Sat, 29 Sep 2007 16:51:42 +0000 (16:51 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Sat, 29 Sep 2007 16:51:42 +0000 (16:51 +0000)
ext/standard/tests/strings/htmlspecialchars_decode_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_error.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation3.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation4.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation5.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_basic.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_basic.phpt
new file mode 100644 (file)
index 0000000..dc02739
--- /dev/null
@@ -0,0 +1,42 @@
+--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&#039;s height &gt; Sam&#039;s height. 13 &lt; 25. 1111 &amp; 0000 = 0000. &quot; double quoted string &quot;";
+$double_quote_string = "Roy&#039;s height &gt; Sam&#039;s height. 13 &lt; 25. 1111 &amp; 0000 = 0000. &quot; double quoted string &quot;";
+
+// 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&#039;s height > Sam&#039;s height. 13 < 25. 1111 & 0000 = 0000. " double quoted string ""
+string(92) "Roy&#039;s height > Sam&#039;s height. 13 < 25. 1111 & 0000 = 0000. " double quoted string ""
+string(92) "Roy&#039;s height > Sam&#039;s height. 13 < 25. 1111 & 0000 = 0000. " double quoted string ""
+string(92) "Roy&#039;s height > Sam&#039;s height. 13 < 25. 1111 & 0000 = 0000. " double quoted string ""
+string(102) "Roy&#039;s height > Sam&#039;s height. 13 < 25. 1111 & 0000 = 0000. &quot; double quoted string &quot;"
+string(102) "Roy&#039;s height > Sam&#039;s height. 13 < 25. 1111 & 0000 = 0000. &quot; double quoted string &quot;"
+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 (file)
index 0000000..f4201d2
--- /dev/null
@@ -0,0 +1,37 @@
+--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 &amp; &gt; &lt; &quot; &#039; 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
diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt
new file mode 100644 (file)
index 0000000..5f0582d
--- /dev/null
@@ -0,0 +1,160 @@
+--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
diff --git a/ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt b/ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt
new file mode 100644 (file)
index 0000000..2ef7dd1
--- /dev/null
@@ -0,0 +1,191 @@
+--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&#039;s height &gt; Sam&#039;s height. 13 &lt; 15. 1111 &amp; 0000 = 0000. &quot; double quote string &quot;</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&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 2 --
+string(104) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. " double quote string "</html>"
+
+-- Iteration 3 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 4 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 5 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</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&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 12 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 13 --
+string(104) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 14 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 15 --
+string(104) "<html>Roy's height > Sam's height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 16 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</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&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- Iteration 23 --
+string(114) "<html>Roy&#039;s height > Sam&#039;s height. 13 < 15. 1111 & 0000 = 0000. &quot; double quote string &quot;</html>"
+
+-- 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 (file)
index 0000000..83cb1c7
--- /dev/null
@@ -0,0 +1,100 @@
+--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&#039;s height &gt; Sam&#039;s height
+13 &lt; 25
+1111 &amp; 0000 = 0000
+&quot;This is a double quoted string&quot;
+EOT;
+
+// heredoc with diferent whitespaces
+$diff_whitespaces = <<<EOT
+<html>Roy&#039;s height\r &gt; Sam\t&#039;s height
+1111\t\t &amp; 0000\v\v = \f0000
+&quot; heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces&quot;
+EOT;
+
+// heredoc with numeric values
+$numeric_string = <<<EOT
+<html>11 &lt; 12. 123 string 4567
+&quot;string&quot; 1111\t &amp; 0000\t = 0000\n;
+EOT;
+
+// heredoc with quote chars & slash
+$quote_char_string = <<<EOT
+<html>&lt; This's a string with quotes:
+"strings in double quote" &amp;
+'strings in single quote' &quot;
+this\line is &#039;single quoted&#039; /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&#039;s height > Sam&#039;s height
+13 < 25
+1111 & 0000 = 0000
+"This is a double quoted string""
+-- Iteration 4 --
+string(130) "<html>Roy&#039;s height
+ > Sam &#039;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 &#039;single quoted&#039; /with\slashes </html>"
+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 (file)
index 0000000..e51e904
--- /dev/null
@@ -0,0 +1,65 @@
+--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&#039s height &gt; Sam&#039;s \$height... 1111 &ap; 0000 = 0000... &quot; double quote string &quot;',
+  'Roy&#039;s height &gt; Sam&#039;s height... \t\t 13 &lt; 15...\n\r &quot; double quote\f\v string &quot;',
+  '\nRoy&#039;s height &gt\t; Sam&#039;s\v height\f',
+  '\r\tRoy&#039;s height &gt\r; Sam\t&#039;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&#039s height > Sam&#039;s \$height... 1111 &ap; 0000 = 0000... " double quote string ""
+string(90) "Roy&#039s height > Sam&#039;s \$height... 1111 &ap; 0000 = 0000... " double quote string ""
+string(100) "Roy&#039s height > Sam&#039;s \$height... 1111 &ap; 0000 = 0000... &quot; double quote string &quot;"
+string(85) "Roy&#039s height > Sam's \$height... 1111 &ap; 0000 = 0000... " double quote string ""
+-- Iteration 2 --
+string(88) "Roy&#039;s height > Sam&#039;s height... \t\t 13 < 15...\n\r " double quote\f\v string ""
+string(88) "Roy&#039;s height > Sam&#039;s height... \t\t 13 < 15...\n\r " double quote\f\v string ""
+string(98) "Roy&#039;s height > Sam&#039;s height... \t\t 13 < 15...\n\r &quot; double quote\f\v string &quot;"
+string(78) "Roy's height > Sam's height... \t\t 13 < 15...\n\r " double quote\f\v string ""
+-- Iteration 3 --
+string(48) "\nRoy&#039;s height &gt\t; Sam&#039;s\v height\f"
+string(48) "\nRoy&#039;s height &gt\t; Sam&#039;s\v height\f"
+string(48) "\nRoy&#039;s height &gt\t; Sam&#039;s\v height\f"
+string(38) "\nRoy's height &gt\t; Sam's\v height\f"
+-- Iteration 4 --
+string(48) "\r\tRoy&#039;s height &gt\r; Sam\t&#039;s height"
+string(48) "\r\tRoy&#039;s height &gt\r; Sam\t&#039;s height"
+string(48) "\r\tRoy&#039;s height &gt\r; Sam\t&#039;s height"
+string(38) "\r\tRoy's height &gt\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 (file)
index 0000000..c2f0056
--- /dev/null
@@ -0,0 +1,88 @@
+--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&#039s height &gt; Sam&#039;s \$height... 1111 &ap; 0000 = 0000... &quot; double quote string &quot;",
+  "Roy&#039;s height &gt; Sam&#039;s height... \t\t 13 &lt; 15...\n\r &quot; double quote\f\v string &quot;",
+  "\nRoy&#039;s height &gt\t; Sam&#039;s\v height\f",
+  "\r\tRoy&#039;s height &gt\r; Sam\t&#039;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&#039s height > Sam&#039;s $height... 1111 &ap; 0000 = 0000... " double quote string ""
+string(89) "Roy&#039s height > Sam&#039;s $height... 1111 &ap; 0000 = 0000... " double quote string ""
+string(99) "Roy&#039s height > Sam&#039;s $height... 1111 &ap; 0000 = 0000... &quot; double quote string &quot;"
+string(84) "Roy&#039s height > Sam's $height... 1111 &ap; 0000 = 0000... " double quote string ""
+-- Iteration 2 --
+string(82) "Roy&#039;s height > Sam&#039;s height...            13 < 15...
+
+ " double quote\f\v string ""
+string(82) "Roy&#039;s height > Sam&#039;s height...            13 < 15...
+
+ " double quote\f\v string ""
+string(92) "Roy&#039;s height > Sam&#039;s height...            13 < 15...
+
+ &quot; double quote\f\v string &quot;"
+string(72) "Roy's height > Sam's height...              13 < 15...
+
+ " double quote\f\v string ""
+-- Iteration 3 --
+string(44) "
+Roy&#039;s height &gt  ; Sam&#039;s\v height\f"
+string(44) "
+Roy&#039;s height &gt  ; Sam&#039;s\v height\f"
+string(44) "
+Roy&#039;s height &gt  ; Sam&#039;s\v height\f"
+string(34) "
+Roy's height &gt       ; Sam's\v height\f"
+-- Iteration 4 --
+string(44) "
+       Roy&#039;s height &gt
+; Sam  &#039;s height"
+string(44) "
+       Roy&#039;s height &gt
+; Sam  &#039;s height"
+string(44) "
+       Roy&#039;s height &gt
+; Sam  &#039;s height"
+string(34) "
+       Roy's height &gt
+; 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 (file)
index 0000000..d1636eb
Binary files /dev/null and b/ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt differ