mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
refactor CSV Parser unit tests from the old home-made framework into PHP Unit, and add new test to check that <NULL> is parsed as a real null value
This commit is contained in:
68
test/core/CSVParserTest.php
Normal file
68
test/core/CSVParserTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use CSVParser;
|
||||
|
||||
|
||||
class CSVParserTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once(APPROOT.'core/csvparser.class.inc.php');
|
||||
require_once(APPROOT.'core/coreexception.class.inc.php');
|
||||
}
|
||||
|
||||
public function testFile()
|
||||
{
|
||||
$sSeparator = ';';
|
||||
$sDelimiter = '?';
|
||||
$sDataFile = '?field1?;?field2?;?field3?
|
||||
?line 0, col 0?;?line 0, col 1?;?line 0, col 2?
|
||||
a;b;c
|
||||
a;b;<NULL>
|
||||
? 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user