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_',
43 'vid' => 'vocabulary_2_i_1_',
50 'vid' => 'vocabulary_2_i_1_',
57 'vid' => 'vocabulary_3_i_2_',
63 'vid' => 'vocabulary_3_i_2_',
69 'vid' => 'vocabulary_3_i_2_',
74 $terms = Term::loadMultiple(array_keys($expected_results));
76 // Find each term in the tree.
77 $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
78 $vids = array_unique(array_column($expected_results, 'vid'));
80 foreach ($vids as $vid) {
81 foreach ($storage->loadTree($vid) as $term) {
82 $tree_terms[$term->tid] = $term;
86 foreach ($expected_results as $tid => $values) {
87 /** @var \Drupal\taxonomy\Entity\Term $term */
89 $language = isset($values['language']) ? $values['language'] . ' - ' : '';
90 $this->assertSame("{$language}term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
91 $this->assertSame("{$language}description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
92 $this->assertSame($values['vid'], $term->vid->target_id);
93 $this->assertSame((string) $values['weight'], $term->weight->value);
94 if ($values['parent'] === [0]) {
95 $this->assertSame(0, (int) $term->parent->target_id);
99 foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
100 $parents[] = (int) $parent->id();
102 $this->assertSame($parents, $values['parent']);
105 $this->assertArrayHasKey($tid, $tree_terms, "Term $tid exists in vocabulary tree");
106 $tree_term = $tree_terms[$tid];
108 // PostgreSQL, MySQL and SQLite may not return the parent terms in the
109 // same order so sort before testing.
110 $expected_parents = $values['parent'];
111 sort($expected_parents);
112 $actual_parents = $tree_term->parents;
113 sort($actual_parents);
114 $this->assertEquals($expected_parents, $actual_parents, "Term $tid has correct parents in vocabulary tree");