public function ParagraphsTest::testAddMapping

Tests adding mapping to a paragraph field.

File

paragraphs/tests/src/Functional/Feeds/Target/ParagraphsTest.php, line 54

Class

ParagraphsTest
Tests the FeedsTarget plugin "paragraphs" in the UI.

Namespace

Drupal\Tests\paragraphs\Functional\Feeds\Target

Code

public function testAddMapping() {
  $this
    ->drupalGet('admin/structure/feeds/manage/' . $this->feedType
    ->id() . '/mapping');
  $edit = [
    'add_target' => 'field_paragraphs',
  ];
  $this
    ->submitForm($edit, 'Save');

  // And try to configure it.
  $edit = [];
  $this
    ->submitForm($edit, 'target-settings-2');

  // Select paragraphs type.
  $edit = [
    'mappings[2][settings][paragraphs_type]' => 'test_paragraph',
  ];
  $this
    ->submitForm($edit, 'target-save-2');

  // Configure again to select field.
  $edit = [];
  $this
    ->submitForm($edit, 'target-settings-2');

  // Select paragraphs field.
  $edit = [
    'mappings[2][settings][paragraph_field]' => 'field_text',
  ];
  $this
    ->submitForm($edit, 'target-save-2');

  // Set a source and save mappings.
  $edit = [
    'mappings[2][map][value][select]' => 'content',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Assert expected mapping configuration.
  $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]);
}