1--TEST--
2Test wordwrap() function : error conditions
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
10echo "*** Testing wordwrap() : error conditions ***\n";
11
12// Zero argument
13echo "\n-- Testing wordwrap() function with Zero arguments --\n";
14var_dump( wordwrap() );
15
16// More than expected number of arguments
17echo "\n-- Testing wordwrap() function with more than expected no. of arguments --\n";
18$str = 'testing wordwrap function';
19$width = 10;
20$break = '<br />\n';
21$cut = true;
22$extra_arg = "extra_arg";
23
24var_dump( wordwrap($str, $width, $break, $cut, $extra_arg) );
25
26// $width arg as negative value
27echo "\n-- Testing wordwrap() function with negative/zero value for width argument --\n";
28echo "-- width = 0 & cut = false --\n";
29// width as zero and cut as false
30$width = 0;
31$cut = false;
32var_dump( wordwrap($str, $width, $break, $cut) );
33
34echo "-- width = 0 & cut = true --\n";
35// width as zero and cut as true
36$width = 0;
37$cut = true;
38var_dump( wordwrap($str, $width, $break, $cut) );
39
40echo "-- width = -10 & cut = false --\n";
41// width as -ne and cut as false
42$width = -10;
43$cut = false;
44var_dump( wordwrap($str, $width, $break, $cut) );
45
46echo "-- width = -10 & cut = true --\n";
47// width as -ne and cut as true
48$width = -10;
49$cut = true;
50var_dump( wordwrap($str, $width, $break, $cut) );
51
52echo "Done\n";
53?>
54--EXPECTF--
55*** Testing wordwrap() : error conditions ***
56
57-- Testing wordwrap() function with Zero arguments --
58
59Warning: wordwrap() expects at least 1 parameter, 0 given in %s on line %d
60NULL
61
62-- Testing wordwrap() function with more than expected no. of arguments --
63
64Warning: wordwrap() expects at most 4 parameters, 5 given in %s on line %d
65NULL
66
67-- Testing wordwrap() function with negative/zero value for width argument --
68-- width = 0 & cut = false --
69string(39) "testing<br />\nwordwrap<br />\nfunction"
70-- width = 0 & cut = true --
71
72Warning: wordwrap(): Can't force cut when width is zero in %s on line %d
73bool(false)
74-- width = -10 & cut = false --
75string(39) "testing<br />\nwordwrap<br />\nfunction"
76-- width = -10 & cut = true --
77string(223) "<br />\nt<br />\ne<br />\ns<br />\nt<br />\ni<br />\nn<br />\ng<br />\n<br />\nw<br />\no<br />\nr<br />\nd<br />\nw<br />\nr<br />\na<br />\np<br />\n<br />\nf<br />\nu<br />\nn<br />\nc<br />\nt<br />\ni<br />\no<br />\nn"
78Done
79