File:
[ELWIX - Embedded LightWeight unIX -] /
embedaddon /
php /
ext /
spl /
tests /
SplFileObject_fputcsv.phpt
Revision
1.1.1.1 (vendor branch):
download - view:
text,
annotated -
select for diffs -
revision graph
Tue May 29 12:34:43 2012 UTC (12 years, 2 months ago) by
misho
Branches:
php,
MAIN
CVS tags:
v5_4_3elwix,
v5_4_29p0,
v5_4_29,
v5_4_20p0,
v5_4_20,
v5_4_17p0,
v5_4_17,
HEAD
php 5.4.3+patches
--TEST--
SplFileObject::fputcsv(): functionality tests
--FILE--
<?php
$file = __DIR__ . '/SplFileObject_fputcsv.csv';
$fo = new SplFileObject($file, 'w');
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"bbb"',
2 => '"aaa","bbb"',
3 => 'aaa,bbb',
4 => '"aaa",bbb',
5 => '"aaa", "bbb"',
6 => ',',
7 => 'aaa,',
8 => ',"aaa"',
9 => '"",""',
10 => '"""""",',
11 => '""""",aaa',
12 => 'aaa,bbb ',
13 => 'aaa,"bbb "',
14 => 'aaa"aaa","bbb"bbb',
15 => 'aaa"aaa""",bbb',
16 => 'aaa,"\\"bbb,ccc',
17 => 'aaa"\\"a","bbb"',
18 => '"\\"","aaa"',
19 => '"\\""",aaa',
);
foreach ($list as $v) {
$fo->fputcsv(explode(',', $v));
}
unset($fo);
$res = file($file);
foreach($res as &$val)
{
$val = substr($val, 0, -1);
}
echo '$list = ';var_export($res);echo ";\n";
$fp = fopen($file, "r");
$res = array();
while($l=fgetcsv($fp))
{
$res[] = join(',',$l);
}
fclose($fp);
echo '$list = ';var_export($res);echo ";\n";
?>
===DONE===
<?php exit(0); ?>
--CLEAN--
<?php
$file = __DIR__ . '/SplFileObject_fputcsv.csv';
unlink($file);
?>
--EXPECT--
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"""bbb"""',
2 => '"""aaa""","""bbb"""',
3 => 'aaa,bbb',
4 => '"""aaa""",bbb',
5 => '"""aaa"""," ""bbb"""',
6 => ',',
7 => 'aaa,',
8 => ',"""aaa"""',
9 => '"""""",""""""',
10 => '"""""""""""""",',
11 => '"""""""""""",aaa',
12 => 'aaa,"bbb "',
13 => 'aaa,"""bbb """',
14 => '"aaa""aaa""","""bbb""bbb"',
15 => '"aaa""aaa""""""",bbb',
16 => 'aaa,"""\\"bbb",ccc',
17 => '"aaa""\\"a""","""bbb"""',
18 => '"""\\"""","""aaa"""',
19 => '"""\\"""""",aaa',
);
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"bbb"',
2 => '"aaa","bbb"',
3 => 'aaa,bbb',
4 => '"aaa",bbb',
5 => '"aaa", "bbb"',
6 => ',',
7 => 'aaa,',
8 => ',"aaa"',
9 => '"",""',
10 => '"""""",',
11 => '""""",aaa',
12 => 'aaa,bbb ',
13 => 'aaa,"bbb "',
14 => 'aaa"aaa","bbb"bbb',
15 => 'aaa"aaa""",bbb',
16 => 'aaa,"\\"bbb,ccc',
17 => 'aaa"\\"a","bbb"',
18 => '"\\"","aaa"',
19 => '"\\""",aaa',
);
===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>