1--TEST--
2Test fgetss() function : usage variations - write only modes
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip.. only on 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
41if(substr(PHP_OS, 0, 3) == "WIN")  {
42	$string_with_tags = str_replace("\r",'', $string_with_tags);
43}
44
45$filename = dirname(__FILE__)."/fgetss_variation1.tmp";
46
47/* try reading the file opened in different modes of reading */
48$file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt");
49
50for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
51  echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
52
53  /* create an empty file and write the strings with tags */
54  $file_handle = fopen($filename, $file_modes[$mode_counter]);
55  fwrite($file_handle,$string_with_tags);
56  if(!$file_handle) {
57    echo "Error: failed to open file $filename!\n";
58    exit();
59  }
60
61  // rewind the file pointer to beginning of the file
62  var_dump( filesize($filename) );
63  var_dump( rewind($file_handle) );
64  var_dump( ftell($file_handle) );
65  var_dump( feof($file_handle) );
66
67  /* read entire file and strip tags */
68  echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n";
69  var_dump( fgetss($file_handle) ); // expected : no character should be read
70  var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed
71  var_dump( feof($file_handle) ); // check if end of file pointer is set
72
73  // close the file
74  fclose($file_handle);
75
76  // delete the file
77  delete_file($filename);
78} // end of for - mode_counter
79
80echo "Done\n";
81?>
82--EXPECT--
83*** Testing fgetss() : usage variations ***
84
85-- Testing fgetss() with file opened using w mode --
86int(445)
87bool(true)
88int(0)
89bool(false)
90-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
91bool(false)
92int(0)
93bool(false)
94
95-- Testing fgetss() with file opened using wb mode --
96int(445)
97bool(true)
98int(0)
99bool(false)
100-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
101bool(false)
102int(0)
103bool(false)
104
105-- Testing fgetss() with file opened using wt mode --
106int(453)
107bool(true)
108int(0)
109bool(false)
110-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
111bool(false)
112int(0)
113bool(false)
114
115-- Testing fgetss() with file opened using a mode --
116int(445)
117bool(true)
118int(0)
119bool(false)
120-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
121bool(false)
122int(0)
123bool(false)
124
125-- Testing fgetss() with file opened using ab mode --
126int(445)
127bool(true)
128int(0)
129bool(false)
130-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
131bool(false)
132int(0)
133bool(false)
134
135-- Testing fgetss() with file opened using at mode --
136int(453)
137bool(true)
138int(0)
139bool(false)
140-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
141bool(false)
142int(0)
143bool(false)
144
145-- Testing fgetss() with file opened using x mode --
146int(445)
147bool(true)
148int(0)
149bool(false)
150-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
151bool(false)
152int(0)
153bool(false)
154
155-- Testing fgetss() with file opened using xb mode --
156int(445)
157bool(true)
158int(0)
159bool(false)
160-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
161bool(false)
162int(0)
163bool(false)
164
165-- Testing fgetss() with file opened using xt mode --
166int(453)
167bool(true)
168int(0)
169bool(false)
170-- fgetss() with default length, file pointer at 0 , expected : no character should be read --
171bool(false)
172int(0)
173bool(false)
174Done
175