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