diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-10-09 12:44:45 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-10-09 12:44:45 +0000 |
commit | 1d0c11f472b4440ed6670c3076a850f18d0272d2 (patch) | |
tree | 1c9152fceb3f4f0123389ea13dc100e095b5fd25 /ext | |
parent | 5f24b53cc5f23cf8c5028910c82792b6c5cec5fb (diff) | |
download | php-git-1d0c11f472b4440ed6670c3076a850f18d0272d2.tar.gz |
New testcases for strip_tags() function
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/tests/strings/strip_tags_basic1.phpt | 75 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_basic2.phpt | 61 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_error.phpt | 40 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation1.phpt | 157 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation10.phpt | 55 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation2.phpt | 159 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation3.phpt | 167 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation4.phpt | 74 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation5.phpt | 105 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation6.phpt | 47 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation7.phpt | 72 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation8.phpt | 59 | ||||
-rw-r--r-- | ext/standard/tests/strings/strip_tags_variation9.phpt | 56 |
13 files changed, 1127 insertions, 0 deletions
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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strip_tags() : basic functionality ***\n"; + +// array of arguments +$string_array = array ( + "<html>hello</html>", + '<html>hello</html>', + "<?php echo hello ?>", + '<?php echo hello ?>', + "<? echo hello ?>", + '<? echo hello ?>', + "<% echo hello %>", + '<% echo hello %>', + "<script language=\"PHP\"> echo hello </script>", + '<script language=\"PHP\"> echo hello </script>', + "<html><b>hello</b><p>world</p></html>", + '<html><b>hello</b><p>world</p></html>', + "<html><!-- COMMENT --></html>", + '<html><!-- COMMENT --></html>' +); + + +// 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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strip_tags() : basic functionality ***\n"; + +// Calling strip_tags() with all possible arguments +$string = "<html><p>hello</p><b>world</b><a href=\"#fragment\">Other text</a></html><?php echo hello ?>"; + +$allowed_tags_array=array( + "<html>", + '<html>', + "<p>", + '<p>', + "<a>", + '<a>', + "<?php", + '<?php', + "<html><p><a><?php" +); + +// loop through the $string with various $allowed_tags_array to test strip_tags +// on various allowed tags +$iteration = 1; +foreach($allowed_tags_array as $tags) +{ + echo "-- Iteration $iteration --\n"; + var_dump( strip_tags($string, $tags) ); + $iteration++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing strip_tags() : basic functionality *** +-- Iteration 1 -- +string(33) "<html>helloworldOther text</html>" +-- Iteration 2 -- +string(33) "<html>helloworldOther text</html>" +-- Iteration 3 -- +string(27) "<p>hello</p>worldOther text" +-- Iteration 4 -- +string(27) "<p>hello</p>worldOther text" +-- Iteration 5 -- +string(44) "helloworld<a href="#fragment">Other text</a>" +-- Iteration 6 -- +string(44) "helloworld<a href="#fragment">Other text</a>" +-- Iteration 7 -- +string(20) "helloworldOther text" +-- Iteration 8 -- +string(20) "helloworldOther text" +-- Iteration 9 -- +string(64) "<html><p>hello</p>world<a href="#fragment">Other text</a></html>" +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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + + +echo "*** Testing strip_tags() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing strip_tags() function with Zero arguments --\n"; +var_dump( strip_tags() ); + +//Test strip_tags with one more than the expected number of arguments +echo "\n-- Testing strip_tags() function with more than expected no. of arguments --\n"; +$str = "<html>hello</html>"; +$allowable_tags = "<html>"; +$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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving unexpected input values for $str argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +//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($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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving single quoted strings as values for $str argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + + +$single_quote_string = array ( + '<html> \$ -> This represents the dollar sign</html><?php echo hello ?>', + '<html>\t\r\v The quick brown fo\fx jumped over the lazy dog</p>', + '<a>This is a hyper text tag</a>', + '<? <html>hello world\\t</html>?>', + '<p>This is a paragraph</p>', + '<b>This is \ta text in bold letters\r\s\malong with slashes\n</b>' +); + +$quotes = "<html><a><p><b><?php"; + +//loop through the various elements of strings array to test strip_tags() functionality +$iterator = 1; +foreach($single_quote_string 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(51) "<html> \$ -> This represents the dollar sign</html>" +-- Iteration 2 -- +string(63) "<html>\t\r\v The quick brown fo\fx jumped over the lazy dog</p>" +-- Iteration 3 -- +string(31) "<a>This is a hyper text tag</a>" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(26) "<p>This is a paragraph</p>" +-- Iteration 6 -- +string(65) "<b>This is \ta text in bold letters\r\s\malong with slashes\n</b>" +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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving unexpected values for $allowable_tags argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +// Initialise function argument +$string = "<html><a>hello</a></html><p>world</p><!-- COMMENT --><?php echo hello ?>"; + +//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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving unexpected values for $str and $allowable_tags arguments +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +// get a resource +$fp=fopen(__FILE__, "r"); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// 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($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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving invalid values for $str and valid values for $allowable_tags argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +// unexpected values for $string +$strings = array ( + "<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>", + '<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>', + "<%?php hello\t world?%>", + '<%?php hello\t world?%>', + "<<htmL>>hello<</htmL>>", + '<<htmL>>hello<</htmL>>', + "<a.>HtMl text</.a>", + '<a.>HtMl text</.a>', + "<nnn>I am not a valid html text</nnn>", + '<nnn>I am not a valid html text</nnn>', + "<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>", + '<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>', +); + +//valid html and php tags +$quotes = "<p><a><?php<html>"; + +//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) "<htmL>hello</htmL>" +-- Iteration 6 -- +string(18) "<htmL>hello</htmL>" +-- 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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + + +/* + * testing functionality of strip_tags() by giving heredoc strings as values for $str argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +// null here doc string +$null_string = <<<EOT +EOT; + +// heredoc string with blank line +$blank_line = <<<EOT + +EOT; + +// here doc with multiline string +$multiline_string = <<<EOT +<html>hello world</html> +<p>13 < 25</p> +<?php 1111 & 0000 = 0000 ?> +<b>This is a double quoted string</b> +EOT; + +// here doc with diferent whitespaces +$diff_whitespaces = <<<EOT +<html>hello\r world\t +1111\t\t != 2222\v\v</html> +<? heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces ?> +EOT; + +// here doc with numeric values +$numeric_string = <<<EOT +<html>11 < 12. 123 >22</html> +<p>string</p> 1111\t <b>0000\t = 0000\n</b> +EOT; + +// heredoc with quote chars & slash +$quote_char_string = <<<EOT +<html>This's a string with quotes:</html> +"strings in double quote"; +'strings in single quote'; +<html>this\line is single quoted /with\slashes </html> +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 = "<html><a><?php"; + +// loop through $res_heredoc_strings element and check the working on strip_tags() +$count = 1; +for($index =0; $index < count($res_heredoc_strings); $index ++) { + echo "-- Iteration $count --\n"; + var_dump( strip_tags($res_heredoc_strings[$index], $quotes) ); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strip_tags() : usage variations *** +-- Iteration 1 -- +string(0) "" +-- Iteration 2 -- +string(0) "" +-- Iteration 3 -- +string(67) "<html>hello world</html> +13 < 25 + +This is a double quoted string" +-- Iteration 4 -- +string(44) "<html>hello + world +1111 != 2222</html> +" +-- Iteration 5 -- +string(56) "<html>11 < 12. 123 >22</html> +string 1111 0000 = 0000 +" +-- Iteration 6 -- +string(150) "<html>This's a string with quotes:</html> +"strings in double quote"; +'strings in single quote'; +<html>this\line is single quoted /with\slashes </html>" +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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing whether strip_tags() is binary safe or not +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +//various string inputs +$strings = array ( + "<html> I am html string </html>".chr(0)."<?php I am php string ?>", + "<html> I am html string\0 </html><?php I am php string ?>", + b"<a>I am html string</a>", + "<html>I am html string</html>".decbin(65)."<?php I am php string?>" +); + +//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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving invalid values for $str and $allowable_tags argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +$strings = array ( + "<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>", + '<abc>hello</abc> \t\tworld... <ppp>strip_tags_test</ppp>', + "<%?php hello\t world?%>", + '<%?php hello\t world?%>', + "<<htmL>>hello<</htmL>>", + '<<htmL>>hello<</htmL>>', + "<a.>HtMl text</.a>", + '<a.>HtMl text</.a>', + "<nnn>I am not a valid html text</nnn>", + '<nnn>I am not a valid html text</nnn>', + "<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>", + '<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>', +); + +$quotes = "<nnn><abc><%?<<html>>"; + +//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) "<abc>hello</abc> world... strip_tags_test" +-- Iteration 2 -- +string(45) "<abc>hello</abc> \t\tworld... strip_tags_test" +-- Iteration 3 -- +string(0) "" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(18) "<htmL>hello</htmL>" +-- Iteration 6 -- +string(18) "<htmL>hello</htmL>" +-- Iteration 7 -- +string(9) "HtMl text" +-- Iteration 8 -- +string(9) "HtMl text" +-- Iteration 9 -- +string(37) "<nnn>I am not a valid html text</nnn>" +-- Iteration 10 -- +string(37) "<nnn>I am not a valid html text</nnn>" +-- Iteration 11 -- +string(73) "<nnn>I am a quoted (") string with special chars like $,\!,\@,\%,\&</nnn>" +-- Iteration 12 -- +string(75) "<nnn>I am a quoted (\") string with special chars like \$,\!,\@,\%,\&</nnn>" +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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving valid value for $str and invalid values for $allowable_tags argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +$strings = "<html>hello</html> \tworld... <p>strip_tags_test\v\f</p><?php hello\t wo\rrld?>"; + +$quotes = array ( + "<nnn>", + '<nnn>', + "<abc>", + '<abc>', + "<%?php", + '<%?php', + "<<html>>", + '<<html>>' +); + +//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) "<html>hello</html> world... strip_tags_test" +-- Iteration 8 -- +string(46) "<html>hello</html> 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-- +<?php +/* Prototype : string strip_tags(string $str [, string $allowable_tags]) + * Description: Strips HTML and PHP tags from a string + * Source code: ext/standard/string.c +*/ + +/* + * testing functionality of strip_tags() by giving double quoted strings as values for $str argument +*/ + +echo "*** Testing strip_tags() : usage variations ***\n"; + +$double_quote_string = array ( + "<html> \$ -> This represents the dollar sign</html><?php echo hello ?>", + "<html>\t\r\v The quick brown fo\fx jumped over the lazy dog</p>", + "<a>This is a hyper text tag</a>", + "<? <html>hello world\\t</html>?>", + "<p>This is a paragraph</p>", + "<b>This is \ta text in bold letters\r\s\malong with slashes\n</b>" +); + +$quotes = "<html><a><p><b><?php"; + +//loop through the various elements of strings array to test strip_tags() functionality +$iterator = 1; +foreach($double_quote_string 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(50) "<html> $ -> This represents the dollar sign</html>" +-- Iteration 2 -- +string(59) "<html> + The quick brown fox jumped over the lazy dog</p>" +-- Iteration 3 -- +string(31) "<a>This is a hyper text tag</a>" +-- Iteration 4 -- +string(0) "" +-- Iteration 5 -- +string(26) "<p>This is a paragraph</p>" +-- Iteration 6 -- +string(62) "<b>This is a text in bold letters +\s\malong with slashes +</b>" +Done |