1--TEST--
2Test fgetss() function : error conditions
3--FILE--
4<?php
5/*
6 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
7 Description: Gets line from file pointer and strip HTML tags
8*/
9
10echo "*** Testing error conditions ***\n";
11// zero argument
12echo "-- Testing fgetss() with zero argument --\n";
13var_dump( fgetss() );
14
15// more than expected no. of args
16echo "-- Testing fgetss() with more than expected number of arguments --\n";
17$fp = fopen(__FILE__, "r");
18var_dump( fgetss($fp, 100, '<p><a>', $fp) );
19
20// invalid length argument
21echo "-- Testing fgetss() with invalid length arguments --\n";
22$len = 0;
23$allowable_tags = '<p><a>';
24var_dump( fgetss($fp, $len, $allowable_tags) );
25$len = -10;
26var_dump( fgetss($fp, $len, $allowable_tags) );
27$len = 1;
28var_dump( fgetss($fp, $len, $allowable_tags) ); // return length - 1 always, expect false
29
30// test invalid arguments : non-resources
31echo "-- Testing fgetss() with invalid arguments --\n";
32$invalid_args = array (
33  "string",
34  10,
35  10.5,
36  true,
37  array(1,2,3),
38  new stdclass,
39);
40/* loop to test fgetss() with different invalid type of args */
41for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
42  echo "-- Iteration $loop_counter --\n";
43  var_dump( fgetss($invalid_args[$loop_counter - 1], 10, $allowable_tags) );
44}
45// fgetss() on a file handle which is already closed
46echo "-- Testing fgetss() with closed/unset file handle --";
47fclose($fp);
48var_dump(fgetss($fp,10,$allowable_tags));
49
50// fgetss() on a file handle which is unset
51$file_handle = fopen(__FILE__, "r");
52unset($file_handle); //unset file handle
53var_dump( fgetss(@$file_handle,10));
54
55echo "Done\n";
56?>
57--EXPECTF--
58*** Testing error conditions ***
59-- Testing fgetss() with zero argument --
60
61Warning: fgetss() expects at least 1 parameter, 0 given in %s on line %d
62bool(false)
63-- Testing fgetss() with more than expected number of arguments --
64
65Warning: fgetss() expects at most 3 parameters, 4 given in %s on line %d
66bool(false)
67-- Testing fgetss() with invalid length arguments --
68
69Warning: fgetss(): Length parameter must be greater than 0 in %s on line %d
70bool(false)
71
72Warning: fgetss(): Length parameter must be greater than 0 in %s on line %d
73bool(false)
74bool(false)
75-- Testing fgetss() with invalid arguments --
76-- Iteration 1 --
77
78Warning: fgetss() expects parameter 1 to be resource, string given in %s on line %d
79bool(false)
80-- Iteration 2 --
81
82Warning: fgetss() expects parameter 1 to be resource, integer given in %s on line %d
83bool(false)
84-- Iteration 3 --
85
86Warning: fgetss() expects parameter 1 to be resource, double given in %s on line %d
87bool(false)
88-- Iteration 4 --
89
90Warning: fgetss() expects parameter 1 to be resource, boolean given in %s on line %d
91bool(false)
92-- Iteration 5 --
93
94Warning: fgetss() expects parameter 1 to be resource, array given in %s on line %d
95bool(false)
96-- Iteration 6 --
97
98Warning: fgetss() expects parameter 1 to be resource, object given in %s on line %d
99bool(false)
100-- Testing fgetss() with closed/unset file handle --
101Warning: fgetss(): %d is not a valid stream resource in %s on line %d
102bool(false)
103
104Warning: fgetss() expects parameter 1 to be resource, null given in %s on line %d
105bool(false)
106Done
107