You are here

public function ContentEntityTest::testNodeSource in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testNodeSource()

Tests node source plugin.

@dataProvider migrationConfigurationProvider

File

core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php, line 340

Class

ContentEntityTest
Tests the entity content source plugin.

Namespace

Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source

Code

public function testNodeSource(array $configuration) {
  $configuration += [
    'bundle' => $this->bundle,
  ];
  $migration = $this->migrationPluginManager
    ->createStubMigration($this
    ->migrationDefinition('content_entity:node', $configuration));
  $node_source = $migration
    ->getSourcePlugin();
  $this
    ->assertSame('content items', $node_source
    ->__toString());
  $this
    ->assertIds($node_source, $configuration);
  $fields = $node_source
    ->fields();
  $this
    ->assertArrayHasKey('nid', $fields);
  $this
    ->assertArrayHasKey('vid', $fields);
  $this
    ->assertArrayHasKey('title', $fields);
  $this
    ->assertArrayHasKey('uid', $fields);
  $this
    ->assertArrayHasKey('sticky', $fields);
  $node_source
    ->rewind();
  $values = $node_source
    ->current()
    ->getSource();
  $this
    ->assertEquals($this->bundle, $values['type'][0]['target_id']);
  $this
    ->assertEquals(1, $values['nid']);
  if ($configuration['add_revision_id']) {
    $this
      ->assertEquals(1, $values['vid']);
  }
  else {
    $this
      ->assertEquals([
      [
        'value' => '1',
      ],
    ], $values['vid']);
  }
  $this
    ->assertEquals('en', $values['langcode']);
  $this
    ->assertEquals(1, $values['status'][0]['value']);
  $this
    ->assertEquals('Apples', $values['title'][0]['value']);
  $this
    ->assertEquals(1, $values['default_langcode'][0]['value']);
  $this
    ->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
  if ($configuration['include_translations']) {
    $node_source
      ->next();
    $values = $node_source
      ->current()
      ->getSource();
    $this
      ->assertEquals($this->bundle, $values['type'][0]['target_id']);
    $this
      ->assertEquals(1, $values['nid']);
    if ($configuration['add_revision_id']) {
      $this
        ->assertEquals(1, $values['vid']);
    }
    else {
      $this
        ->assertEquals([
        0 => [
          'value' => 1,
        ],
      ], $values['vid']);
    }
    $this
      ->assertEquals('fr', $values['langcode']);
    $this
      ->assertEquals(1, $values['status'][0]['value']);
    $this
      ->assertEquals('Pommes', $values['title'][0]['value']);
    $this
      ->assertEquals(0, $values['default_langcode'][0]['value']);
    $this
      ->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
  }
}