3 namespace Drupal\Tests\content_translation\Kernel\Migrate\d6;
5 use Drupal\taxonomy\Entity\Term;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7 use Drupal\taxonomy\TermInterface;
10 * Test migration of translated taxonomy terms.
12 * @group migrate_drupal_6
14 class MigrateTaxonomyTermTranslationTest extends MigrateDrupal6TestBase {
19 public static $modules = [
20 'content_translation',
28 * The cached taxonomy tree items, keyed by vid and tid.
32 protected $treeData = [];
37 protected function setUp() {
39 $this->installEntitySchema('taxonomy_term');
40 $this->installConfig(static::$modules);
41 $this->executeMigrations([
44 'd6_taxonomy_vocabulary',
47 'd6_taxonomy_term_translation',
52 * Validate a migrated term contains the expected values.
55 * Entity ID to load and check.
56 * @param string $expected_language
57 * The language code for this term.
58 * @param string $expected_label
59 * The label the migrated entity should have.
60 * @param string $expected_vid
61 * The parent vocabulary the migrated entity should have.
62 * @param string $expected_description
63 * The description the migrated entity should have.
64 * @param string $expected_format
65 * The format the migrated entity should have.
66 * @param int $expected_weight
67 * The weight the migrated entity should have.
68 * @param array $expected_parents
69 * The parent terms the migrated entity should have.
70 * @param int $expected_field_integer_value
71 * The value the migrated entity field should have.
72 * @param int $expected_term_reference_tid
73 * The term reference ID the migrated entity field should have.
75 protected function assertEntity($id, $expected_language, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) {
76 /** @var \Drupal\taxonomy\TermInterface $entity */
77 $entity = Term::load($id);
78 $this->assertInstanceOf(TermInterface::class, $entity);
79 $this->assertSame($expected_language, $entity->language()->getId());
80 $this->assertSame($expected_label, $entity->label());
81 $this->assertSame($expected_vid, $entity->getVocabularyId());
82 $this->assertSame($expected_description, $entity->getDescription());
83 $this->assertSame($expected_format, $entity->getFormat());
84 $this->assertSame($expected_weight, $entity->getWeight());
85 $this->assertHierarchy($expected_vid, $id, $expected_parents);
89 * Assert that a term is present in the tree storage, with the right parents.
94 * ID of the term to check.
95 * @param array $parent_ids
96 * The expected parent term IDs.
98 protected function assertHierarchy($vid, $tid, array $parent_ids) {
99 if (!isset($this->treeData[$vid])) {
100 $tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
101 $this->treeData[$vid] = [];
102 foreach ($tree as $item) {
103 $this->treeData[$vid][$item->tid] = $item;
107 $this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree");
108 $term = $this->treeData[$vid][$tid];
109 $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree");
113 * Tests the Drupal 6 i18n taxonomy term to Drupal 8 migration.
115 public function testTranslatedTaxonomyTerms() {
116 $this->assertEntity(1, 'zu', 'zu - term 1 of vocabulary 1', 'vocabulary_1_i_0_', 'zu - description of term 1 of vocabulary 1', NULL, '0', []);
117 $this->assertEntity(2, 'fr', 'fr - term 2 of vocabulary 2', 'vocabulary_2_i_1_', 'fr - description of term 2 of vocabulary 2', NULL, '3', []);
118 $this->assertEntity(3, 'fr', 'fr - term 3 of vocabulary 2', 'vocabulary_2_i_1_', 'fr - description of term 3 of vocabulary 2', NULL, '4', ['2']);
119 $this->assertEntity(4, 'en', 'term 4 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 4 of vocabulary 3', NULL, '6', []);
120 $this->assertEntity(5, 'en', 'term 5 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 5 of vocabulary 3', NULL, '7', ['4']);
121 $this->assertEntity(6, 'en', 'term 6 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 6 of vocabulary 3', NULL, '8', ['4', '5']);
122 $this->assertEntity(7, 'fr', 'fr - term 2 of vocabulary 1', 'vocabulary_1_i_0_', 'fr - desc of term 2 vocab 1', NULL, '0', []);