<?php
namespace Drupal\Tests\paragraphs\Functional\Feeds\Target;
use Drupal\Tests\feeds\Functional\FeedsBrowserTestBase;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
class ParagraphsTest extends FeedsBrowserTestBase {
use ParagraphsTestBaseTrait;
protected static $modules = [
'feeds',
'node',
'paragraphs',
];
protected $feedType;
public function setUp() : void {
parent::setUp();
$this
->addParagraphsField('article', 'field_paragraphs', 'node');
$this
->addParagraphsType('test_paragraph');
$this
->addFieldtoParagraphType('test_paragraph', 'field_text', 'text');
$this->feedType = $this
->createFeedType();
}
public function testAddMapping() {
$this
->drupalGet('admin/structure/feeds/manage/' . $this->feedType
->id() . '/mapping');
$edit = [
'add_target' => 'field_paragraphs',
];
$this
->submitForm($edit, 'Save');
$edit = [];
$this
->submitForm($edit, 'target-settings-2');
$edit = [
'mappings[2][settings][paragraphs_type]' => 'test_paragraph',
];
$this
->submitForm($edit, 'target-save-2');
$edit = [];
$this
->submitForm($edit, 'target-settings-2');
$edit = [
'mappings[2][settings][paragraph_field]' => 'field_text',
];
$this
->submitForm($edit, 'target-save-2');
$edit = [
'mappings[2][map][value][select]' => 'content',
];
$this
->submitForm($edit, 'Save');
$this->feedType = $this
->reloadEntity($this->feedType);
$saved_mappings = $this->feedType
->getMappings();
$expected_mapping = [
'target' => 'field_paragraphs',
'map' => [
'value' => 'content',
],
'settings' => [
'paragraphs_type' => 'test_paragraph',
'paragraph_field' => 'field_text',
'language' => '',
'format' => 'plain_text',
],
];
$this
->assertEquals($expected_mapping, $saved_mappings[2]);
}
}