Annotation of embedaddon/php/ext/spl/tests/SplFileObject_fputcsv_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fputcsv() : usage variations - with different delimiter and same enclosure
3: --FILE--
4: <?php
5:
6: /*
7: Testing fputcsv() to write to a file when enclosure is same but delimiter is different from those
8: present in the field to be written to the file
9: */
10:
11: echo "*** Testing fputcsv() : with different delimiter and same 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_variation7.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, '+', $enclosure) );
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 same 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(20)
159: int(20)
160: bool(false)
161: string(20) """"water"",""fruit"
162: "
163:
164: -- file opened in r+b --
165: int(20)
166: int(20)
167: bool(false)
168: string(20) """"water"",""fruit"
169: "
170:
171: -- file opened in r+t --
172: int(20)
173: int(20)
174: bool(false)
175: string(%d) """"water"",""fruit"
176: "
177:
178: -- file opened in a+ --
179: int(20)
180: int(20)
181: bool(false)
182: string(20) """"water"",""fruit"
183: "
184:
185: -- file opened in a+b --
186: int(20)
187: int(20)
188: bool(false)
189: string(20) """"water"",""fruit"
190: "
191:
192: -- file opened in a+t --
193: int(20)
194: int(20)
195: bool(false)
196: string(%d) """"water"",""fruit"
197: "
198:
199: -- file opened in w+ --
200: int(20)
201: int(20)
202: bool(false)
203: string(20) """"water"",""fruit"
204: "
205:
206: -- file opened in w+b --
207: int(20)
208: int(20)
209: bool(false)
210: string(20) """"water"",""fruit"
211: "
212:
213: -- file opened in w+t --
214: int(20)
215: int(20)
216: bool(false)
217: string(%d) """"water"",""fruit"
218: "
219:
220: -- file opened in x+ --
221: int(20)
222: int(20)
223: bool(false)
224: string(20) """"water"",""fruit"
225: "
226:
227: -- file opened in x+b --
228: int(20)
229: int(20)
230: bool(false)
231: string(20) """"water"",""fruit"
232: "
233:
234: -- file opened in x+t --
235: int(20)
236: int(20)
237: bool(false)
238: string(%d) """"water"",""fruit"
239: "
240:
241: -- file opened in r+ --
242: int(22)
243: int(22)
244: bool(false)
245: string(22) """"water"",""fruit"""
246: "
247:
248: -- file opened in r+b --
249: int(22)
250: int(22)
251: bool(false)
252: string(22) """"water"",""fruit"""
253: "
254:
255: -- file opened in r+t --
256: int(22)
257: int(22)
258: bool(false)
259: string(%d) """"water"",""fruit"""
260: "
261:
262: -- file opened in a+ --
263: int(22)
264: int(22)
265: bool(false)
266: string(22) """"water"",""fruit"""
267: "
268:
269: -- file opened in a+b --
270: int(22)
271: int(22)
272: bool(false)
273: string(22) """"water"",""fruit"""
274: "
275:
276: -- file opened in a+t --
277: int(22)
278: int(22)
279: bool(false)
280: string(%d) """"water"",""fruit"""
281: "
282:
283: -- file opened in w+ --
284: int(22)
285: int(22)
286: bool(false)
287: string(22) """"water"",""fruit"""
288: "
289:
290: -- file opened in w+b --
291: int(22)
292: int(22)
293: bool(false)
294: string(22) """"water"",""fruit"""
295: "
296:
297: -- file opened in w+t --
298: int(22)
299: int(22)
300: bool(false)
301: string(%d) """"water"",""fruit"""
302: "
303:
304: -- file opened in x+ --
305: int(22)
306: int(22)
307: bool(false)
308: string(22) """"water"",""fruit"""
309: "
310:
311: -- file opened in x+b --
312: int(22)
313: int(22)
314: bool(false)
315: string(22) """"water"",""fruit"""
316: "
317:
318: -- file opened in x+t --
319: int(22)
320: int(22)
321: bool(false)
322: string(%d) """"water"",""fruit"""
323: "
324:
325: -- file opened in r+ --
326: int(22)
327: int(22)
328: bool(false)
329: string(22) "^^^water^^ ^^fruit^^^
330: "
331:
332: -- file opened in r+b --
333: int(22)
334: int(22)
335: bool(false)
336: string(22) "^^^water^^ ^^fruit^^^
337: "
338:
339: -- file opened in r+t --
340: int(22)
341: int(22)
342: bool(false)
343: string(%d) "^^^water^^ ^^fruit^^^
344: "
345:
346: -- file opened in a+ --
347: int(22)
348: int(22)
349: bool(false)
350: string(22) "^^^water^^ ^^fruit^^^
351: "
352:
353: -- file opened in a+b --
354: int(22)
355: int(22)
356: bool(false)
357: string(22) "^^^water^^ ^^fruit^^^
358: "
359:
360: -- file opened in a+t --
361: int(22)
362: int(22)
363: bool(false)
364: string(%d) "^^^water^^ ^^fruit^^^
365: "
366:
367: -- file opened in w+ --
368: int(22)
369: int(22)
370: bool(false)
371: string(22) "^^^water^^ ^^fruit^^^
372: "
373:
374: -- file opened in w+b --
375: int(22)
376: int(22)
377: bool(false)
378: string(22) "^^^water^^ ^^fruit^^^
379: "
380:
381: -- file opened in w+t --
382: int(22)
383: int(22)
384: bool(false)
385: string(%d) "^^^water^^ ^^fruit^^^
386: "
387:
388: -- file opened in x+ --
389: int(22)
390: int(22)
391: bool(false)
392: string(22) "^^^water^^ ^^fruit^^^
393: "
394:
395: -- file opened in x+b --
396: int(22)
397: int(22)
398: bool(false)
399: string(22) "^^^water^^ ^^fruit^^^
400: "
401:
402: -- file opened in x+t --
403: int(22)
404: int(22)
405: bool(false)
406: string(%d) "^^^water^^ ^^fruit^^^
407: "
408:
409: -- file opened in r+ --
410: int(22)
411: int(22)
412: bool(false)
413: string(22) "&&&water&&:&&fruit&&&
414: "
415:
416: -- file opened in r+b --
417: int(22)
418: int(22)
419: bool(false)
420: string(22) "&&&water&&:&&fruit&&&
421: "
422:
423: -- file opened in r+t --
424: int(22)
425: int(22)
426: bool(false)
427: string(%d) "&&&water&&:&&fruit&&&
428: "
429:
430: -- file opened in a+ --
431: int(22)
432: int(22)
433: bool(false)
434: string(22) "&&&water&&:&&fruit&&&
435: "
436:
437: -- file opened in a+b --
438: int(22)
439: int(22)
440: bool(false)
441: string(22) "&&&water&&:&&fruit&&&
442: "
443:
444: -- file opened in a+t --
445: int(22)
446: int(22)
447: bool(false)
448: string(%d) "&&&water&&:&&fruit&&&
449: "
450:
451: -- file opened in w+ --
452: int(22)
453: int(22)
454: bool(false)
455: string(22) "&&&water&&:&&fruit&&&
456: "
457:
458: -- file opened in w+b --
459: int(22)
460: int(22)
461: bool(false)
462: string(22) "&&&water&&:&&fruit&&&
463: "
464:
465: -- file opened in w+t --
466: int(22)
467: int(22)
468: bool(false)
469: string(%d) "&&&water&&:&&fruit&&&
470: "
471:
472: -- file opened in x+ --
473: int(22)
474: int(22)
475: bool(false)
476: string(22) "&&&water&&:&&fruit&&&
477: "
478:
479: -- file opened in x+b --
480: int(22)
481: int(22)
482: bool(false)
483: string(22) "&&&water&&:&&fruit&&&
484: "
485:
486: -- file opened in x+t --
487: int(22)
488: int(22)
489: bool(false)
490: string(%d) "&&&water&&:&&fruit&&&
491: "
492:
493: -- file opened in r+ --
494: int(23)
495: int(23)
496: bool(false)
497: string(23) "===water======fruit===
498: "
499:
500: -- file opened in r+b --
501: int(23)
502: int(23)
503: bool(false)
504: string(23) "===water======fruit===
505: "
506:
507: -- file opened in r+t --
508: int(23)
509: int(23)
510: bool(false)
511: string(%d) "===water======fruit===
512: "
513:
514: -- file opened in a+ --
515: int(23)
516: int(23)
517: bool(false)
518: string(23) "===water======fruit===
519: "
520:
521: -- file opened in a+b --
522: int(23)
523: int(23)
524: bool(false)
525: string(23) "===water======fruit===
526: "
527:
528: -- file opened in a+t --
529: int(23)
530: int(23)
531: bool(false)
532: string(%d) "===water======fruit===
533: "
534:
535: -- file opened in w+ --
536: int(23)
537: int(23)
538: bool(false)
539: string(23) "===water======fruit===
540: "
541:
542: -- file opened in w+b --
543: int(23)
544: int(23)
545: bool(false)
546: string(23) "===water======fruit===
547: "
548:
549: -- file opened in w+t --
550: int(23)
551: int(23)
552: bool(false)
553: string(%d) "===water======fruit===
554: "
555:
556: -- file opened in x+ --
557: int(23)
558: int(23)
559: bool(false)
560: string(23) "===water======fruit===
561: "
562:
563: -- file opened in x+b --
564: int(23)
565: int(23)
566: bool(false)
567: string(23) "===water======fruit===
568: "
569:
570: -- file opened in x+t --
571: int(23)
572: int(23)
573: bool(false)
574: string(%d) "===water======fruit===
575: "
576:
577: -- file opened in r+ --
578: int(24)
579: int(24)
580: bool(false)
581: string(24) "---water----fruit--air-
582: "
583:
584: -- file opened in r+b --
585: int(24)
586: int(24)
587: bool(false)
588: string(24) "---water----fruit--air-
589: "
590:
591: -- file opened in r+t --
592: int(24)
593: int(24)
594: bool(false)
595: string(%d) "---water----fruit--air-
596: "
597:
598: -- file opened in a+ --
599: int(24)
600: int(24)
601: bool(false)
602: string(24) "---water----fruit--air-
603: "
604:
605: -- file opened in a+b --
606: int(24)
607: int(24)
608: bool(false)
609: string(24) "---water----fruit--air-
610: "
611:
612: -- file opened in a+t --
613: int(24)
614: int(24)
615: bool(false)
616: string(%d) "---water----fruit--air-
617: "
618:
619: -- file opened in w+ --
620: int(24)
621: int(24)
622: bool(false)
623: string(24) "---water----fruit--air-
624: "
625:
626: -- file opened in w+b --
627: int(24)
628: int(24)
629: bool(false)
630: string(24) "---water----fruit--air-
631: "
632:
633: -- file opened in w+t --
634: int(24)
635: int(24)
636: bool(false)
637: string(%d) "---water----fruit--air-
638: "
639:
640: -- file opened in x+ --
641: int(24)
642: int(24)
643: bool(false)
644: string(24) "---water----fruit--air-
645: "
646:
647: -- file opened in x+b --
648: int(24)
649: int(24)
650: bool(false)
651: string(24) "---water----fruit--air-
652: "
653:
654: -- file opened in x+t --
655: int(24)
656: int(24)
657: bool(false)
658: string(%d) "---water----fruit--air-
659: "
660:
661: -- file opened in r+ --
662: int(32)
663: int(32)
664: bool(false)
665: string(32) "---water------fruit------air---
666: "
667:
668: -- file opened in r+b --
669: int(32)
670: int(32)
671: bool(false)
672: string(32) "---water------fruit------air---
673: "
674:
675: -- file opened in r+t --
676: int(32)
677: int(32)
678: bool(false)
679: string(%d) "---water------fruit------air---
680: "
681:
682: -- file opened in a+ --
683: int(32)
684: int(32)
685: bool(false)
686: string(32) "---water------fruit------air---
687: "
688:
689: -- file opened in a+b --
690: int(32)
691: int(32)
692: bool(false)
693: string(32) "---water------fruit------air---
694: "
695:
696: -- file opened in a+t --
697: int(32)
698: int(32)
699: bool(false)
700: string(%d) "---water------fruit------air---
701: "
702:
703: -- file opened in w+ --
704: int(32)
705: int(32)
706: bool(false)
707: string(32) "---water------fruit------air---
708: "
709:
710: -- file opened in w+b --
711: int(32)
712: int(32)
713: bool(false)
714: string(32) "---water------fruit------air---
715: "
716:
717: -- file opened in w+t --
718: int(32)
719: int(32)
720: bool(false)
721: string(%d) "---water------fruit------air---
722: "
723:
724: -- file opened in x+ --
725: int(32)
726: int(32)
727: bool(false)
728: string(32) "---water------fruit------air---
729: "
730:
731: -- file opened in x+b --
732: int(32)
733: int(32)
734: bool(false)
735: string(32) "---water------fruit------air---
736: "
737:
738: -- file opened in x+t --
739: int(32)
740: int(32)
741: bool(false)
742: string(%d) "---water------fruit------air---
743: "
744:
745: -- file opened in r+ --
746: int(32)
747: int(32)
748: bool(false)
749: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
750: "
751:
752: -- file opened in r+b --
753: int(32)
754: int(32)
755: bool(false)
756: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
757: "
758:
759: -- file opened in r+t --
760: int(32)
761: int(32)
762: bool(false)
763: string(%d) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
764: "
765:
766: -- file opened in a+ --
767: int(32)
768: int(32)
769: bool(false)
770: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
771: "
772:
773: -- file opened in a+b --
774: int(32)
775: int(32)
776: bool(false)
777: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
778: "
779:
780: -- file opened in a+t --
781: int(32)
782: int(32)
783: bool(false)
784: string(%d) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
785: "
786:
787: -- file opened in w+ --
788: int(32)
789: int(32)
790: bool(false)
791: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
792: "
793:
794: -- file opened in w+b --
795: int(32)
796: int(32)
797: bool(false)
798: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
799: "
800:
801: -- file opened in w+t --
802: int(32)
803: int(32)
804: bool(false)
805: string(%d) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
806: "
807:
808: -- file opened in x+ --
809: int(32)
810: int(32)
811: bool(false)
812: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
813: "
814:
815: -- file opened in x+b --
816: int(32)
817: int(32)
818: bool(false)
819: string(32) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
820: "
821:
822: -- file opened in x+t --
823: int(32)
824: int(32)
825: bool(false)
826: string(%d) "&&&""""&&:&&"&&:,:":&&,&&:,,,,&
827: "
828: Done
829:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>