3 namespace Drupal\Tests\migrate\Kernel;
5 use Drupal\migrate\MigrateExecutable;
6 use Drupal\taxonomy\Entity\Term;
7 use Drupal\taxonomy\Entity\Vocabulary;
10 * Tests setting of bundles on content entity migrations.
14 class MigrateBundleTest extends MigrateTestBase {
21 public static $modules = ['taxonomy', 'text'];
26 protected function setUp() {
28 $this->installEntitySchema('taxonomy_vocabulary');
29 $this->installEntitySchema('taxonomy_term');
30 $this->installConfig(['taxonomy']);
31 // Set up two vocabularies (taxonomy bundles).
32 Vocabulary::create(['vid' => 'tags', 'name' => 'Tags']);
33 Vocabulary::create(['vid' => 'categories', 'name' => 'Categories']);
37 * Tests setting the bundle in the destination.
39 public function testDestinationBundle() {
41 ['id' => 1, 'name' => 'Category 1'],
43 $ids = ['id' => ['type' => 'integer']];
46 'migration_tags' => ['Bundle test'],
48 'plugin' => 'embedded_data',
49 'data_rows' => $term_data_rows,
57 'plugin' => 'entity:taxonomy_term',
58 'default_bundle' => 'categories',
60 'migration_dependencies' => [],
63 $term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
65 // Import and validate the term entity was created with the correct bundle.
66 $term_executable = new MigrateExecutable($term_migration, $this);
67 $term_executable->import();
68 /** @var Term $term */
69 $term = Term::load(1);
70 $this->assertEquals($term->bundle(), 'categories');
74 * Tests setting the bundle in the process pipeline.
76 public function testProcessBundle() {
78 ['id' => 1, 'vocab' => 'categories', 'name' => 'Category 1'],
79 ['id' => 2, 'vocab' => 'tags', 'name' => 'Tag 1'],
81 $ids = ['id' => ['type' => 'integer']];
84 'migration_tags' => ['Bundle test'],
86 'plugin' => 'embedded_data',
87 'data_rows' => $term_data_rows,
96 'plugin' => 'entity:taxonomy_term',
98 'migration_dependencies' => [],
101 $term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
103 // Import and validate the term entities were created with the correct bundle.
104 $term_executable = new MigrateExecutable($term_migration, $this);
105 $term_executable->import();
106 /** @var Term $term */
107 $term = Term::load(1);
108 $this->assertEquals($term->bundle(), 'categories');
109 $term = Term::load(2);
110 $this->assertEquals($term->bundle(), 'tags');
114 * Tests setting bundles both in process and destination.
116 public function testMixedBundles() {
118 ['id' => 1, 'vocab' => 'categories', 'name' => 'Category 1'],
119 ['id' => 2, 'name' => 'Tag 1'],
121 $ids = ['id' => ['type' => 'integer']];
124 'migration_tags' => ['Bundle test'],
126 'plugin' => 'embedded_data',
127 'data_rows' => $term_data_rows,
136 'plugin' => 'entity:taxonomy_term',
137 // When no vocab is provided, the destination bundle is applied.
138 'default_bundle' => 'tags',
140 'migration_dependencies' => [],
143 $term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
145 // Import and validate the term entities were created with the correct bundle.
146 $term_executable = new MigrateExecutable($term_migration, $this);
147 $term_executable->import();
148 /** @var Term $term */
149 $term = Term::load(1);
150 $this->assertEquals($term->bundle(), 'categories');
151 $term = Term::load(2);
152 $this->assertEquals($term->bundle(), 'tags');