kraghuba                Fri Oct  5 18:47:47 2007 UTC

  Modified files:              
    /php-src/ext/standard/tests/strings nl2br_error.phpt 
                                        nl2br_variation1.phpt 
                                        nl2br_variation2.phpt 
                                        nl2br_variation3.phpt 
                                        nl2br_variation4.phpt 
                                        nl2br_variation5.phpt 
  Log:
  New testcases for nl2br() function
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/nl2br_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/nl2br_error.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/nl2br_error.phpt:1.2
--- /dev/null   Fri Oct  5 18:47:47 2007
+++ php-src/ext/standard/tests/strings/nl2br_error.phpt Fri Oct  5 18:47:47 2007
@@ -0,0 +1,33 @@
+--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 ***";
+
+// 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: nl2br() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing nl2br() function with more than expected no. of arguments --
+Warning: nl2br() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/nl2br_variation1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/nl2br_variation1.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/nl2br_variation1.phpt:1.2
--- /dev/null   Fri Oct  5 18:47:47 2007
+++ php-src/ext/standard/tests/strings/nl2br_variation1.phpt    Fri Oct  5 
18:47:47 2007
@@ -0,0 +1,113 @@
+--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
+  b"Hello\nWorld",  //binary input
+  "\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
+--UEXPECTF--
+*** Testing nl2br() : usage variations ***
+-- Iteration 1 --
+string(17) "Hello<br />
+World"
+-- Iteration 2 --
+unicode(31) "<br />
+Hello<br />
+World<br />
+"
+-- Iteration 3 --
+unicode(17) "Hello<br />World"
+-- Iteration 4 --
+unicode(31) "<br />Hello<br />World<br />"
+-- Iteration 5 --
+unicode(18) "Hello<br />
+World"
+-- Iteration 6 --
+unicode(34) "<br />
+Hello<br />
+World<br />
+"
+-- Iteration 7 --
+unicode(7) "<br />
+"
+-- Iteration 8 --
+unicode(14) "<br />
+<br />
+"
+-- Iteration 9 --
+unicode(17) "Hello<br />
+World"
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/nl2br_variation2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/nl2br_variation2.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/nl2br_variation2.phpt:1.2
--- /dev/null   Fri Oct  5 18:47:47 2007
+++ php-src/ext/standard/tests/strings/nl2br_variation2.phpt    Fri Oct  5 
18:47:47 2007
@@ -0,0 +1,95 @@
+--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
+--UEXPECTF--
+*** Testing nl2br() : usage variations ***
+-- Iteration 1 --
+unicode(2) "\n"
+-- Iteration 2 --
+unicode(2) "\r"
+-- Iteration 3 --
+unicode(4) "\r\n"
+-- Iteration 4 --
+unicode(12) "Hello\nWorld"
+-- Iteration 5 --
+unicode(12) "Hello\rWorld"
+-- Iteration 6 --
+unicode(14) "Hello\r\nWorld"
+-- Iteration 7 --
+unicode(7) "<br />
+"
+-- Iteration 8 --
+unicode(14) "<br />
+<br />
+"
+-- Iteration 9 --
+unicode(17) "Hello<br />
+World"
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/nl2br_variation3.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/nl2br_variation3.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/nl2br_variation3.phpt:1.2
--- /dev/null   Fri Oct  5 18:47:47 2007
+++ php-src/ext/standard/tests/strings/nl2br_variation3.phpt    Fri Oct  5 
18:47:47 2007
@@ -0,0 +1,92 @@
+--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
+--UEXPECTF--
+*** Testing nl2br() : usage variations ***
+unicode(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"
+unicode(118) "Hello<br />
+World<br />
+This is        es       for <br />
+ <br />
+ew lines<br />
+like <br />
+ <br />
+ <br /> <br />
+ and etc"
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/nl2br_variation4.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/nl2br_variation4.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/nl2br_variation4.phpt:1.2
--- /dev/null   Fri Oct  5 18:47:47 2007
+++ php-src/ext/standard/tests/strings/nl2br_variation4.phpt    Fri Oct  5 
18:47:47 2007
@@ -0,0 +1,52 @@
+--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
+--UEXPECTF--
+*** Testing nl2br() : usage variations ***
+unicode(29) "<html>Hello<br />world</html>"
+unicode(19) "<html><br /></html>"
+unicode(45) "<html><br />
+Hello<br />
+world<br /></html>"
+unicode(37) "<html><br />
+ <br />
+ <br /></html>"
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/nl2br_variation5.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/nl2br_variation5.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/nl2br_variation5.phpt:1.2
--- /dev/null   Fri Oct  5 18:47:47 2007
+++ php-src/ext/standard/tests/strings/nl2br_variation5.phpt    Fri Oct  5 
18:47:47 2007
@@ -0,0 +1,215 @@
+--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 input 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 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 13 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 14 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- 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 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), 
resource given in %s on line %d
+NULL
+-- Iteration 22 --
+string(9) "My String"
+-- Iteration 23 --
+string(0) ""
+-- Iteration 24 --
+string(0) ""
+Done
+--UEXPECTF--
+*** Testing nl2br() : usage variations ***
+-- Iteration 1 --
+unicode(1) "0"
+-- Iteration 2 --
+unicode(1) "1"
+-- Iteration 3 --
+unicode(5) "12345"
+-- Iteration 4 --
+unicode(5) "-2345"
+-- Iteration 5 --
+unicode(4) "10.5"
+-- Iteration 6 --
+unicode(5) "-10.5"
+-- Iteration 7 --
+unicode(12) "105000000000"
+-- Iteration 8 --
+unicode(7) "1.06E-9"
+-- Iteration 9 --
+unicode(3) "0.5"
+-- Iteration 10 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 13 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 14 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), array 
given in %s on line %d
+NULL
+-- Iteration 15 --
+unicode(0) ""
+-- Iteration 16 --
+unicode(0) ""
+-- Iteration 17 --
+unicode(1) "1"
+-- Iteration 18 --
+unicode(0) ""
+-- Iteration 19 --
+unicode(1) "1"
+-- Iteration 20 --
+unicode(0) ""
+-- Iteration 21 --
+
+Warning: nl2br() expects parameter 1 to be string (Unicode or binary), 
resource given in %s on line %d
+NULL
+-- Iteration 22 --
+unicode(9) "My String"
+-- Iteration 23 --
+unicode(0) ""
+-- Iteration 24 --
+unicode(0) ""
+Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to