Annotation of embedaddon/php/ext/standard/tests/file/fgetcsv_variation19.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fgetcsv() : usage variations - with default enclosure & delimiter of two chars
3: --FILE--
4: <?php
5: /*
6: Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] );
7: Description: Gets line from file pointer and parse for CSV fields
8: */
9:
10: /*
11: Testing fgetcsv() to read a file when provided with default enclosure character
12: and with delimiter of two characters
13: */
14:
15: echo "*** Testing fgetcsv() : with default enclosure & delimiter of two chars ***\n";
16:
17: /* the array is with two elements in it. Each element should be read as
18: 1st element is delimiter & 2nd element is csv fields
19: */
20: $csv_lists = array (
21: array(',', 'water,fruit'),
22: array(' ', 'water fruit'),
23: array(' ', '"water" "fruit"'),
24: array('\\', 'water\\"fruit"\\"air"'),
25: array('\\', '"water"\\"fruit"\\"""'),
26: );
27:
28: $filename = dirname(__FILE__) . '/fgetcsv_variation19.tmp';
29: @unlink($filename);
30:
31: $file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t",
32: "a+", "a+b", "a+t",
33: "w+", "w+b", "w+t",
34: "x+", "x+b", "x+t");
35:
36: $loop_counter = 1;
37: foreach ($csv_lists as $csv_list) {
38: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
39: // create the file and add the content with has csv fields
40: if ( strstr($file_modes[$mode_counter], "r") ) {
41: $file_handle = fopen($filename, "w");
42: } else {
43: $file_handle = fopen($filename, $file_modes[$mode_counter] );
44: }
45: if ( !$file_handle ) {
46: echo "Error: failed to create file $filename!\n";
47: exit();
48: }
49: $delimiter = $csv_list[0];
50: $csv_field = $csv_list[1];
51: fwrite($file_handle, $csv_field . "\n");
52: // write another line of text and a blank line
53: // this will be used to test, if the fgetcsv() read more than a line and its
54: // working when only a blank line is read
55: fwrite($file_handle, "This is line of text without csv fields\n");
56: fwrite($file_handle, "\n"); // blank line
57:
58: // close the file if the mode to be used is read mode and re-open using read mode
59: // else rewind the file pointer to begining of the file
60: if ( strstr($file_modes[$mode_counter], "r" ) ) {
61: fclose($file_handle);
62: $file_handle = fopen($filename, $file_modes[$mode_counter]);
63: } else {
64: // rewind the file pointer to bof
65: rewind($file_handle);
66: }
67:
68: echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
69:
70: // call fgetcsv() to parse csv fields
71:
72: // use delimiter & enclosure char of two chars
73: fseek($file_handle, 0, SEEK_SET);
74: $del = "++";
75: var_dump( fgetcsv($file_handle, 1024, $del) );
76: // check the file pointer position and if eof
77: var_dump( ftell($file_handle) );
78: var_dump( feof($file_handle) );
79:
80: // close the file
81: fclose($file_handle);
82: //delete file
83: unlink($filename);
84: } //end of mode loop
85: } // end of foreach
86:
87: echo "Done\n";
88: ?>
89: --EXPECTF--
90: *** Testing fgetcsv() : with default enclosure & delimiter of two chars ***
91:
92: -- Testing fgetcsv() with file opened using r mode --
93:
94: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
95: array(1) {
96: [0]=>
97: string(11) "water,fruit"
98: }
99: int(12)
100: bool(false)
101:
102: -- Testing fgetcsv() with file opened using rb mode --
103:
104: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
105: array(1) {
106: [0]=>
107: string(11) "water,fruit"
108: }
109: int(12)
110: bool(false)
111:
112: -- Testing fgetcsv() with file opened using rt mode --
113:
114: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
115: array(1) {
116: [0]=>
117: string(11) "water,fruit"
118: }
119: int(12)
120: bool(false)
121:
122: -- Testing fgetcsv() with file opened using r+ mode --
123:
124: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
125: array(1) {
126: [0]=>
127: string(11) "water,fruit"
128: }
129: int(12)
130: bool(false)
131:
132: -- Testing fgetcsv() with file opened using r+b mode --
133:
134: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
135: array(1) {
136: [0]=>
137: string(11) "water,fruit"
138: }
139: int(12)
140: bool(false)
141:
142: -- Testing fgetcsv() with file opened using r+t mode --
143:
144: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
145: array(1) {
146: [0]=>
147: string(11) "water,fruit"
148: }
149: int(12)
150: bool(false)
151:
152: -- Testing fgetcsv() with file opened using a+ mode --
153:
154: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
155: array(1) {
156: [0]=>
157: string(11) "water,fruit"
158: }
159: int(12)
160: bool(false)
161:
162: -- Testing fgetcsv() with file opened using a+b mode --
163:
164: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
165: array(1) {
166: [0]=>
167: string(11) "water,fruit"
168: }
169: int(12)
170: bool(false)
171:
172: -- Testing fgetcsv() with file opened using a+t mode --
173:
174: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
175: array(1) {
176: [0]=>
177: string(11) "water,fruit"
178: }
179: int(12)
180: bool(false)
181:
182: -- Testing fgetcsv() with file opened using w+ mode --
183:
184: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
185: array(1) {
186: [0]=>
187: string(11) "water,fruit"
188: }
189: int(12)
190: bool(false)
191:
192: -- Testing fgetcsv() with file opened using w+b mode --
193:
194: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
195: array(1) {
196: [0]=>
197: string(11) "water,fruit"
198: }
199: int(12)
200: bool(false)
201:
202: -- Testing fgetcsv() with file opened using w+t mode --
203:
204: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
205: array(1) {
206: [0]=>
207: string(11) "water,fruit"
208: }
209: int(12)
210: bool(false)
211:
212: -- Testing fgetcsv() with file opened using x+ mode --
213:
214: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
215: array(1) {
216: [0]=>
217: string(11) "water,fruit"
218: }
219: int(12)
220: bool(false)
221:
222: -- Testing fgetcsv() with file opened using x+b mode --
223:
224: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
225: array(1) {
226: [0]=>
227: string(11) "water,fruit"
228: }
229: int(12)
230: bool(false)
231:
232: -- Testing fgetcsv() with file opened using x+t mode --
233:
234: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
235: array(1) {
236: [0]=>
237: string(11) "water,fruit"
238: }
239: int(12)
240: bool(false)
241:
242: -- Testing fgetcsv() with file opened using r mode --
243:
244: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
245: array(1) {
246: [0]=>
247: string(11) "water fruit"
248: }
249: int(12)
250: bool(false)
251:
252: -- Testing fgetcsv() with file opened using rb mode --
253:
254: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
255: array(1) {
256: [0]=>
257: string(11) "water fruit"
258: }
259: int(12)
260: bool(false)
261:
262: -- Testing fgetcsv() with file opened using rt mode --
263:
264: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
265: array(1) {
266: [0]=>
267: string(11) "water fruit"
268: }
269: int(12)
270: bool(false)
271:
272: -- Testing fgetcsv() with file opened using r+ mode --
273:
274: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
275: array(1) {
276: [0]=>
277: string(11) "water fruit"
278: }
279: int(12)
280: bool(false)
281:
282: -- Testing fgetcsv() with file opened using r+b mode --
283:
284: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
285: array(1) {
286: [0]=>
287: string(11) "water fruit"
288: }
289: int(12)
290: bool(false)
291:
292: -- Testing fgetcsv() with file opened using r+t mode --
293:
294: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
295: array(1) {
296: [0]=>
297: string(11) "water fruit"
298: }
299: int(12)
300: bool(false)
301:
302: -- Testing fgetcsv() with file opened using a+ mode --
303:
304: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
305: array(1) {
306: [0]=>
307: string(11) "water fruit"
308: }
309: int(12)
310: bool(false)
311:
312: -- Testing fgetcsv() with file opened using a+b mode --
313:
314: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
315: array(1) {
316: [0]=>
317: string(11) "water fruit"
318: }
319: int(12)
320: bool(false)
321:
322: -- Testing fgetcsv() with file opened using a+t mode --
323:
324: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
325: array(1) {
326: [0]=>
327: string(11) "water fruit"
328: }
329: int(12)
330: bool(false)
331:
332: -- Testing fgetcsv() with file opened using w+ mode --
333:
334: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
335: array(1) {
336: [0]=>
337: string(11) "water fruit"
338: }
339: int(12)
340: bool(false)
341:
342: -- Testing fgetcsv() with file opened using w+b mode --
343:
344: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
345: array(1) {
346: [0]=>
347: string(11) "water fruit"
348: }
349: int(12)
350: bool(false)
351:
352: -- Testing fgetcsv() with file opened using w+t mode --
353:
354: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
355: array(1) {
356: [0]=>
357: string(11) "water fruit"
358: }
359: int(12)
360: bool(false)
361:
362: -- Testing fgetcsv() with file opened using x+ mode --
363:
364: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
365: array(1) {
366: [0]=>
367: string(11) "water fruit"
368: }
369: int(12)
370: bool(false)
371:
372: -- Testing fgetcsv() with file opened using x+b mode --
373:
374: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
375: array(1) {
376: [0]=>
377: string(11) "water fruit"
378: }
379: int(12)
380: bool(false)
381:
382: -- Testing fgetcsv() with file opened using x+t mode --
383:
384: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
385: array(1) {
386: [0]=>
387: string(11) "water fruit"
388: }
389: int(12)
390: bool(false)
391:
392: -- Testing fgetcsv() with file opened using r mode --
393:
394: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
395: array(1) {
396: [0]=>
397: string(13) "water "fruit""
398: }
399: int(16)
400: bool(false)
401:
402: -- Testing fgetcsv() with file opened using rb mode --
403:
404: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
405: array(1) {
406: [0]=>
407: string(13) "water "fruit""
408: }
409: int(16)
410: bool(false)
411:
412: -- Testing fgetcsv() with file opened using rt mode --
413:
414: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
415: array(1) {
416: [0]=>
417: string(13) "water "fruit""
418: }
419: int(16)
420: bool(false)
421:
422: -- Testing fgetcsv() with file opened using r+ mode --
423:
424: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
425: array(1) {
426: [0]=>
427: string(13) "water "fruit""
428: }
429: int(16)
430: bool(false)
431:
432: -- Testing fgetcsv() with file opened using r+b mode --
433:
434: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
435: array(1) {
436: [0]=>
437: string(13) "water "fruit""
438: }
439: int(16)
440: bool(false)
441:
442: -- Testing fgetcsv() with file opened using r+t mode --
443:
444: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
445: array(1) {
446: [0]=>
447: string(13) "water "fruit""
448: }
449: int(16)
450: bool(false)
451:
452: -- Testing fgetcsv() with file opened using a+ mode --
453:
454: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
455: array(1) {
456: [0]=>
457: string(13) "water "fruit""
458: }
459: int(16)
460: bool(false)
461:
462: -- Testing fgetcsv() with file opened using a+b mode --
463:
464: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
465: array(1) {
466: [0]=>
467: string(13) "water "fruit""
468: }
469: int(16)
470: bool(false)
471:
472: -- Testing fgetcsv() with file opened using a+t mode --
473:
474: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
475: array(1) {
476: [0]=>
477: string(13) "water "fruit""
478: }
479: int(16)
480: bool(false)
481:
482: -- Testing fgetcsv() with file opened using w+ mode --
483:
484: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
485: array(1) {
486: [0]=>
487: string(13) "water "fruit""
488: }
489: int(16)
490: bool(false)
491:
492: -- Testing fgetcsv() with file opened using w+b mode --
493:
494: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
495: array(1) {
496: [0]=>
497: string(13) "water "fruit""
498: }
499: int(16)
500: bool(false)
501:
502: -- Testing fgetcsv() with file opened using w+t mode --
503:
504: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
505: array(1) {
506: [0]=>
507: string(13) "water "fruit""
508: }
509: int(16)
510: bool(false)
511:
512: -- Testing fgetcsv() with file opened using x+ mode --
513:
514: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
515: array(1) {
516: [0]=>
517: string(13) "water "fruit""
518: }
519: int(16)
520: bool(false)
521:
522: -- Testing fgetcsv() with file opened using x+b mode --
523:
524: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
525: array(1) {
526: [0]=>
527: string(13) "water "fruit""
528: }
529: int(16)
530: bool(false)
531:
532: -- Testing fgetcsv() with file opened using x+t mode --
533:
534: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
535: array(1) {
536: [0]=>
537: string(13) "water "fruit""
538: }
539: int(16)
540: bool(false)
541:
542: -- Testing fgetcsv() with file opened using r mode --
543:
544: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
545: array(1) {
546: [0]=>
547: string(19) "water\"fruit"\"air""
548: }
549: int(20)
550: bool(false)
551:
552: -- Testing fgetcsv() with file opened using rb mode --
553:
554: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
555: array(1) {
556: [0]=>
557: string(19) "water\"fruit"\"air""
558: }
559: int(20)
560: bool(false)
561:
562: -- Testing fgetcsv() with file opened using rt mode --
563:
564: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
565: array(1) {
566: [0]=>
567: string(19) "water\"fruit"\"air""
568: }
569: int(20)
570: bool(false)
571:
572: -- Testing fgetcsv() with file opened using r+ mode --
573:
574: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
575: array(1) {
576: [0]=>
577: string(19) "water\"fruit"\"air""
578: }
579: int(20)
580: bool(false)
581:
582: -- Testing fgetcsv() with file opened using r+b mode --
583:
584: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
585: array(1) {
586: [0]=>
587: string(19) "water\"fruit"\"air""
588: }
589: int(20)
590: bool(false)
591:
592: -- Testing fgetcsv() with file opened using r+t mode --
593:
594: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
595: array(1) {
596: [0]=>
597: string(19) "water\"fruit"\"air""
598: }
599: int(20)
600: bool(false)
601:
602: -- Testing fgetcsv() with file opened using a+ mode --
603:
604: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
605: array(1) {
606: [0]=>
607: string(19) "water\"fruit"\"air""
608: }
609: int(20)
610: bool(false)
611:
612: -- Testing fgetcsv() with file opened using a+b mode --
613:
614: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
615: array(1) {
616: [0]=>
617: string(19) "water\"fruit"\"air""
618: }
619: int(20)
620: bool(false)
621:
622: -- Testing fgetcsv() with file opened using a+t mode --
623:
624: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
625: array(1) {
626: [0]=>
627: string(19) "water\"fruit"\"air""
628: }
629: int(20)
630: bool(false)
631:
632: -- Testing fgetcsv() with file opened using w+ mode --
633:
634: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
635: array(1) {
636: [0]=>
637: string(19) "water\"fruit"\"air""
638: }
639: int(20)
640: bool(false)
641:
642: -- Testing fgetcsv() with file opened using w+b mode --
643:
644: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
645: array(1) {
646: [0]=>
647: string(19) "water\"fruit"\"air""
648: }
649: int(20)
650: bool(false)
651:
652: -- Testing fgetcsv() with file opened using w+t mode --
653:
654: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
655: array(1) {
656: [0]=>
657: string(19) "water\"fruit"\"air""
658: }
659: int(20)
660: bool(false)
661:
662: -- Testing fgetcsv() with file opened using x+ mode --
663:
664: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
665: array(1) {
666: [0]=>
667: string(19) "water\"fruit"\"air""
668: }
669: int(20)
670: bool(false)
671:
672: -- Testing fgetcsv() with file opened using x+b mode --
673:
674: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
675: array(1) {
676: [0]=>
677: string(19) "water\"fruit"\"air""
678: }
679: int(20)
680: bool(false)
681:
682: -- Testing fgetcsv() with file opened using x+t mode --
683:
684: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
685: array(1) {
686: [0]=>
687: string(19) "water\"fruit"\"air""
688: }
689: int(20)
690: bool(false)
691:
692: -- Testing fgetcsv() with file opened using r mode --
693:
694: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
695: array(1) {
696: [0]=>
697: string(17) "water\"fruit"\""""
698: }
699: int(20)
700: bool(false)
701:
702: -- Testing fgetcsv() with file opened using rb mode --
703:
704: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
705: array(1) {
706: [0]=>
707: string(17) "water\"fruit"\""""
708: }
709: int(20)
710: bool(false)
711:
712: -- Testing fgetcsv() with file opened using rt mode --
713:
714: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
715: array(1) {
716: [0]=>
717: string(17) "water\"fruit"\""""
718: }
719: int(20)
720: bool(false)
721:
722: -- Testing fgetcsv() with file opened using r+ mode --
723:
724: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
725: array(1) {
726: [0]=>
727: string(17) "water\"fruit"\""""
728: }
729: int(20)
730: bool(false)
731:
732: -- Testing fgetcsv() with file opened using r+b mode --
733:
734: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
735: array(1) {
736: [0]=>
737: string(17) "water\"fruit"\""""
738: }
739: int(20)
740: bool(false)
741:
742: -- Testing fgetcsv() with file opened using r+t mode --
743:
744: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
745: array(1) {
746: [0]=>
747: string(17) "water\"fruit"\""""
748: }
749: int(20)
750: bool(false)
751:
752: -- Testing fgetcsv() with file opened using a+ mode --
753:
754: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
755: array(1) {
756: [0]=>
757: string(17) "water\"fruit"\""""
758: }
759: int(20)
760: bool(false)
761:
762: -- Testing fgetcsv() with file opened using a+b mode --
763:
764: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
765: array(1) {
766: [0]=>
767: string(17) "water\"fruit"\""""
768: }
769: int(20)
770: bool(false)
771:
772: -- Testing fgetcsv() with file opened using a+t mode --
773:
774: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
775: array(1) {
776: [0]=>
777: string(17) "water\"fruit"\""""
778: }
779: int(20)
780: bool(false)
781:
782: -- Testing fgetcsv() with file opened using w+ mode --
783:
784: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
785: array(1) {
786: [0]=>
787: string(17) "water\"fruit"\""""
788: }
789: int(20)
790: bool(false)
791:
792: -- Testing fgetcsv() with file opened using w+b mode --
793:
794: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
795: array(1) {
796: [0]=>
797: string(17) "water\"fruit"\""""
798: }
799: int(20)
800: bool(false)
801:
802: -- Testing fgetcsv() with file opened using w+t mode --
803:
804: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
805: array(1) {
806: [0]=>
807: string(17) "water\"fruit"\""""
808: }
809: int(20)
810: bool(false)
811:
812: -- Testing fgetcsv() with file opened using x+ mode --
813:
814: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
815: array(1) {
816: [0]=>
817: string(17) "water\"fruit"\""""
818: }
819: int(20)
820: bool(false)
821:
822: -- Testing fgetcsv() with file opened using x+b mode --
823:
824: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
825: array(1) {
826: [0]=>
827: string(17) "water\"fruit"\""""
828: }
829: int(20)
830: bool(false)
831:
832: -- Testing fgetcsv() with file opened using x+t mode --
833:
834: Notice: fgetcsv(): delimiter must be a single character in %s on line %d
835: array(1) {
836: [0]=>
837: string(17) "water\"fruit"\""""
838: }
839: int(20)
840: bool(false)
841: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>