You are here

public function MigrateBundleTest::testProcessBundle in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/MigrateBundleTest.php \Drupal\Tests\migrate\Kernel\MigrateBundleTest::testProcessBundle()
  2. 9 core/modules/migrate/tests/src/Kernel/MigrateBundleTest.php \Drupal\Tests\migrate\Kernel\MigrateBundleTest::testProcessBundle()

Tests setting the bundle in the process pipeline.

File

core/modules/migrate/tests/src/Kernel/MigrateBundleTest.php, line 77

Class

MigrateBundleTest
Tests setting of bundles on content entity migrations.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testProcessBundle() {
  $term_data_rows = [
    [
      'id' => 1,
      'vocab' => 'categories',
      'name' => 'Category 1',
    ],
    [
      'id' => 2,
      'vocab' => 'tags',
      'name' => 'Tag 1',
    ],
  ];
  $ids = [
    'id' => [
      'type' => 'integer',
    ],
  ];
  $definition = [
    'id' => 'terms',
    'migration_tags' => [
      'Bundle test',
    ],
    'source' => [
      'plugin' => 'embedded_data',
      'data_rows' => $term_data_rows,
      'ids' => $ids,
    ],
    'process' => [
      'tid' => 'id',
      'vid' => 'vocab',
      'name' => 'name',
    ],
    'destination' => [
      'plugin' => 'entity:taxonomy_term',
    ],
    'migration_dependencies' => [],
  ];
  $term_migration = \Drupal::service('plugin.manager.migration')
    ->createStubMigration($definition);

  // Import and validate the term entities were created with the correct bundle.
  $term_executable = new MigrateExecutable($term_migration, $this);
  $term_executable
    ->import();

  /** @var \Drupal\taxonomy\Entity\Term $term */
  $term = Term::load(1);
  $this
    ->assertEquals('categories', $term
    ->bundle());
  $term = Term::load(2);
  $this
    ->assertEquals('tags', $term
    ->bundle());
}