3 namespace Drupal\Tests\taxonomy\Kernel\Migrate;
5 use Drupal\migrate\MigrateExecutable;
6 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
7 use Drupal\migrate_drupal\Tests\StubTestTrait;
8 use Drupal\taxonomy\Entity\Term;
9 use Drupal\taxonomy\Entity\Vocabulary;
12 * Test stub creation for taxonomy terms.
16 class MigrateTaxonomyTermStubTest extends MigrateDrupalTestBase {
23 public static $modules = ['taxonomy', 'text', 'taxonomy_term_stub_test'];
28 protected function setUp() {
30 $this->installEntitySchema('taxonomy_term');
34 * Tests creation of taxonomy term stubs.
36 public function testStub() {
38 'vid' => 'test_vocabulary',
39 'name' => 'Test vocabulary',
41 $this->performStubTest('taxonomy_term');
45 * Tests creation of stubs when weight is mapped.
47 public function testStubWithWeightMapping() {
48 // Create a vocabulary via migration for the terms to reference.
49 $vocabulary_data_rows = [
50 ['id' => '1', 'name' => 'tags'],
52 $ids = ['id' => ['type' => 'integer']];
54 'migration_tags' => ['Stub test'],
56 'plugin' => 'embedded_data',
57 'data_rows' => $vocabulary_data_rows,
64 'destination' => ['plugin' => 'entity:taxonomy_vocabulary'],
66 $vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
67 $vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
68 $vocabulary_executable->import();
70 // We have a term referencing an unmigrated parent, forcing a stub to be
72 $migration = $this->getMigration('taxonomy_term_stub_test');
73 $term_executable = new MigrateExecutable($migration, $this);
74 $term_executable->import();
75 $this->assertTrue($migration->getIdMap()->getRowBySource(['2']), 'Stub row exists in the ID map table');
77 // Load the referenced term, which should exist as a stub.
78 /** @var \Drupal\Core\Entity\ContentEntityBase $stub_entity */
79 $stub_entity = Term::load(2);
80 $this->assertTrue($stub_entity, 'Stub successfully created');
82 $this->assertIdentical(count($stub_entity->validate()), 0, 'Stub is a valid entity');