You are here

public function JsonPathParserTest::testBatchParsing in Feeds extensible parsers 8

Tests batch parsing.

File

tests/src/Unit/Feeds/Parser/JsonPathParserTest.php, line 78

Class

JsonPathParserTest
@coversDefaultClass \Drupal\feeds_ex\Feeds\Parser\JsonPathParser @group feeds_ex

Namespace

Drupal\Tests\feeds_ex\Unit\Feeds\Parser

Code

public function testBatchParsing() {
  $fetcher_result = new RawFetcherResult(file_get_contents($this->moduleDir . '/tests/resources/test.json'), $this->fileSystem);
  $config = [
    'context' => [
      'value' => '$.items.*',
    ],
    'sources' => [
      'title' => [
        'name' => 'Title',
        'value' => 'title',
      ],
      'description' => [
        'name' => 'Title',
        'value' => 'description',
      ],
    ],
    'line_limit' => 1,
  ] + $this->parser
    ->defaultConfiguration();
  $this->parser
    ->setConfiguration($config);
  foreach (range(0, 2) as $delta) {
    $result = $this->parser
      ->parse($this->feed, $fetcher_result, $this->state);
    $this
      ->assertCount(1, $result);
    $this
      ->assertSame('I am a title' . $delta, $result[0]
      ->get('title'));
    $this
      ->assertSame('I am a description' . $delta, $result[0]
      ->get('description'));
  }

  // We should be out of items.
  $result = $this->parser
    ->parse($this->feed, $fetcher_result, $this->state);
  $this
    ->assertCount(0, $result);
}