public function CsvParserTest::testAlternateLineEnding in Feeds 8.3
Tests parsing a CSV source with several line endings.
@dataProvider provider
File
- tests/
src/ Unit/ Component/ CsvParserTest.php, line 20
Class
- CsvParserTest
- @coversDefaultClass \Drupal\feeds\Component\CsvParser @group feeds
Namespace
Drupal\Tests\feeds\Unit\ComponentCode
public function testAlternateLineEnding(array $expected, $ending) {
$text = file_get_contents(dirname(dirname(dirname(dirname(__DIR__)))) . '/tests/resources/csv/example.csv');
$text = str_replace("\r\n", $ending, $text);
$parser = new \LimitIterator(CsvParser::createFromString($text), 0, 4);
$first = array_slice($expected, 0, 4);
$this
->assertSame(count(iterator_to_array($parser)), 4);
$this
->assertSame(count(iterator_to_array($parser)), 4);
foreach ($parser as $delta => $row) {
$this
->assertSame($first[$delta], $row);
}
// Test second batch.
$last_pos = $parser
->lastLinePos();
$parser = (new \LimitIterator(CsvParser::createFromString($text), 0, 4))
->setStartByte($last_pos);
$second = array_slice($expected, 4);
// // Test that rewinding works as expected.
$this
->assertSame(3, count(iterator_to_array($parser)));
$this
->assertSame(3, count(iterator_to_array($parser)));
foreach ($parser as $delta => $row) {
$this
->assertSame($second[$delta], $row);
}
}