Annotation of embedaddon/php/ext/standard/tests/strings/nl2br_variation5.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test nl2br() function : usage variations - unexpected values for 'str' argument
3: --FILE--
4: <?php
5: /* Prototype : string nl2br(string $str)
6: * Description: Inserts HTML line breaks before all newlines in a string.
7: * Source code: ext/standard/string.c
8: */
9:
10: /*
11: * Test nl2br() function by passing different types of values other than
12: * expected type for 'str' argument
13: */
14:
15: echo "*** Testing nl2br() : usage variations ***\n";
16:
17: //get an unset variable
18: $unset_var = 10;
19: unset ($unset_var);
20:
21: //getting resource
22: $file_handle = fopen(__FILE__, "r");
23:
24: //defining class
25: class Sample {
26: public function __toString() {
27: return "My String";
28: }
29: }
30:
31: //array of values to iterate over
32: $values = array(
33:
34: // int data
35: 0,
36: 1,
37: 12345,
38: -2345,
39:
40: // float data
41: 10.5,
42: -10.5,
43: 10.5e10,
44: 10.6E-10,
45: .5,
46:
47: // array data
48: array(),
49: array(0),
50: array(1),
51: array(1, 2),
52: array('color' => 'red', 'item' => 'pen'),
53:
54: // null data
55: NULL,
56: null,
57:
58: // boolean data
59: true,
60: false,
61: TRUE,
62: FALSE,
63:
64: //resource
65: $file_handle,
66:
67: // object data
68: new Sample(),
69:
70: // undefined data
71: @$undefined_var,
72:
73: // unset data
74: @$unset_var,
75: );
76:
77: // loop through $values array to test nl2br() function with each element
78: $count = 1;
79: foreach($values as $value) {
80: echo "-- Iteration $count --\n";
81: var_dump( nl2br($value) );
82: $count ++ ;
83: };
84:
85: //closing the file handle
86: fclose( $file_handle );
87:
88: echo "Done";
89: ?>
90: --EXPECTF--
91: *** Testing nl2br() : usage variations ***
92: -- Iteration 1 --
93: string(1) "0"
94: -- Iteration 2 --
95: string(1) "1"
96: -- Iteration 3 --
97: string(5) "12345"
98: -- Iteration 4 --
99: string(5) "-2345"
100: -- Iteration 5 --
101: string(4) "10.5"
102: -- Iteration 6 --
103: string(5) "-10.5"
104: -- Iteration 7 --
105: string(12) "105000000000"
106: -- Iteration 8 --
107: string(7) "1.06E-9"
108: -- Iteration 9 --
109: string(3) "0.5"
110: -- Iteration 10 --
111:
112: Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d
113: NULL
114: -- Iteration 11 --
115:
116: Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d
117: NULL
118: -- Iteration 12 --
119:
120: Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d
121: NULL
122: -- Iteration 13 --
123:
124: Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d
125: NULL
126: -- Iteration 14 --
127:
128: Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d
129: NULL
130: -- Iteration 15 --
131: string(0) ""
132: -- Iteration 16 --
133: string(0) ""
134: -- Iteration 17 --
135: string(1) "1"
136: -- Iteration 18 --
137: string(0) ""
138: -- Iteration 19 --
139: string(1) "1"
140: -- Iteration 20 --
141: string(0) ""
142: -- Iteration 21 --
143:
144: Warning: nl2br() expects parameter 1 to be string, resource given in %s on line %d
145: NULL
146: -- Iteration 22 --
147: string(9) "My String"
148: -- Iteration 23 --
149: string(0) ""
150: -- Iteration 24 --
151: string(0) ""
152: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>