]> granicus.if.org Git - php/commitdiff
New and fixed html tests. Tested in Windows, Linux and Linux 64.
authorandy wharmby <wharmby@php.net>
Tue, 23 Jun 2009 22:45:30 +0000 (22:45 +0000)
committerandy wharmby <wharmby@php.net>
Tue, 23 Jun 2009 22:45:30 +0000 (22:45 +0000)
ext/standard/tests/strings/htmlentities09.phpt
ext/standard/tests/strings/htmlentities16.phpt
ext/standard/tests/strings/htmlspecialchars_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation1.phpt
ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt

index 4c6ef60c740ec8efec6a7a1cfe2e4eb9386fa4e7..c9ffe128e739b4a093dc65d0ddc791767895f691 100644 (file)
@@ -16,8 +16,10 @@ output_handler=
 <?php
        mb_internal_encoding('Shift_JIS');
        print mb_internal_encoding()."\n";
-       var_dump(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, ''));
+       var_dump(bin2hex((binary)htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, '')));
 ?>
+===DONE===
 --EXPECT--
 SJIS
-string(6) "\81A\81B\81C"
+unicode(12) "814181428143"
+===DONE===
index 0f945280b52f18156b3d0165512933154609b274..7f83a6b4b1449290145de63b7af5c81fdd8cbf4d 100644 (file)
@@ -13,9 +13,12 @@ output_handler=
 --FILE--
 <?php
 mb_internal_encoding('cp1251');
-$str = "\x88\xa9\xf0\xee\xf1\xea\xee\xf8\xed\xfb\xe9";
-var_dump($str, htmlentities($str, ENT_QUOTES, ''));
+$str = b"\x88\xa9\xf0\xee\xf1\xea\xee\xf8\xed\xfb\xe9";
+var_dump(bin2hex($str));
+var_dump(htmlentities($str, ENT_QUOTES, ''));
 ?>
+===DONE===
 --EXPECT--
-string(11) "\88©ðîñêîøíûé"
+unicode(22) "88a9f0eef1eaeef8edfbe9"
 string(75) "&euro;&copy;&#1088;&#1086;&#1089;&#1082;&#1086;&#1096;&#1085;&#1099;&#1081;"
