diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-10-05 18:46:02 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-10-05 18:46:02 +0000 |
commit | a458ad89f93810451d3a7988b8d137abe82ec136 (patch) | |
tree | 7e72205592904147e5ef7f7e8fcce82a384cf359 | |
parent | 8ad09bf445c547cd224c9412026a0162c0396c32 (diff) | |
download | php-git-a458ad89f93810451d3a7988b8d137abe82ec136.tar.gz |
New testcases for nl2br() function
-rw-r--r-- | ext/standard/tests/strings/nl2br_error.phpt | 34 | ||||
-rw-r--r-- | ext/standard/tests/strings/nl2br_variation1.phpt | 84 | ||||
-rw-r--r-- | ext/standard/tests/strings/nl2br_variation2.phpt | 70 | ||||
-rw-r--r-- | ext/standard/tests/strings/nl2br_variation3.phpt | 75 | ||||
-rw-r--r-- | ext/standard/tests/strings/nl2br_variation4.phpt | 43 | ||||
-rw-r--r-- | ext/standard/tests/strings/nl2br_variation5.phpt | 150 |
6 files changed, 456 insertions, 0 deletions
diff --git a/ext/standard/tests/strings/nl2br_error.phpt b/ext/standard/tests/strings/nl2br_error.phpt new file mode 100644 index 0000000000..c600dddda6 --- /dev/null +++ b/ext/standard/tests/strings/nl2br_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test nl2br() function : error conditions +--FILE-- +<?php +/* Prototype : string nl2br(string $str) + * Description: Inserts HTML line breaks before all newlines in a string. + * Source code: ext/standard/string.c +*/ + +echo "*** Testing nl2br() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing nl2br() function with Zero arguments --"; +var_dump( nl2br() ); + +//Test nl2br with one more than the expected number of arguments +echo "\n-- Testing nl2br() function with more than expected no. of arguments --"; +$str = 'string_val'; +$extra_arg = 10; +var_dump( nl2br($str, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing nl2br() : error conditions *** + +-- Testing nl2br() function with Zero arguments -- +Warning: Wrong parameter count for nl2br() in %s on line %d +NULL + +-- Testing nl2br() function with more than expected no. of arguments -- +Warning: Wrong parameter count for nl2br() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/strings/nl2br_variation1.phpt b/ext/standard/tests/strings/nl2br_variation1.phpt new file mode 100644 index 0000000000..89480cbca5 --- /dev/null +++ b/ext/standard/tests/strings/nl2br_variation1.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test nl2br() function : usage variations - double quoted strings for 'str' argument +--FILE-- +<?php +/* Prototype : string nl2br(string $str); + * Description: Inserts HTML line breaks before all newlines in a string + * Source code: ext/standard/string.c +*/ + +/* Test nl2br() function by passing double quoted strings containing various + * combinations of new line chars to 'str' argument +*/ + +echo "*** Testing nl2br() : usage variations ***\n"; + +$strings = array( + //new line chars embedded in strings + "Hello\nWorld", + "\nHello\nWorld\n", + "Hello\rWorld", + "\rHello\rWorld\r", + "Hello\r\nWorld", + "\r\nHello\r\nWorld\r\n", + + //one blank line + " +", + + //two blank lines + " + +", + + //inserted new line in a string + "Hello +World" +); + +//loop through $strings array to test nl2br() function with each element +$count = 1; +foreach( $strings as $str ){ + echo "-- Iteration $count --\n"; + var_dump(nl2br($str) ); + $count ++ ; +} +echo "Done"; +?> +--EXPECTF-- +*** Testing nl2br() : usage variations *** +-- Iteration 1 -- +string(17) "Hello<br /> +World" +-- Iteration 2 -- +string(31) "<br /> +Hello<br /> +World<br /> +" +-- Iteration 3 -- +string(17) "Hello<br /> +World" +-- Iteration 4 -- +string(31) "<br /> +Hello<br /> +World<br /> +" +-- Iteration 5 -- +string(18) "Hello<br /> +World" +-- Iteration 6 -- +string(34) "<br /> +Hello<br /> +World<br /> +" +-- Iteration 7 -- +string(7) "<br /> +" +-- Iteration 8 -- +string(14) "<br /> +<br /> +" +-- Iteration 9 -- +string(17) "Hello<br /> +World" +Done diff --git a/ext/standard/tests/strings/nl2br_variation2.phpt b/ext/standard/tests/strings/nl2br_variation2.phpt new file mode 100644 index 0000000000..a4423df319 --- /dev/null +++ b/ext/standard/tests/strings/nl2br_variation2.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test nl2br() function : usage variations - single quoted strings for 'str' argument +--FILE-- +<?php +/* Prototype : string nl2br(string $str); + * Description: Inserts HTML line breaks before all newlines in a string + * Source code: ext/standard/string.c +*/ + +/* Test nl2br() function by passing single quoted strings containing various + * combinations of new line chars to 'str' argument +*/ + +echo "*** Testing nl2br() : usage variations ***\n"; +$strings = array( + '\n', + '\r', + '\r\n', + 'Hello\nWorld', + 'Hello\rWorld', + 'Hello\r\nWorld', + + //one blank line + ' +', + + //two blank lines + ' + +', + + //inserted new line + 'Hello +World' +); + +//loop through $strings array to test nl2br() function with each element +$count = 1; +foreach( $strings as $str ){ + echo "-- Iteration $count --\n"; + var_dump(nl2br($str) ); + $count ++ ; +} +echo "Done"; +?> +--EXPECTF-- +*** Testing nl2br() : usage variations *** +-- Iteration 1 -- +string(2) "\n" +-- Iteration 2 -- +string(2) "\r" +-- Iteration 3 -- +string(4) "\r\n" +-- Iteration 4 -- +string(12) "Hello\nWorld" +-- Iteration 5 -- +string(12) "Hello\rWorld" +-- Iteration 6 -- +string(14) "Hello\r\nWorld" +-- Iteration 7 -- +string(7) "<br /> +" +-- Iteration 8 -- +string(14) "<br /> +<br /> +" +-- Iteration 9 -- +string(17) "Hello<br /> +World" +Done diff --git a/ext/standard/tests/strings/nl2br_variation3.phpt b/ext/standard/tests/strings/nl2br_variation3.phpt new file mode 100644 index 0000000000..c7baced910 --- /dev/null +++ b/ext/standard/tests/strings/nl2br_variation3.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test nl2br() function : usage variations - heredoc strings for 'str' argument +--FILE-- +<?php +/* Prototype : string nl2br(string $str); + * Description: Inserts HTML line breaks before all newlines in a string. + * Source code: ext/standard/string.c +*/ + +/* Test nl2br() function by passing heredoc strings containing various + * combinations of new line chars to 'str' argument +*/ + +echo "*** Testing nl2br() : usage variations ***\n"; +//heredoc string containing new line chars(\n, \r and combinations of \r & \n) and new lines +$heredoc_str1 = <<<EOD +\n +\r +\r\n +\nnn\n\n\nn +\rrr\r\r\rr +\n\r\n\r\r\n\nr\rn +EOD; + +//heredoc string containing embedded 'new line chars'/'new lines' in the string +$heredoc_str2 = <<<EOD +Hello\nWorld\r +This is \tes\t for \n \new lines +like \n \r\n \r \n\r and etc +EOD; + +var_dump(nl2br($heredoc_str1) ); +var_dump(nl2br($heredoc_str2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing nl2br() : usage variations *** +string(147) "<br /> +<br /> + +<br /> + +<br /> +<br /> +<br /> +nn<br /> +<br /> +<br /> +n<br /> + +rr<br /> +<br /> +<br /> +r<br /> +<br /> + +<br /> + +<br /> +<br /> +r<br /> +n" +string(118) "Hello<br /> +World<br /> +This is es for <br /> + <br /> +ew lines<br /> +like <br /> + <br /> + <br /> + <br /> + + and etc" +Done diff --git a/ext/standard/tests/strings/nl2br_variation4.phpt b/ext/standard/tests/strings/nl2br_variation4.phpt new file mode 100644 index 0000000000..eceb067021 --- /dev/null +++ b/ext/standard/tests/strings/nl2br_variation4.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test nl2br() function : usage variations - html values for 'str' argument +--FILE-- +<?php +/* Prototype : string nl2br(string $str) + * Description: Inserts HTML line breaks before all newlines in a string. + * Source code: ext/standard/string.c +*/ + +/* +* Test nl2br() function by passing html string inputs containing line breaks and +* new line chars for 'str' +*/ + +echo "*** Testing nl2br() : usage variations ***\n"; + +//array of html strings +$strings = array( + "<html>Hello<br />world</html>", + "<html><br /></html>", + "<html>\nHello\r\nworld\r</html>", + "<html>\n \r\n \r</html>", +); + +//loop through $strings array to test nl2br() function with each element +foreach( $strings as $str ){ + var_dump(nl2br($str) ); +} +echo "Done"; +?> +--EXPECTF-- +*** Testing nl2br() : usage variations *** +string(29) "<html>Hello<br />world</html>" +string(19) "<html><br /></html>" +string(45) "<html><br /> +Hello<br /> +world<br /> +</html>" +string(37) "<html><br /> + <br /> + <br /> +</html>" +Done diff --git a/ext/standard/tests/strings/nl2br_variation5.phpt b/ext/standard/tests/strings/nl2br_variation5.phpt new file mode 100644 index 0000000000..df19cb324b --- /dev/null +++ b/ext/standard/tests/strings/nl2br_variation5.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test nl2br() function : usage variations - unexpected values for 'str' argument +--FILE-- +<?php +/* Prototype : string nl2br(string $str) + * Description: Inserts HTML line breaks before all newlines in a string. + * Source code: ext/standard/string.c +*/ + +/* +* Test nl2br() function by passing different types of values other than +* expected type for 'str' argument +*/ + +echo "*** Testing nl2br() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//getting resource +$file_handle = fopen(__FILE__, "r"); + +//defining class +class Sample { + public function __toString() { + return "My String"; + } +} + +//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, + + //resource + $file_handle, + + // object data + new Sample(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, +); + +// loop through $values array to test nl2br() function with each element +$count = 1; +foreach($values as $value) { + echo "-- Iteration $count --\n"; + var_dump( nl2br($value) ); + $count ++ ; +}; + +//closing the file handle +fclose( $file_handle ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing nl2br() : 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(14) "Resource id #5" +-- Iteration 22 -- +string(9) "My String" +-- Iteration 23 -- +string(0) "" +-- Iteration 24 -- +string(0) "" +Done |