<?php
namespace Drupal\Tests\paragraphs\Kernel\Feeds\Target;
use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Tests\feeds\Kernel\FeedsKernelTestBase;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
class ParagraphsTest extends FeedsKernelTestBase {
use ParagraphsTestBaseTrait;
protected static $modules = [
'field',
'feeds',
'node',
'entity_reference_revisions',
'paragraphs',
'file',
'text',
];
protected $feedType;
public function setUp() : void {
parent::setUp();
$this
->installEntitySchema('paragraph');
$this->feedType = $this
->createFeedTypeForCsv([
'guid' => 'guid',
'title' => 'title',
'alpha' => 'alpha',
]);
$this
->addParagraphsField('article', 'field_paragraphs', 'node');
$this
->addParagraphsType('test_paragraph');
$this
->addFieldtoParagraphType('test_paragraph', 'field_text', 'text');
drupal_flush_all_caches();
}
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();
$feed = $this
->createFeed($this->feedType
->id(), [
'source' => $this
->resourcesPath() . '/csv/content.csv',
]);
$feed
->import();
$this
->assertNodeCount(2);
$expected = [
1 => 'Lorem',
2 => 'Ut wisi',
];
foreach ($expected as $nid => $value) {
$node = Node::load($nid);
$paragraph = Paragraph::load($node->field_paragraphs->target_id);
$this
->assertEquals($value, $paragraph->field_text->value);
}
}
}