class ParagraphsTest

Same name in this branch
  1. 8.x-1.x paragraphs/tests/src/Functional/Feeds/Target/ParagraphsTest.php \Drupal\Tests\paragraphs\Functional\Feeds\Target\ParagraphsTest
  2. 8.x-1.x paragraphs/tests/src/Kernel/Feeds/Target/ParagraphsTest.php \Drupal\Tests\paragraphs\Kernel\Feeds\Target\ParagraphsTest

Tests the FeedsTarget plugin "paragraphs" in the UI.

@group paragraphs

Hierarchy

Expanded class hierarchy of ParagraphsTest

File

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

Namespace

Drupal\Tests\paragraphs\Functional\Feeds\Target
View source
class ParagraphsTest extends FeedsBrowserTestBase {
  use ParagraphsTestBaseTrait;

  /**
   * Modules to enable.
   *
   * @var string[]
   */
  protected static $modules = [
    'feeds',
    'node',
    'paragraphs',
  ];

  /**
   * The feed type entity.
   *
   * @var \Drupal\feeds\Entity\FeedType
   */
  protected $feedType;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();

    // Add a Paragraph field to the article content type.
    $this
      ->addParagraphsField('article', 'field_paragraphs', 'node');
    $this
      ->addParagraphsType('test_paragraph');
    $this
      ->addFieldtoParagraphType('test_paragraph', 'field_text', 'text');

    // Create a feed type.
    $this->feedType = $this
      ->createFeedType();
  }

  /**
   * Tests adding mapping to a paragraph field.
   */
  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]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsTest::$feedType protected property The feed type entity.
ParagraphsTest::$modules protected static property Modules to enable.
ParagraphsTest::setUp public function
ParagraphsTest::testAddMapping public function Tests adding mapping to a paragraph field.
ParagraphsTestBaseTrait::$workflow protected property The workflow entity.
ParagraphsTestBaseTrait::addFieldtoParagraphType protected function Adds a field to a given paragraph type.
ParagraphsTestBaseTrait::addParagraphedContentType protected function Adds a content type with a Paragraphs field.
ParagraphsTestBaseTrait::addParagraphsField protected function Adds a Paragraphs field to a given entity type.
ParagraphsTestBaseTrait::addParagraphsType protected function Adds a Paragraphs type.
ParagraphsTestBaseTrait::addParagraphsTypeIcon protected function Adds an icon to a paragraphs type.
ParagraphsTestBaseTrait::coreVersion protected function Checks the core version.
ParagraphsTestBaseTrait::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.