feeds_ex-8.x-1.0-alpha4/tests/src/Kernel/Feeds/Parser/JsonPathParserTest.php
tests/src/Kernel/Feeds/Parser/JsonPathParserTest.php
<?php namespace Drupal\Tests\feeds_ex\Kernel\Feeds\Parser; use Drupal\node\Entity\Node; use Drupal\Tests\feeds_ex\Kernel\FeedsExKernelTestBase; /** * @coversDefaultClass \Drupal\feeds_ex\Feeds\Parser\JsonPathParser * @group feeds_ex */ class JsonPathParserTest extends FeedsExKernelTestBase { /** * Tests that Blank sources are ignored by the XML parser. */ public function testImportWithBlankSource() { $this->setUpBodyField(); // Create a feed type using the XML parser. $feed_type = $this->createFeedType([ 'fetcher' => 'directory', 'fetcher_configuration' => [ 'allowed_extensions' => 'json', ], 'parser' => 'jsonpath', 'parser_configuration' => [ 'context' => [ 'value' => '$.items.*', ], ], 'custom_sources' => [ 'title' => [ 'label' => 'Title', 'value' => 'title', 'machine_name' => 'title', 'type' => 'json', ], 'description' => [ 'label' => 'Body', 'value' => 'body', 'machine_name' => 'body', 'type' => 'blank', ], ], 'mappings' => [ [ 'target' => 'title', 'map' => ['value' => 'title'], 'unique' => ['value' => TRUE], 'settings' => [ 'language' => NULL, ], ], [ 'target' => 'body', 'map' => ['value' => 'body'], 'settings' => [ 'format' => 'plain_text', 'language' => NULL, ], ], ], ]); // Create a feed and import. $feed = $this->createFeed($feed_type->id(), [ 'source' => $this->resourcesPath() . '/content.json', ]); $feed->import(); // Assert that two nodes are created. $this->assertEquals(2, $feed->getItemCount()); $this->assertNodeCount(2); // Assert that node has a title, but not a body because a custom source was // mapped to that. $node = Node::load(1); $this->assertEquals('Lorem ipsum', $node->title->value); $this->assertTrue($node->body->isEmpty()); } }