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

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

Hierarchy

Expanded class hierarchy of ParagraphsTest

File

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

Namespace

Drupal\Tests\paragraphs\Kernel\Feeds\Target
View source
class ParagraphsTest extends FeedsKernelTestBase {
  use ParagraphsTestBaseTrait;

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

  /**
   * The feed type.
   *
   * @var \Drupal\feeds\FeedTypeInterface
   */
  protected $feedType;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    $this
      ->installEntitySchema('paragraph');

    // Create feed type.
    $this->feedType = $this
      ->createFeedTypeForCsv([
      'guid' => 'guid',
      'title' => 'title',
      'alpha' => 'alpha',
    ]);

    // 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');
    drupal_flush_all_caches();
  }

  /**
   * Tests importing from a timestamp.
   */
  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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsTest::$feedType protected property The feed type.
ParagraphsTest::$modules protected static property Modules to enable.
ParagraphsTest::setUp public function
ParagraphsTest::testImportParagraph public function Tests importing from a timestamp.
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.