Annotation of embedaddon/php/ext/standard/tests/file/fgetss_variation5.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test fgetss() function : usage variations - read/write modes, file pointer at EOF
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) == 'WIN') {
6: die('skip.. Not valid for Windows');
7: }
8: ?>
9: --FILE--
10: <?php
11: /*
12: Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
13: Description: Gets line from file pointer and strip HTML tags
14: */
15:
16: /* try fgetss on files which are opened in read/write modes
17: w+, w+b, w+t,
18: a+, a+b, a+t,
19: x+, x+b, x+t
20: */
21:
22:
23: echo "*** Testing fgetss() : usage variations ***\n";
24:
25: /* string with html and php tags */
26: $string_with_tags = <<<EOT
27: <test>Testing fgetss() functions</test>
28: <?php echo "this string is within php tag"; ?> {;}<{> this
29: is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
30: <html> html </html> <?php echo "php"; ?>
31: this line is without any html and php tags
32: this is a line with more than eighty character,want to check line splitting correctly after 80 characters
33: this text contains some html tags <body> body </body> <br> br </br>
34: this is the line with \n character.
35: EOT;
36:
37: $filename = dirname(__FILE__)."/fgetss_variation5.tmp";
38:
39: /* try reading the file opened in different modes of reading */
40: $file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t");
41:
42: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
43: echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
44:
45: /* create an empty file and write the strings with tags */
46: $file_handle = fopen($filename, $file_modes[$mode_counter]);
47: fwrite($file_handle,$string_with_tags); //writing data to the file
48: if(!$file_handle) {
49: echo "Error: failed to open file $filename!\n";
50: exit();
51: }
1.1.1.2 ! misho 52: // rewind the file pointer to beginning of the file
1.1 misho 53: var_dump( filesize($filename) );
54: var_dump( rewind($file_handle) );
55: var_dump( ftell($file_handle) );
56: var_dump( feof($file_handle) );
57:
58: echo "-- Reading when file pointer points to EOF --\n";
59: var_dump( fseek($file_handle,0,SEEK_END) ); // now file pointer at end
60: var_dump( ftell($file_handle) ); //ensure file pointer at end
61: var_dump( fgetss($file_handle) ); // try to read
62: var_dump( ftell($file_handle) ); // find out file position
63: var_dump( feof($file_handle) ); // ensure that file pointer is at eof
64:
65: // now file is at the end try reading with length and allowable tags,expecting false
66: var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
67: var_dump( ftell($file_handle) ); // find out file position
68: var_dump( feof($file_handle) ); // ensure that file pointer is at eof
69:
70:
71: // close the file
72: fclose($file_handle);
73:
74: // delete the file
75: unlink($filename);
76: } // end of for - mode_counter
77:
78: echo "Done\n";
79: ?>
80: --EXPECTF--
81: *** Testing fgetss() : usage variations ***
82:
83: -- Testing fgetss() with file opened using w+ mode --
84: int(445)
85: bool(true)
86: int(0)
87: bool(false)
88: -- Reading when file pointer points to EOF --
89: int(0)
90: int(445)
91: bool(false)
92: int(445)
93: bool(true)
94: bool(false)
95: int(445)
96: bool(true)
97:
98: -- Testing fgetss() with file opened using w+b mode --
99: int(445)
100: bool(true)
101: int(0)
102: bool(false)
103: -- Reading when file pointer points to EOF --
104: int(0)
105: int(445)
106: bool(false)
107: int(445)
108: bool(true)
109: bool(false)
110: int(445)
111: bool(true)
112:
113: -- Testing fgetss() with file opened using w+t mode --
114: int(445)
115: bool(true)
116: int(0)
117: bool(false)
118: -- Reading when file pointer points to EOF --
119: int(0)
120: int(445)
121: bool(false)
122: int(445)
123: bool(true)
124: bool(false)
125: int(445)
126: bool(true)
127:
128: -- Testing fgetss() with file opened using a+ mode --
129: int(445)
130: bool(true)
131: int(0)
132: bool(false)
133: -- Reading when file pointer points to EOF --
134: int(0)
135: int(445)
136: bool(false)
137: int(445)
138: bool(true)
139: bool(false)
140: int(445)
141: bool(true)
142:
143: -- Testing fgetss() with file opened using a+b mode --
144: int(445)
145: bool(true)
146: int(0)
147: bool(false)
148: -- Reading when file pointer points to EOF --
149: int(0)
150: int(445)
151: bool(false)
152: int(445)
153: bool(true)
154: bool(false)
155: int(445)
156: bool(true)
157:
158: -- Testing fgetss() with file opened using a+t mode --
159: int(445)
160: bool(true)
161: int(0)
162: bool(false)
163: -- Reading when file pointer points to EOF --
164: int(0)
165: int(445)
166: bool(false)
167: int(445)
168: bool(true)
169: bool(false)
170: int(445)
171: bool(true)
172:
173: -- Testing fgetss() with file opened using x+ mode --
174: int(445)
175: bool(true)
176: int(0)
177: bool(false)
178: -- Reading when file pointer points to EOF --
179: int(0)
180: int(445)
181: bool(false)
182: int(445)
183: bool(true)
184: bool(false)
185: int(445)
186: bool(true)
187:
188: -- Testing fgetss() with file opened using x+b mode --
189: int(445)
190: bool(true)
191: int(0)
192: bool(false)
193: -- Reading when file pointer points to EOF --
194: int(0)
195: int(445)
196: bool(false)
197: int(445)
198: bool(true)
199: bool(false)
200: int(445)
201: bool(true)
202:
203: -- Testing fgetss() with file opened using x+t mode --
204: int(445)
205: bool(true)
206: int(0)
207: bool(false)
208: -- Reading when file pointer points to EOF --
209: int(0)
210: int(445)
211: bool(false)
212: int(445)
213: bool(true)
214: bool(false)
215: int(445)
216: bool(true)
217: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>