1--TEST--
2Test fgetcsv() : usage variations - with only file handle as argument, file pointer pointing at end of file
3--FILE--
4<?php
5/*
6   Testing fgetcsv() to read a file whose file pointer is pointing to end of file
7   and fgetcsv() provided with only file handle in its argument
8*/
9
10echo "*** Testing fgetcsv() : with file handle as only argument and file pointer pointing at end of file ***\n";
11
12/* the array is with two elements in it. Each element should be read as
13   1st element is delimiter & 2nd element is csv fields
14*/
15$csv_lists = array (
16  array(',', 'water,fruit'),
17  array(' ', 'water fruit'),
18  array(' ', '"water" "fruit"'),
19  array('\\', 'water\\"fruit"\\"air"'),
20  array('\\', '"water"\\"fruit"\\"""'),
21);
22
23$filename = __DIR__ . '/fgetcsv_variation29.tmp';
24@unlink($filename);
25
26$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t",
27                     "a+", "a+b", "a+t",
28                     "w+", "w+b", "w+t",
29                     "x+", "x+b", "x+t");
30
31$loop_counter = 1;
32foreach ($csv_lists as $csv_list) {
33  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
34    // create the file and add the content with has csv fields
35    if ( strstr($file_modes[$mode_counter], "r") ) {
36      $file_handle = fopen($filename, "w");
37    } else {
38      $file_handle = fopen($filename, $file_modes[$mode_counter] );
39    }
40    if ( !$file_handle ) {
41      echo "Error: failed to create file $filename!\n";
42      exit();
43    }
44    $delimiter = $csv_list[0];
45    $csv_field = $csv_list[1];
46
47    fwrite($file_handle, $csv_field . "\n");
48    // write another line of text and a blank line
49    // this will be used to test, if the fgetcsv() read more than a line and its
50    // working when only a blan line is read
51    fwrite($file_handle, "This is line of text without csv fields\n");
52    fwrite($file_handle, "\n"); // blank line
53
54    // close the file if the mode to be used is read mode  and re-open using read mode
55    // else rewind the file pointer to beginning of the file
56    if ( strstr($file_modes[$mode_counter], "r" ) ) {
57      fclose($file_handle);
58      $file_handle = fopen($filename, $file_modes[$mode_counter]);
59    }
60
61    echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
62
63    // set the file pointer to EOF
64    var_dump( fseek($file_handle, 0, SEEK_END) );
65
66    // call fgetcsv() to parse csv fields
67
68    // now file pointer should point to end of the file, try reading again
69    var_dump( feof($file_handle) );
70    var_dump( fgetcsv($file_handle) );
71    // check the file pointer position and if eof
72    var_dump( ftell($file_handle) );
73    var_dump( feof($file_handle) );
74    // close the file
75    fclose($file_handle);
76    //delete file
77    unlink($filename);
78  } //end of mode loop
79} // end of foreach
80
81echo "Done\n";
82?>
83--EXPECTF--
84*** Testing fgetcsv() : with file handle as only argument and file pointer pointing at end of file ***
85
86-- Testing fgetcsv() with file opened using r mode --
87int(0)
88bool(false)
89bool(false)
90int(53)
91bool(true)
92
93-- Testing fgetcsv() with file opened using rb mode --
94int(0)
95bool(false)
96bool(false)
97int(53)
98bool(true)
99
100-- Testing fgetcsv() with file opened using rt mode --
101int(0)
102bool(false)
103bool(false)
104int(%d)
105bool(true)
106
107-- Testing fgetcsv() with file opened using r+ mode --
108int(0)
109bool(false)
110bool(false)
111int(53)
112bool(true)
113
114-- Testing fgetcsv() with file opened using r+b mode --
115int(0)
116bool(false)
117bool(false)
118int(53)
119bool(true)
120
121-- Testing fgetcsv() with file opened using r+t mode --
122int(0)
123bool(false)
124bool(false)
125int(%d)
126bool(true)
127
128-- Testing fgetcsv() with file opened using a+ mode --
129int(0)
130bool(false)
131bool(false)
132int(53)
133bool(true)
134
135-- Testing fgetcsv() with file opened using a+b mode --
136int(0)
137bool(false)
138bool(false)
139int(53)
140bool(true)
141
142-- Testing fgetcsv() with file opened using a+t mode --
143int(0)
144bool(false)
145bool(false)
146int(%d)
147bool(true)
148
149-- Testing fgetcsv() with file opened using w+ mode --
150int(0)
151bool(false)
152bool(false)
153int(53)
154bool(true)
155
156-- Testing fgetcsv() with file opened using w+b mode --
157int(0)
158bool(false)
159bool(false)
160int(53)
161bool(true)
162
163-- Testing fgetcsv() with file opened using w+t mode --
164int(0)
165bool(false)
166bool(false)
167int(%d)
168bool(true)
169
170-- Testing fgetcsv() with file opened using x+ mode --
171int(0)
172bool(false)
173bool(false)
174int(53)
175bool(true)
176
177-- Testing fgetcsv() with file opened using x+b mode --
178int(0)
179bool(false)
180bool(false)
181int(53)
182bool(true)
183
184-- Testing fgetcsv() with file opened using x+t mode --
185int(0)
186bool(false)
187bool(false)
188int(%d)
189bool(true)
190
191-- Testing fgetcsv() with file opened using r mode --
192int(0)
193bool(false)
194bool(false)
195int(53)
196bool(true)
197
198-- Testing fgetcsv() with file opened using rb mode --
199int(0)
200bool(false)
201bool(false)
202int(53)
203bool(true)
204
205-- Testing fgetcsv() with file opened using rt mode --
206int(0)
207bool(false)
208bool(false)
209int(%d)
210bool(true)
211
212-- Testing fgetcsv() with file opened using r+ mode --
213int(0)
214bool(false)
215bool(false)
216int(53)
217bool(true)
218
219-- Testing fgetcsv() with file opened using r+b mode --
220int(0)
221bool(false)
222bool(false)
223int(53)
224bool(true)
225
226-- Testing fgetcsv() with file opened using r+t mode --
227int(0)
228bool(false)
229bool(false)
230int(%d)
231bool(true)
232
233-- Testing fgetcsv() with file opened using a+ mode --
234int(0)
235bool(false)
236bool(false)
237int(53)
238bool(true)
239
240-- Testing fgetcsv() with file opened using a+b mode --
241int(0)
242bool(false)
243bool(false)
244int(53)
245bool(true)
246
247-- Testing fgetcsv() with file opened using a+t mode --
248int(0)
249bool(false)
250bool(false)
251int(%d)
252bool(true)
253
254-- Testing fgetcsv() with file opened using w+ mode --
255int(0)
256bool(false)
257bool(false)
258int(53)
259bool(true)
260
261-- Testing fgetcsv() with file opened using w+b mode --
262int(0)
263bool(false)
264bool(false)
265int(53)
266bool(true)
267
268-- Testing fgetcsv() with file opened using w+t mode --
269int(0)
270bool(false)
271bool(false)
272int(%d)
273bool(true)
274
275-- Testing fgetcsv() with file opened using x+ mode --
276int(0)
277bool(false)
278bool(false)
279int(53)
280bool(true)
281
282-- Testing fgetcsv() with file opened using x+b mode --
283int(0)
284bool(false)
285bool(false)
286int(53)
287bool(true)
288
289-- Testing fgetcsv() with file opened using x+t mode --
290int(0)
291bool(false)
292bool(false)
293int(%d)
294bool(true)
295
296-- Testing fgetcsv() with file opened using r mode --
297int(0)
298bool(false)
299bool(false)
300int(57)
301bool(true)
302
303-- Testing fgetcsv() with file opened using rb mode --
304int(0)
305bool(false)
306bool(false)
307int(57)
308bool(true)
309
310-- Testing fgetcsv() with file opened using rt mode --
311int(0)
312bool(false)
313bool(false)
314int(%d)
315bool(true)
316
317-- Testing fgetcsv() with file opened using r+ mode --
318int(0)
319bool(false)
320bool(false)
321int(57)
322bool(true)
323
324-- Testing fgetcsv() with file opened using r+b mode --
325int(0)
326bool(false)
327bool(false)
328int(57)
329bool(true)
330
331-- Testing fgetcsv() with file opened using r+t mode --
332int(0)
333bool(false)
334bool(false)
335int(%d)
336bool(true)
337
338-- Testing fgetcsv() with file opened using a+ mode --
339int(0)
340bool(false)
341bool(false)
342int(57)
343bool(true)
344
345-- Testing fgetcsv() with file opened using a+b mode --
346int(0)
347bool(false)
348bool(false)
349int(57)
350bool(true)
351
352-- Testing fgetcsv() with file opened using a+t mode --
353int(0)
354bool(false)
355bool(false)
356int(%d)
357bool(true)
358
359-- Testing fgetcsv() with file opened using w+ mode --
360int(0)
361bool(false)
362bool(false)
363int(57)
364bool(true)
365
366-- Testing fgetcsv() with file opened using w+b mode --
367int(0)
368bool(false)
369bool(false)
370int(57)
371bool(true)
372
373-- Testing fgetcsv() with file opened using w+t mode --
374int(0)
375bool(false)
376bool(false)
377int(%d)
378bool(true)
379
380-- Testing fgetcsv() with file opened using x+ mode --
381int(0)
382bool(false)
383bool(false)
384int(57)
385bool(true)
386
387-- Testing fgetcsv() with file opened using x+b mode --
388int(0)
389bool(false)
390bool(false)
391int(57)
392bool(true)
393
394-- Testing fgetcsv() with file opened using x+t mode --
395int(0)
396bool(false)
397bool(false)
398int(%d)
399bool(true)
400
401-- Testing fgetcsv() with file opened using r mode --
402int(0)
403bool(false)
404bool(false)
405int(61)
406bool(true)
407
408-- Testing fgetcsv() with file opened using rb mode --
409int(0)
410bool(false)
411bool(false)
412int(61)
413bool(true)
414
415-- Testing fgetcsv() with file opened using rt mode --
416int(0)
417bool(false)
418bool(false)
419int(%d)
420bool(true)
421
422-- Testing fgetcsv() with file opened using r+ mode --
423int(0)
424bool(false)
425bool(false)
426int(61)
427bool(true)
428
429-- Testing fgetcsv() with file opened using r+b mode --
430int(0)
431bool(false)
432bool(false)
433int(61)
434bool(true)
435
436-- Testing fgetcsv() with file opened using r+t mode --
437int(0)
438bool(false)
439bool(false)
440int(%d)
441bool(true)
442
443-- Testing fgetcsv() with file opened using a+ mode --
444int(0)
445bool(false)
446bool(false)
447int(61)
448bool(true)
449
450-- Testing fgetcsv() with file opened using a+b mode --
451int(0)
452bool(false)
453bool(false)
454int(61)
455bool(true)
456
457-- Testing fgetcsv() with file opened using a+t mode --
458int(0)
459bool(false)
460bool(false)
461int(%d)
462bool(true)
463
464-- Testing fgetcsv() with file opened using w+ mode --
465int(0)
466bool(false)
467bool(false)
468int(61)
469bool(true)
470
471-- Testing fgetcsv() with file opened using w+b mode --
472int(0)
473bool(false)
474bool(false)
475int(61)
476bool(true)
477
478-- Testing fgetcsv() with file opened using w+t mode --
479int(0)
480bool(false)
481bool(false)
482int(%d)
483bool(true)
484
485-- Testing fgetcsv() with file opened using x+ mode --
486int(0)
487bool(false)
488bool(false)
489int(61)
490bool(true)
491
492-- Testing fgetcsv() with file opened using x+b mode --
493int(0)
494bool(false)
495bool(false)
496int(61)
497bool(true)
498
499-- Testing fgetcsv() with file opened using x+t mode --
500int(0)
501bool(false)
502bool(false)
503int(%d)
504bool(true)
505
506-- Testing fgetcsv() with file opened using r mode --
507int(0)
508bool(false)
509bool(false)
510int(61)
511bool(true)
512
513-- Testing fgetcsv() with file opened using rb mode --
514int(0)
515bool(false)
516bool(false)
517int(61)
518bool(true)
519
520-- Testing fgetcsv() with file opened using rt mode --
521int(0)
522bool(false)
523bool(false)
524int(%d)
525bool(true)
526
527-- Testing fgetcsv() with file opened using r+ mode --
528int(0)
529bool(false)
530bool(false)
531int(61)
532bool(true)
533
534-- Testing fgetcsv() with file opened using r+b mode --
535int(0)
536bool(false)
537bool(false)
538int(61)
539bool(true)
540
541-- Testing fgetcsv() with file opened using r+t mode --
542int(0)
543bool(false)
544bool(false)
545int(%d)
546bool(true)
547
548-- Testing fgetcsv() with file opened using a+ mode --
549int(0)
550bool(false)
551bool(false)
552int(61)
553bool(true)
554
555-- Testing fgetcsv() with file opened using a+b mode --
556int(0)
557bool(false)
558bool(false)
559int(61)
560bool(true)
561
562-- Testing fgetcsv() with file opened using a+t mode --
563int(0)
564bool(false)
565bool(false)
566int(%d)
567bool(true)
568
569-- Testing fgetcsv() with file opened using w+ mode --
570int(0)
571bool(false)
572bool(false)
573int(61)
574bool(true)
575
576-- Testing fgetcsv() with file opened using w+b mode --
577int(0)
578bool(false)
579bool(false)
580int(61)
581bool(true)
582
583-- Testing fgetcsv() with file opened using w+t mode --
584int(0)
585bool(false)
586bool(false)
587int(%d)
588bool(true)
589
590-- Testing fgetcsv() with file opened using x+ mode --
591int(0)
592bool(false)
593bool(false)
594int(61)
595bool(true)
596
597-- Testing fgetcsv() with file opened using x+b mode --
598int(0)
599bool(false)
600bool(false)
601int(61)
602bool(true)
603
604-- Testing fgetcsv() with file opened using x+t mode --
605int(0)
606bool(false)
607bool(false)
608int(%d)
609bool(true)
610Done
611