1--TEST--
2Test wordwrap() function : usage variations  - unexptected values for break argument
3--FILE--
4<?php
5/* Prototype  : string wordwrap ( string $str [, int $width [, string $break [, bool $cut]]] )
6 * Description: Wraps buffer to selected number of characters using string break char
7 * Source code: ext/standard/string.c
8*/
9
10/*
11 * test wordwrap by passing different values for break argument
12*/
13echo "*** Testing wordwrap() : usage variations ***\n";
14// initialize all required variables
15$str = 'testing wordwrap function';
16$width = 10;
17$cut = true;
18
19// resource var
20$fp = fopen(__FILE__, "r");
21
22// get an unset variable
23$unset_var = 'string_val';
24unset($unset_var);
25
26
27// array with different values for break arg
28$values =  array (
29
30  // integer values
31  0,
32  1,
33  12345,
34  -2345,
35
36  // float values
37  10.5,
38  -10.5,
39  10.1234567e10,
40  10.7654321E-10,
41  .5,
42
43  // array values
44  array(),
45  array(0),
46  array(1),
47  array(1, 2),
48  array('color' => 'red', 'item' => 'pen'),
49
50  // boolean values
51  true,
52  false,
53  TRUE,
54  FALSE,
55
56  // objects
57  new stdclass(),
58
59  // empty string
60  "",
61  '',
62
63  //Null
64  NULL,
65  null,
66
67  // resource var
68  $fp,
69
70  // undefined variable
71  @$undefined_var,
72
73  // unset variable
74  @$unset_var
75);
76
77// loop though each element of the array and check the working of wordwrap()
78// when $break argument is supplied with different values
79echo "\n--- Testing wordwrap() by supplying different values for 'break' argument ---\n";
80$counter = 1;
81for($index = 0; $index < count($values); $index ++) {
82  echo "-- Iteration $counter --\n";
83  $break = $values [$index];
84
85  var_dump( wordwrap($str, $width, $break) );
86
87  // $cut as false
88  $cut = false;
89  var_dump( wordwrap($str, $width, $break, $cut) );
90
91  // $cut as true
92  $cut = true;
93  var_dump( wordwrap($str, $width, $break, $cut) );
94
95  $counter ++;
96}
97
98// close the resource used
99fclose($fp);
100
101echo "Done\n";
102?>
103--EXPECTF--
104*** Testing wordwrap() : usage variations ***
105
106--- Testing wordwrap() by supplying different values for 'break' argument ---
107-- Iteration 1 --
108string(25) "testing0wordwrap0function"
109string(25) "testing0wordwrap0function"
110string(25) "testing0wordwrap0function"
111-- Iteration 2 --
112string(25) "testing1wordwrap1function"
113string(25) "testing1wordwrap1function"
114string(25) "testing1wordwrap1function"
115-- Iteration 3 --
116string(33) "testing12345wordwrap12345function"
117string(33) "testing12345wordwrap12345function"
118string(33) "testing12345wordwrap12345function"
119-- Iteration 4 --
120string(33) "testing-2345wordwrap-2345function"
121string(33) "testing-2345wordwrap-2345function"
122string(33) "testing-2345wordwrap-2345function"
123-- Iteration 5 --
124string(31) "testing10.5wordwrap10.5function"
125string(31) "testing10.5wordwrap10.5function"
126string(31) "testing10.5wordwrap10.5function"
127-- Iteration 6 --
128string(33) "testing-10.5wordwrap-10.5function"
129string(33) "testing-10.5wordwrap-10.5function"
130string(33) "testing-10.5wordwrap-10.5function"
131-- Iteration 7 --
132string(47) "testing101234567000wordwrap101234567000function"
133string(47) "testing101234567000wordwrap101234567000function"
134string(47) "testing101234567000wordwrap101234567000function"
135-- Iteration 8 --
136string(49) "testing1.07654321E-9wordwrap1.07654321E-9function"
137string(49) "testing1.07654321E-9wordwrap1.07654321E-9function"
138string(49) "testing1.07654321E-9wordwrap1.07654321E-9function"
139-- Iteration 9 --
140string(29) "testing0.5wordwrap0.5function"
141string(29) "testing0.5wordwrap0.5function"
142string(29) "testing0.5wordwrap0.5function"
143-- Iteration 10 --
144
145Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
146NULL
147
148Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
149NULL
150
151Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
152NULL
153-- Iteration 11 --
154
155Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
156NULL
157
158Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
159NULL
160
161Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
162NULL
163-- Iteration 12 --
164
165Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
166NULL
167
168Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
169NULL
170
171Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
172NULL
173-- Iteration 13 --
174
175Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
176NULL
177
178Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
179NULL
180
181Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
182NULL
183-- Iteration 14 --
184
185Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
186NULL
187
188Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
189NULL
190
191Warning: wordwrap() expects parameter 3 to be string, array given in %s on line %d
192NULL
193-- Iteration 15 --
194string(25) "testing1wordwrap1function"
195string(25) "testing1wordwrap1function"
196string(25) "testing1wordwrap1function"
197-- Iteration 16 --
198
199Warning: wordwrap(): Break string cannot be empty in %s on line %d
200bool(false)
201
202Warning: wordwrap(): Break string cannot be empty in %s on line %d
203bool(false)
204
205Warning: wordwrap(): Break string cannot be empty in %s on line %d
206bool(false)
207-- Iteration 17 --
208string(25) "testing1wordwrap1function"
209string(25) "testing1wordwrap1function"
210string(25) "testing1wordwrap1function"
211-- Iteration 18 --
212
213Warning: wordwrap(): Break string cannot be empty in %s on line %d
214bool(false)
215
216Warning: wordwrap(): Break string cannot be empty in %s on line %d
217bool(false)
218
219Warning: wordwrap(): Break string cannot be empty in %s on line %d
220bool(false)
221-- Iteration 19 --
222
223Warning: wordwrap() expects parameter 3 to be string, object given in %s on line %d
224NULL
225
226Warning: wordwrap() expects parameter 3 to be string, object given in %s on line %d
227NULL
228
229Warning: wordwrap() expects parameter 3 to be string, object given in %s on line %d
230NULL
231-- Iteration 20 --
232
233Warning: wordwrap(): Break string cannot be empty in %s on line %d
234bool(false)
235
236Warning: wordwrap(): Break string cannot be empty in %s on line %d
237bool(false)
238
239Warning: wordwrap(): Break string cannot be empty in %s on line %d
240bool(false)
241-- Iteration 21 --
242
243Warning: wordwrap(): Break string cannot be empty in %s on line %d
244bool(false)
245
246Warning: wordwrap(): Break string cannot be empty in %s on line %d
247bool(false)
248
249Warning: wordwrap(): Break string cannot be empty in %s on line %d
250bool(false)
251-- Iteration 22 --
252
253Warning: wordwrap(): Break string cannot be empty in %s on line %d
254bool(false)
255
256Warning: wordwrap(): Break string cannot be empty in %s on line %d
257bool(false)
258
259Warning: wordwrap(): Break string cannot be empty in %s on line %d
260bool(false)
261-- Iteration 23 --
262
263Warning: wordwrap(): Break string cannot be empty in %s on line %d
264bool(false)
265
266Warning: wordwrap(): Break string cannot be empty in %s on line %d
267bool(false)
268
269Warning: wordwrap(): Break string cannot be empty in %s on line %d
270bool(false)
271-- Iteration 24 --
272
273Warning: wordwrap() expects parameter 3 to be string, resource given in %s on line %d
274NULL
275
276Warning: wordwrap() expects parameter 3 to be string, resource given in %s on line %d
277NULL
278
279Warning: wordwrap() expects parameter 3 to be string, resource given in %s on line %d
280NULL
281-- Iteration 25 --
282
283Warning: wordwrap(): Break string cannot be empty in %s on line %d
284bool(false)
285
286Warning: wordwrap(): Break string cannot be empty in %s on line %d
287bool(false)
288
289Warning: wordwrap(): Break string cannot be empty in %s on line %d
290bool(false)
291-- Iteration 26 --
292
293Warning: wordwrap(): Break string cannot be empty in %s on line %d
294bool(false)
295
296Warning: wordwrap(): Break string cannot be empty in %s on line %d
297bool(false)
298
299Warning: wordwrap(): Break string cannot be empty in %s on line %d
300bool(false)
301Done
302