1--TEST--
2Test fgetss() function : usage variations - write only modes
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. Not valid for Windows');
7}
8?>
9--FILE--
10<?php
11error_reporting(E_ALL & ~E_DEPRECATED);
12
13/*
14 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
15 Description: Gets line from file pointer and strip HTML tags
16*/
17
18/* try fgets on files which are opened in non readable modes
19    w, wb, wt,
20    a, ab, at,
21    x, xb, xt
22*/
23
24// include the common file related test functions
25include ("file.inc");
26
27echo "*** Testing fgetss() : usage variations ***\n";
28
29/* string with html and php tags */
30$string_with_tags = <<<EOT
31<test>Testing fgetss() functions</test>
32<?php echo "this string is within php tag"; ?> {;}<{> this
33is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
34<html> html </html> <?php echo "php"; ?>
35this line is without any html and php tags
36this is a line with more than eighty character,want to check line splitting correctly after 80 characters
37this text contains some html tags <body> body </body> <br> br </br>
38this is the line with \n character.
39EOT;
40
41$filename = __DIR__."/fgetss_variation1.tmp";
42
43/* try reading the file opened in different modes of reading */
44$file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt");
45
46for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
47  echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
48
49  /* create an empty file and write the strings with tags */
50  $file_handle = fopen($filename, $file_modes[$mode_counter]);
51  fwrite($file_handle,$string_with_tags);
52  if(!$file_handle) {
53    echo "Error: failed to open file $filename!\n";
54    exit();
55  }
56
57  // rewind the file pointer to beginning of the file
58  var_dump( filesize($filename) );
59  var_dump( rewind($file_handle) );
60  var_dump( ftell($file_handle) );
61  var_dump( feof($file_handle) );
62
63  /* read entire file and strip tags */
64  echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n";
65  var_dump( fgetss($file_handle) ); // expected : no character should be read
66  var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed
67  var_dump( feof($file_handle) ); // check if end of file pointer is set
68
69  // close the file
70  fclose($file_handle);
71
72  // delete the file
73  delete_file($filename);
74} // end of for - mode_counter
75
76echo "Done\n";
77?>
78--EXPECTF--
79*** Testing fgetss() : usage variations ***
80
81-- Testing fgetss() with file opened using w mode --
82int(445)
83bool(true)
84int(0)
85bool(false)
86-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
87
88Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
89bool(false)
90int(0)
91bool(false)
92
93-- Testing fgetss() with file opened using wb mode --
94int(445)
95bool(true)
96int(0)
97bool(false)
98-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
99
100Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
101bool(false)
102int(0)
103bool(false)
104
105-- Testing fgetss() with file opened using wt mode --
106int(445)
107bool(true)
108int(0)
109bool(false)
110-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
111
112Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
113bool(false)
114int(0)
115bool(false)
116
117-- Testing fgetss() with file opened using a mode --
118int(445)
119bool(true)
120int(0)
121bool(false)
122-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
123
124Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
125bool(false)
126int(0)
127bool(false)
128
129-- Testing fgetss() with file opened using ab mode --
130int(445)
131bool(true)
132int(0)
133bool(false)
134-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
135
136Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
137bool(false)
138int(0)
139bool(false)
140
141-- Testing fgetss() with file opened using at mode --
142int(445)
143bool(true)
144int(0)
145bool(false)
146-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
147
148Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
149bool(false)
150int(0)
151bool(false)
152
153-- Testing fgetss() with file opened using x mode --
154int(445)
155bool(true)
156int(0)
157bool(false)
158-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
159
160Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
161bool(false)
162int(0)
163bool(false)
164
165-- Testing fgetss() with file opened using xb mode --
166int(445)
167bool(true)
168int(0)
169bool(false)
170-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
171
172Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
173bool(false)
174int(0)
175bool(false)
176
177-- Testing fgetss() with file opened using xt mode --
178int(445)
179bool(true)
180int(0)
181bool(false)
182-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
183
184Notice: fgetss(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
185bool(false)
186int(0)
187bool(false)
188Done
189