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