You are here

public function TestImporter::testAppendParagraphs in Feeds Paragraphs 8

@covers ::appendParagraphs

File

tests/src/Unit/TestImporter.php, line 293

Class

TestImporter
@group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\Importer

Namespace

Drupal\Tests\feeds_para_mapper\Unit

Code

public function testAppendParagraphs() {
  $this->entityHelper->values = array(
    'bundle_two_text' => array(
      array(
        'value' => 'a',
      ),
    ),
  );
  $method = $this
    ->getMethod(Importer::class, 'appendParagraphs');
  $values = array(
    array(
      array(
        'value' => 'a',
      ),
    ),
    array(
      array(
        'value' => 'b',
      ),
    ),
    array(
      array(
        'value' => 'c',
      ),
    ),
  );
  $paragraphs = array_values($this->entityHelper->paragraphs);
  $paragraph = $paragraphs[1]
    ->reveal();
  $paragraph->host_info = array(
    'field' => 'bundle_one_bundle_two',
    'bundle' => 'bundle_two',
    'entity' => $paragraphs[0]
      ->reveal(),
    'type' => 'paragraph',
  );
  $args = array(
    array(
      $paragraph,
    ),
    $values,
  );
  $result = $method
    ->invokeArgs($this->importer, $args);
  self::assertCount(3, $result);
  for ($i = 0; $i < count($result); $i++) {
    self::assertArrayEquals($values[$i], $result[$i]['value']);
    self::assertInstanceOf(Paragraph::class, $result[$i]['paragraph']);
    self::assertArrayHasKey('state', $result[$i]);
    $host_info = $result[$i]['paragraph']->host_info;
    self::assertArrayEquals($paragraph->host_info, $host_info);
  }
}