public function ParagraphsTest::testImportParagraph

Tests importing from a timestamp.

File

paragraphs/tests/src/Kernel/Feeds/Target/ParagraphsTest.php, line 67

Class

ParagraphsTest
@coversDefaultClass \Drupal\paragraphs\Feeds\Target\Paragraphs @group paragraphs

Namespace

Drupal\Tests\paragraphs\Kernel\Feeds\Target

Code

public function testImportParagraph() {
  $this->feedType
    ->addMapping([
    'target' => 'field_paragraphs',
    'map' => [
      'value' => 'alpha',
    ],
    'settings' => [
      'paragraphs_type' => 'test_paragraph',
      'paragraph_field' => 'field_text',
      'language' => '',
      'format' => 'plain_text',
    ],
  ]);
  $this->feedType
    ->save();

  // Import.
  $feed = $this
    ->createFeed($this->feedType
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/content.csv',
  ]);
  $feed
    ->import();

  // Assert two created nodes with paragraphs.
  $this
    ->assertNodeCount(2);
  $expected = [
    1 => 'Lorem',
    2 => 'Ut wisi',
  ];
  foreach ($expected as $nid => $value) {

    // Load the node and then the paragraph.
    $node = Node::load($nid);
    $paragraph = Paragraph::load($node->field_paragraphs->target_id);
    $this
      ->assertEquals($value, $paragraph->field_text->value);
  }
}