diff --git a/test/core/CSVParserTest.php b/test/core/CSVParserTest.php new file mode 100644 index 000000000..5c232b0d0 --- /dev/null +++ b/test/core/CSVParserTest.php @@ -0,0 +1,68 @@ + + ? a ? ; ? b ? ; ? c ? + a ; b ; c +??;??;?? +;; +?a"?;?b?;?c? +?a1 +a2?;?b?;?c? +?a1,a2?;?b?;?c? +?a?;?b?;?c1,",c2 +,c3? +?a?;?b?;?ouf !? + spaces trimmed out ; 1234; mac@enroe.com '; + + $aExpectedResult = array( + array('line 0, col 0', 'line 0, col 1', 'line 0, col 2'), + array('a', 'b', 'c'), + array('a', 'b', null), + array(' a ', ' b ', ' c '), + array('a', 'b', 'c'), + array('', '', ''), + array('', '', ''), + array('a"', 'b', 'c'), + array("a1\na2", 'b', 'c'), + array('a1,a2', 'b', 'c'), + array('a', 'b', "c1,\",c2\n,c3"), + array('a', 'b', 'ouf !'), + array('spaces trimmed out', '1234', 'mac@enroe.com'), + ); + + $oCSVParser = new CSVParser($sDataFile, $sSeparator, $sDelimiter); + $aData = $oCSVParser->ToArray(1, null, 0); + + foreach ($aData as $iRow => $aRow) + { + foreach ($aRow as $iCol => $cellValue) + { + $this->assertSame($aExpectedResult[$iRow][$iCol], $cellValue, "Line $iRow, Column $iCol"); + } + } + } +} + diff --git a/test/testlist.inc.php b/test/testlist.inc.php index 0a8bfed61..fd53907fe 100644 --- a/test/testlist.inc.php +++ b/test/testlist.inc.php @@ -123,87 +123,6 @@ class TestSQLQuery extends TestScenarioOnDB } } -class TestCSVParser extends TestFunction -{ - static public function GetName() {return 'Check CSV parsing';} - static public function GetDescription() {return 'Loads a set of CSV data';} - - public function DoExecute() - { - $sDataFile = '?field1?;?field2?;?field3? -?a?;?b?;?c? -a;b;c - ? a ? ; ? b ? ; ? c ? - a ; b ; c -??;??;?? -;; -?a"?;?b?;?c? -?a1 -a2?;?b?;?c? -?a1,a2?;?b?;?c? -?a?;?b?;?c1,",c2 -,c3? -?a?;?b?;?ouf !? - Espace sur la fin ; 1234; e@taloc.com '; - - self::DumpVariable($sDataFile); - - $aExpectedResult = array( - //array('field1', 'field2', 'field3'), - array('a', 'b', 'c'), - array('a', 'b', 'c'), - array(' a ', ' b ', ' c '), - array('a', 'b', 'c'), - array('', '', ''), - array('', '', ''), - array('a"', 'b', 'c'), - array("a1\na2", 'b', 'c'), - array('a1,a2', 'b', 'c'), - array('a', 'b', "c1,\",c2\n,c3"), - array('a', 'b', 'ouf !'), - array('Espace sur la fin', '1234', 'e@taloc.com'), - ); - - $oCSVParser = new CSVParser($sDataFile, ';', '?'); - $aData = $oCSVParser->ToArray(1, null, 0); - - $iIssues = 0; - - echo "
$sCellValue | ";
- }
- echo "