You are here

public function ContentEntityTest::testTermSource in Drupal 8

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

Tests term source plugin.

@dataProvider migrationConfigurationProvider

File

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

Class

ContentEntityTest
Tests the entity content source plugin.

Namespace

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

Code

public function testTermSource(array $configuration) {
  $term2 = Term::create([
    'vid' => $this->vocabulary,
    'name' => 'Granny Smith',
    'uid' => $this->user
      ->id(),
    'parent' => 1,
  ]);
  $term2
    ->save();
  $configuration += [
    'bundle' => $this->vocabulary,
  ];
  $migration = $this->migrationPluginManager
    ->createStubMigration($this
    ->migrationDefinition('content_entity:taxonomy_term', $configuration));
  $term_source = $migration
    ->getSourcePlugin();
  $this
    ->assertSame('taxonomy terms', $term_source
    ->__toString());
  if (!$configuration['include_translations']) {
    $this
      ->assertEquals(2, $term_source
      ->count());
  }
  $this
    ->assertIds($term_source, $configuration);
  $fields = $term_source
    ->fields();
  $this
    ->assertArrayHasKey('vid', $fields);
  $this
    ->assertArrayHasKey('revision_id', $fields);
  $this
    ->assertArrayHasKey('tid', $fields);
  $this
    ->assertArrayHasKey('name', $fields);
  $term_source
    ->rewind();
  $values = $term_source
    ->current()
    ->getSource();
  $this
    ->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
  $this
    ->assertEquals(1, $values['tid']);

  // @TODO: Add test coverage for parent in
  // https://www.drupal.org/project/drupal/issues/2940198
  $this
    ->assertEquals('Apples', $values['name'][0]['value']);
  $term_source
    ->next();
  $values = $term_source
    ->current()
    ->getSource();
  $this
    ->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
  $this
    ->assertEquals(2, $values['tid']);

  // @TODO: Add test coverage for parent in
  // https://www.drupal.org/project/drupal/issues/2940198
  $this
    ->assertEquals('Granny Smith', $values['name'][0]['value']);
}