You are here

public function CsvParserTest::testParse in Feeds 8.3

Tests parsing a CSV file that succeeds.

@covers ::parse

File

tests/src/Unit/Feeds/Parser/CsvParserTest.php, line 72

Class

CsvParserTest
@coversDefaultClass \Drupal\feeds\Feeds\Parser\CsvParser @group feeds

Namespace

Drupal\Tests\feeds\Unit\Feeds\Parser

Code

public function testParse() {
  $this->feedType
    ->method('getMappingSources')
    ->will($this
    ->returnValue([]));
  $this->feed
    ->expects($this
    ->any())
    ->method('getConfigurationFor')
    ->with($this->parser)
    ->will($this
    ->returnValue($this->parser
    ->defaultFeedConfiguration()));
  $file = $this
    ->resourcesPath() . '/csv/example.csv';
  $fetcher_result = new FetcherResult($file);
  $result = $this->parser
    ->parse($this->feed, $fetcher_result, $this->state);
  $this
    ->assertSame(count($result), 3);
  $this
    ->assertSame($result[0]
    ->get('Header A'), '"1"');

  // Parse again. Tests batching.
  $result = $this->parser
    ->parse($this->feed, $fetcher_result, $this->state);
  $this
    ->assertSame(count($result), 3);
  $this
    ->assertSame($result[0]
    ->get('Header B'), "new\r\nline 2");
}