You are here

public function JsonPathParserTest::testRootContext in Feeds extensible parsers 8

Tests parsing with a root object.

File

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

Class

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

Namespace

Drupal\Tests\feeds_ex\Unit\Feeds\Parser

Code

public function testRootContext() {
  $fetcher_result = new RawFetcherResult(file_get_contents($this->moduleDir . '/tests/resources/test.json'), $this->fileSystem);
  $config = [
    'context' => [
      'value' => '.',
    ],
    'sources' => [
      'title' => [
        'name' => 'Title',
        'value' => 'items[0].title',
      ],
    ],
  ] + $this->parser
    ->defaultConfiguration();
  $this->parser
    ->setConfiguration($config);
  $result = $this->parser
    ->parse($this->feed, $fetcher_result, $this->state);
  $this
    ->assertCount(1, $result);
  $this
    ->assertEquals('I am a title0', $result[0]
    ->get('title'));
}