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', 'user'];
26 protected function setUp() {
28 $this->installEntitySchema('user');
29 $this->installEntitySchema('taxonomy_vocabulary');
30 $this->installEntitySchema('taxonomy_term');
31 $this->installConfig(['taxonomy']);
32 // Set up two vocabularies (taxonomy bundles).
33 Vocabulary::create(['vid' => 'tags', 'name' => 'Tags']);
34 Vocabulary::create(['vid' => 'categories', 'name' => 'Categories']);
38 * Tests setting the bundle in the destination.
40 public function testDestinationBundle() {
42 ['id' => 1, 'name' => 'Category 1'],
44 $ids = ['id' => ['type' => 'integer']];
47 'migration_tags' => ['Bundle test'],
49 'plugin' => 'embedded_data',
50 'data_rows' => $term_data_rows,
58 'plugin' => 'entity:taxonomy_term',
59 'default_bundle' => 'categories',
61 'migration_dependencies' => [],
64 $term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
66 // Import and validate the term entity was created with the correct bundle.
67 $term_executable = new MigrateExecutable($term_migration, $this);
68 $term_executable->import();
69 /** @var \Drupal\taxonomy\Entity\Term $term */
70 $term = Term::load(1);
71 $this->assertEquals($term->bundle(), 'categories');
75 * Tests setting the bundle in the process pipeline.
77 public function testProcessBundle() {
79 ['id' => 1, 'vocab' => 'categories', 'name' => 'Category 1'],
80 ['id' => 2, 'vocab' => 'tags', 'name' => 'Tag 1'],
82 $ids = ['id' => ['type' => 'integer']];
85 'migration_tags' => ['Bundle test'],
87 'plugin' => 'embedded_data',
88 'data_rows' => $term_data_rows,
97 'plugin' => 'entity:taxonomy_term',
99 'migration_dependencies' => [],
102 $term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
104 // Import and validate the term entities were created with the correct bundle.
105 $term_executable = new MigrateExecutable($term_migration, $this);
106 $term_executable->import();
107 /** @var \Drupal\taxonomy\Entity\Term $term */
108 $term = Term::load(1);
109 $this->assertEquals($term->bundle(), 'categories');
110 $term = Term::load(2);
111 $this->assertEquals($term->bundle(), 'tags');
115 * Tests setting bundles both in process and destination.
117 public function testMixedBundles() {
119 ['id' => 1, 'vocab' => 'categories', 'name' => 'Category 1'],
120 ['id' => 2, 'name' => 'Tag 1'],
122 $ids = ['id' => ['type' => 'integer']];
125 'migration_tags' => ['Bundle test'],
127 'plugin' => 'embedded_data',
128 'data_rows' => $term_data_rows,
137 'plugin' => 'entity:taxonomy_term',
138 // When no vocab is provided, the destination bundle is applied.
139 'default_bundle' => 'tags',
141 'migration_dependencies' => [],
144 $term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
146 // Import and validate the term entities were created with the correct bundle.
147 $term_executable = new MigrateExecutable($term_migration, $this);
148 $term_executable->import();
149 /** @var \Drupal\taxonomy\Entity\Term $term */
150 $term = Term::load(1);
151 $this->assertEquals($term->bundle(), 'categories');
152 $term = Term::load(2);
153 $this->assertEquals($term->bundle(), 'tags');