+===DONE===
diff --git a/ext/standard/tests/strings/htmlspecialchars_basic.phpt b/ext/standard/tests/strings/htmlspecialchars_basic.phpt
new file mode 100644 (file)
index 0000000..3ef932a
--- /dev/null
@@ -0,0 +1,97 @@
+--TEST--
+Test htmlspecialchars() function : basic functionality 
+--FILE--
+<?php
+/* Prototype  : string htmlspecialchars  ( string $string  [, int $quote_style  [, string $charset  [, bool $double_encode  ]]] )
+ * Description: Convert special characters to HTML entities
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing htmlspecialchars() : basic functionality ***\n";
+
+$s1 = "abc<>\"&\n";
+$s2 = "&&abc<>\"&\n";
+$s3 = "a>,\<bc<>\"&\n";
+$s4 = "a\'\'&bc<>\"&\n";
+$s5 = "&amp;&lt;\n";
+echo "Basic tests\n";
+echo "Test 1: " . htmlspecialchars ($s1);
+echo "Test 2: " . htmlspecialchars ($s2);
+echo "Test 3: " . htmlspecialchars ($s3);
+echo "Test 4: " . htmlspecialchars ($s4);
+echo "Test 5: " . htmlspecialchars ($s5);
+echo "Test 6: " . htmlspecialchars ($s1,ENT_NOQUOTES);
+echo "Test 7: " . htmlspecialchars ($s2,ENT_NOQUOTES);
+echo "Test 8: " . htmlspecialchars ($s3,ENT_NOQUOTES);
+echo "Test 9: " . htmlspecialchars ($s4,ENT_NOQUOTES);
+echo "Test 10: " . htmlspecialchars ($s5,ENT_NOQUOTES);
+echo "Test 11: " . htmlspecialchars ($s1,ENT_COMPAT);
+echo "Test 12: " . htmlspecialchars ($s2,ENT_COMPAT);
+echo "Test 13: " . htmlspecialchars ($s3,ENT_COMPAT);
+echo "Test 14: " . htmlspecialchars ($s4,ENT_COMPAT);
+echo "Test 15: " . htmlspecialchars ($s5,ENT_COMPAT);
+echo "Test 16: " . htmlspecialchars ($s1,ENT_QUOTES);
+echo "Test 17: " . htmlspecialchars ($s2,ENT_QUOTES);
+echo "Test 18: " . htmlspecialchars ($s3,ENT_QUOTES);
+echo "Test 19: " . htmlspecialchars ($s4,ENT_QUOTES);
+echo "Test 20: " . htmlspecialchars ($s5,ENT_QUOTES);
+
+echo "\nTry with char set option - specify default ISO-8859-1\n";
+echo  "Test 21: " . htmlspecialchars ($s1,ENT_NOQUOTES, "ISO-8859-1");
+echo  "Test 22: " . htmlspecialchars ($s2,ENT_COMPAT, "ISO-8859-1");
+echo  "Test 23: " . htmlspecialchars ($s3,ENT_QUOTES, "ISO-8859-1");
+echo  "Test 24: " . htmlspecialchars ($s5,ENT_QUOTES, "ISO-8859-1");
+
+echo "\nTry with double decode FALSE\n";
+$s1 = "&quot;&amp;xyz&gt;abc&quot;\n";
+$s2 = "&quot;&amp;123&lt;456&quot;\n";
+$s3 = "\"300 < 400\"\n";
+echo  "Test 25: " . htmlspecialchars ($s1,ENT_NOQUOTES, "ISO-8859-1", false);
+echo  "Test 26: " . htmlspecialchars ($s2,ENT_NOQUOTES, "ISO-8859-1", false);
+echo  "Test 27: " . htmlspecialchars ($s3,ENT_NOQUOTES, "ISO-8859-1", false);
+
+echo "\nTry with double decode TRUE\n";
+echo  "Test 28: " . htmlspecialchars ($s1, ENT_NOQUOTES, "ISO-8859-1", true);
+echo  "Test 29: " . htmlspecialchars ($s2, ENT_NOQUOTES, "ISO-8859-1", true);
+
+?>
+===DONE===
+--EXPECT--
+*** Testing htmlspecialchars() : basic functionality ***
+Basic tests
+Test 1: abc&lt;&gt;&quot;&amp;
+Test 2: &amp;&amp;abc&lt;&gt;&quot;&amp;
+Test 3: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
+Test 4: a\'\'&amp;bc&lt;&gt;&quot;&amp;
+Test 5: &amp;amp;&amp;lt;
+Test 6: abc&lt;&gt;"&amp;
+Test 7: &amp;&amp;abc&lt;&gt;"&amp;
+Test 8: a&gt;,\&lt;bc&lt;&gt;"&amp;
+Test 9: a\'\'&amp;bc&lt;&gt;"&amp;
+Test 10: &amp;amp;&amp;lt;
+Test 11: abc&lt;&gt;&quot;&amp;
+Test 12: &amp;&amp;abc&lt;&gt;&quot;&amp;
+Test 13: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
+Test 14: a\'\'&amp;bc&lt;&gt;&quot;&amp;
+Test 15: &amp;amp;&amp;lt;
+Test 16: abc&lt;&gt;&quot;&amp;
+Test 17: &amp;&amp;abc&lt;&gt;&quot;&amp;
+Test 18: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
+Test 19: a\&#039;\&#039;&amp;bc&lt;&gt;&quot;&amp;
+Test 20: &amp;amp;&amp;lt;
+
+Try with char set option - specify default ISO-8859-1
+Test 21: abc&lt;&gt;"&amp;
+Test 22: &amp;&amp;abc&lt;&gt;&quot;&amp;
+Test 23: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
+Test 24: &amp;amp;&amp;lt;
+
+Try with double decode FALSE
+Test 25: &quot;&amp;xyz&gt;abc&quot;
+Test 26: &quot;&amp;123&lt;456&quot;
+Test 27: "300 &lt; 400"
+
+Try with double decode TRUE
+Test 28: &amp;quot;&amp;amp;xyz&amp;gt;abc&amp;quot;
+Test 29: &amp;quot;&amp;amp;123&amp;lt;456&amp;quot;
+===DONE===
\ No newline at end of file
index 137af5243fad83b5f8e782a6f8b8182e96b5da77..27b68774b975c55026ae248b63495e6a0169df5b 100644 (file)
@@ -31,51 +31,51 @@ 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
+             // int data
+/*1*/     0,
+             1,
+             12345,
+             -2345,
+       
+             // float data
+/*5*/     10.5,
+             -10.5,
+             10.1234567e10,
+             10.7654321E-10,
+             .5,
+       
+             // array data
+/*10*/    array(),
+             array(0),
+             array(1),
+             array(1, 2),
+             array('color' => 'red', 'item' => 'pen'),
+       
+             // null data
+/*15*/    NULL,
+             null,
+       
+             // boolean data
+/*17*/    true,
+             false,
+             TRUE,
+             FALSE,
+       
+             // empty data
+/*21*/    "",
+             '',
+       
+             // object data
+/*23*/    new classA(),
+       
+             // undefined data
+/*24*/    @$undefined_var,
+       
+             // unset data
+/*25*/    @$unset_var,
+       
+             //resource
+/*26*/    $file_handle
 );
 
 // loop through each element of the array for string
@@ -89,8 +89,8 @@ foreach($values as $value) {
 // close the file resource used
 fclose($file_handle);
 
-echo "Done";
 ?>
+===DONE===
 --EXPECTF--
 *** Testing htmlspecialchars_decode() : usage variations ***
 -- Iterator 1 --
@@ -106,9 +106,9 @@ unicode(4) "10.5"
 -- Iterator 6 --
 unicode(5) "-10.5"
 -- Iterator 7 --
-unicode(12) "105000000000"
+unicode(12) "101234567000"
 -- Iterator 8 --
-unicode(7) "1.06E-9"
+unicode(13) "1.07654321E-9"
 -- Iterator 9 --
 unicode(3) "0.5"
 -- Iterator 10 --
@@ -157,4 +157,5 @@ unicode(0) ""
 
 Warning: htmlspecialchars_decode() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
 NULL
-Done
+===DONE===
+       
\ No newline at end of file
index fcaa6ea6f46dc1e8c8419a37cc8dc4e6e3a13dab..ba0dabefce9d86c609e52de39a84d3c176eda61d 100644 (file)
Binary files a/ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt and b/ext/standard/tests/strings/htmlspecialchars_decode_variation6.phpt differ