3 namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
5 use Drupal\taxonomy\Entity\Term;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
9 * Upgrade taxonomy terms.
11 * @group migrate_drupal_6
13 class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
18 public static $modules = ['taxonomy'];
23 protected function setUp() {
25 $this->installEntitySchema('taxonomy_term');
26 $this->executeMigrations(['d6_taxonomy_vocabulary', 'd6_taxonomy_term']);
30 * Tests the Drupal 6 taxonomy term to Drupal 8 migration.
32 public function testTaxonomyTerms() {
36 'vid' => 'vocabulary_1_i_0_',
42 'vid' => 'vocabulary_2_i_1_',
48 'vid' => 'vocabulary_2_i_1_',
54 'vid' => 'vocabulary_3_i_2_',
60 'vid' => 'vocabulary_3_i_2_',
66 'vid' => 'vocabulary_3_i_2_',
71 $terms = Term::loadMultiple(array_keys($expected_results));
73 // Find each term in the tree.
74 $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
75 $vids = array_unique(array_column($expected_results, 'vid'));
77 foreach ($vids as $vid) {
78 foreach ($storage->loadTree($vid) as $term) {
79 $tree_terms[$term->tid] = $term;
83 foreach ($expected_results as $tid => $values) {
84 /** @var Term $term */
86 $this->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
87 $this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
88 $this->assertIdentical($values['vid'], $term->vid->target_id);
89 $this->assertIdentical((string) $values['weight'], $term->weight->value);
90 if ($values['parent'] === [0]) {
91 $this->assertNull($term->parent->target_id);
95 foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
96 $parents[] = (int) $parent->id();
98 $this->assertIdentical($parents, $values['parent']);
101 $this->assertArrayHasKey($tid, $tree_terms, "Term $tid exists in vocabulary tree");
102 $tree_term = $tree_terms[$tid];
103 $this->assertEquals($values['parent'], $tree_term->parents, "Term $tid has correct parents in vocabulary tree");