2017-04-03 02:52:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader;
|
|
|
|
|
2017-12-17 07:34:40 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Csv;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-04-03 02:52:35 +00:00
|
|
|
|
2017-11-08 15:48:01 +00:00
|
|
|
class CsvTest extends TestCase
|
2017-04-03 02:52:35 +00:00
|
|
|
{
|
2017-12-28 03:22:01 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerDelimiterDetection
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
* @param string $expectedDelimiter
|
|
|
|
* @param string $cell
|
|
|
|
* @param float|int|string $expectedValue
|
|
|
|
*/
|
|
|
|
public function testDelimiterDetection($filename, $expectedDelimiter, $cell, $expectedValue)
|
2017-04-17 16:51:53 +00:00
|
|
|
{
|
2017-12-17 07:34:40 +00:00
|
|
|
$reader = new Csv();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertNull($reader->getDelimiter());
|
2017-04-17 16:51:53 +00:00
|
|
|
|
|
|
|
$spreadsheet = $reader->load($filename);
|
|
|
|
|
2017-12-28 03:22:01 +00:00
|
|
|
self::assertSame($expectedDelimiter, $reader->getDelimiter(), 'should be able to infer the delimiter');
|
2017-04-17 16:51:53 +00:00
|
|
|
|
2017-12-28 03:22:01 +00:00
|
|
|
$actual = $spreadsheet->getActiveSheet()->getCell($cell)->getValue();
|
|
|
|
self::assertSame($expectedValue, $actual, 'should be able to retrieve correct value');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerDelimiterDetection()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
__DIR__ . '/../../data/Reader/CSV/enclosure.csv',
|
|
|
|
',',
|
|
|
|
'C4',
|
|
|
|
'username2',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
__DIR__ . '/../../data/Reader/CSV/semicolon_separated.csv',
|
|
|
|
';',
|
|
|
|
'C2',
|
|
|
|
'25,5',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
__DIR__ . '/../../data/Reader/HTML/csv_with_angle_bracket.csv',
|
|
|
|
',',
|
|
|
|
'B1',
|
|
|
|
'Number of items with weight <= 50kg',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
__DIR__ . '/../../../samples/Reader/sampleData/example1.csv',
|
|
|
|
',',
|
|
|
|
'I4',
|
|
|
|
'100%',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
__DIR__ . '/../../../samples/Reader/sampleData/example2.csv',
|
|
|
|
',',
|
|
|
|
'D8',
|
|
|
|
-58.373161,
|
|
|
|
],
|
|
|
|
];
|
2017-04-17 16:51:53 +00:00
|
|
|
}
|
2017-04-03 02:52:35 +00:00
|
|
|
}
|