summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2018-11-15 15:02:37 (GMT)
committerNathaniel Catchpole2018-11-15 15:03:04 (GMT)
commit36ba6ba3ded347a8ba1cb806be0cb07cf130d5ad (patch)
treef0bb982ef583ba21e735c99d0e5a4b8e701644ac
parent7836638b0800d82208c68037b8551672ddd81a0d (diff)
Issue #2886609 by quietone, Jo Fitzgerald, masipila, heddn, jhodgdon, Gábor Hojtsy, mikeryan, alexpott: Migrate translations for D6 i18n taxonomy 'localized' terms
(cherry picked from commit a3072cba96582ba05aaa989d1905c515369cdbd9)
-rw-r--r--core/modules/content_translation/migrations/d6_taxonomy_term_localized_translation.yml44
-rw-r--r--core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php7
-rw-r--r--core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentTaxonomyVocabularySettingsTest.php4
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php208
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php4
-rw-r--r--core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php100
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php9
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermLocalizedTranslationTest.php142
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateVocabularyFieldInstanceTest.php4
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermLocalizedTranslationTest.php179
10 files changed, 692 insertions, 9 deletions
diff --git a/core/modules/content_translation/migrations/d6_taxonomy_term_localized_translation.yml b/core/modules/content_translation/migrations/d6_taxonomy_term_localized_translation.yml
new file mode 100644
index 0000000..980baf4
--- /dev/null
+++ b/core/modules/content_translation/migrations/d6_taxonomy_term_localized_translation.yml
@@ -0,0 +1,44 @@
+id: d6_taxonomy_term_localized_translation
+label: Taxonomy localized term translations
+migration_tags:
+ - Drupal 6
+ - Content
+ - Multilingual
+source:
+ plugin: d6_term_localized_translation
+ translations: true
+process:
+ # If you are using this file to build a custom migration consider removing
+ # the tid field to allow incremental migrations.
+ tid: tid
+ langcode: language
+ vid:
+ plugin: migration
+ migration: d6_taxonomy_vocabulary
+ source: vid
+ name:
+ -
+ plugin: callback
+ source:
+ - name_translated
+ - name
+ callable: array_filter
+ -
+ plugin: callback
+ callable: current
+ description:
+ -
+ plugin: callback
+ source:
+ - description_translated
+ - description
+ callable: array_filter
+ -
+ plugin: callback
+ callable: current
+destination:
+ plugin: entity:taxonomy_term
+ translations: true
+migration_dependencies:
+ required:
+ - d6_taxonomy_term
diff --git a/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php b/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php
index 3e32406..1baf584 100644
--- a/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php
+++ b/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php
@@ -108,7 +108,12 @@ class MigrateTaxonomyTermTranslationTest extends MigrateDrupal6TestBase {
$this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree");
$term = $this->treeData[$vid][$tid];
- $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree");
+ // PostgreSQL, MySQL and SQLite may not return the parent terms in the same
+ // order so sort before testing.
+ sort($parent_ids);
+ $actual_terms = array_filter($term->parents);
+ sort($actual_terms);
+ $this->assertEquals($parent_ids, $actual_terms, "Term $tid has correct parents in taxonomy tree");
}
/**
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentTaxonomyVocabularySettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentTaxonomyVocabularySettingsTest.php
index 1f7fd03..b7b3f4b 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentTaxonomyVocabularySettingsTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentTaxonomyVocabularySettingsTest.php
@@ -45,9 +45,9 @@ class MigrateLanguageContentTaxonomyVocabularySettingsTest extends MigrateDrupal
// Set language to vocabulary.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_2_i_1_', 'fr', FALSE, ['enabled' => FALSE]);
// Localize terms.
- $this->assertLanguageContentSettings($target_entity, 'vocabulary_3_i_2_', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => TRUE]);
+ $this->assertLanguageContentSettings($target_entity, 'vocabulary_3_i_2_', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => FALSE]);
// None translation enabled.
- $this->assertLanguageContentSettings($target_entity, 'vocabulary_name_much_longer_than', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
+ $this->assertLanguageContentSettings($target_entity, 'vocabulary_name_much_longer_than', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => TRUE]);
$this->assertLanguageContentSettings($target_entity, 'tags', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'forums', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'type', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index 185a7b6..389a4df 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -10071,6 +10071,30 @@ $connection->insert('i18n_strings')
'objectindex' => '0',
'format' => '0',
))
+->values(array(
+ 'lid' => '1692',
+ 'objectid' => '14',
+ 'type' => 'term',
+ 'property' => 'name',
+ 'objectindex' => '14',
+ 'format' => '0',
+))
+->values(array(
+ 'lid' => '1693',
+ 'objectid' => '15',
+ 'type' => 'term',
+ 'property' => 'name',
+ 'objectindex' => '15',
+ 'format' => '0',
+))
+->values(array(
+ 'lid' => '1694',
+ 'objectid' => '14',
+ 'type' => 'term',
+ 'property' => 'description',
+ 'objectindex' => '14',
+ 'format' => '0',
+))
->execute();
$connection->schema()->createTable('i18n_variable', array(
@@ -22642,6 +22666,27 @@ $connection->insert('locales_source')
'source' => 'White',
'version' => '1',
))
+->values(array(
+ 'lid' => '1692',
+ 'location' => 'term:14:name',
+ 'textgroup' => 'taxonomy',
+ 'source' => 'Talos IV',
+ 'version' => '1',
+))
+->values(array(
+ 'lid' => '1693',
+ 'location' => 'term:15:name',
+ 'textgroup' => 'taxonomy',
+ 'source' => 'Vulcan',
+ 'version' => '1',
+))
+->values(array(
+ 'lid' => '1694',
+ 'location' => 'term:14:description',
+ 'textgroup' => 'taxonomy',
+ 'source' => 'The home of Captain Christopher Pike.',
+ 'version' => '1',
+))
->execute();
$connection->schema()->createTable('locales_target', array(
@@ -27719,6 +27764,30 @@ $connection->insert('locales_target')
'i18n_status' => '0',
))
->values(array(
+ 'lid' => '1672',
+ 'translation' => 'fr - Type',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
+ 'lid' => '1692',
+ 'translation' => 'fr - Talos IV',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
+ 'lid' => '1694',
+ 'translation' => 'fr - The home of Captain Christopher Pike.',
+ 'language' => 'fr',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
'lid' => '66',
'translation' => 'zu - CCK - Aucune Intégration aux Vues',
'language' => 'zu',
@@ -27846,6 +27915,30 @@ $connection->insert('locales_target')
'plural' => '0',
'i18n_status' => '0',
))
+->values(array(
+ 'lid' => '1672',
+ 'translation' => 'zu - Type',
+ 'language' => 'zu',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
+ 'lid' => '1693',
+ 'translation' => 'zu - Vulcan',
+ 'language' => 'zu',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
+->values(array(
+ 'lid' => '1694',
+ 'translation' => 'zu - The home of Captain Christopher Pike.',
+ 'language' => 'zu',
+ 'plid' => '0',
+ 'plural' => '0',
+ 'i18n_status' => '0',
+))
->execute();
$connection->schema()->createTable('menu_custom', array(
@@ -40935,6 +41028,28 @@ $connection->insert('menu_router')
'file' => 'sites/all/modules/i18n/i18n.admin.inc',
))
->values(array(
+ 'path' => 'admin/settings/language/i18n/variables',
+ 'load_functions' => '',
+ 'to_arg_functions' => '',
+ 'access_callback' => 'user_access',
+ 'access_arguments' => 'a:1:{i:0;s:29:"administer site configuration";}',
+ 'page_callback' => 'drupal_get_form',
+ 'page_arguments' => 'a:1:{i:0;s:25:"i18n_admin_variables_form";}',
+ 'fit' => '31',
+ 'number_parts' => '5',
+ 'tab_parent' => 'admin/settings/language/i18n',
+ 'tab_root' => 'admin/settings/language',
+ 'title' => 'Variables',
+ 'title_callback' => 't',
+ 'title_arguments' => '',
+ 'type' => '128',
+ 'block_callback' => '',
+ 'description' => 'Multilingual variables.',
+ 'position' => '',
+ 'weight' => '0',
+ 'file' => 'sites/all/modules/i18n/i18n.admin.inc',
+))
+->values(array(
'path' => 'admin/settings/language/overview',
'load_functions' => '',
'to_arg_functions' => '',
@@ -47091,6 +47206,69 @@ $connection->insert('term_data')
'language' => '',
'trid' => '0',
))
+->values(array(
+ 'tid' => '9',
+ 'vid' => '3',
+ 'name' => 'fr - term 4 of vocabulary 3',
+ 'description' => '',
+ 'weight' => '0',
+ 'language' => 'fr',
+ 'trid' => '1',
+))
+->values(array(
+ 'tid' => '10',
+ 'vid' => '3',
+ 'name' => 'zu - term 4 of vocabulary 3',
+ 'description' => '',
+ 'weight' => '0',
+ 'language' => 'zu',
+ 'trid' => '1',
+))
+->values(array(
+ 'tid' => '11',
+ 'vid' => '3',
+ 'name' => 'term 7 of vocabulary 3',
+ 'description' => '',
+ 'weight' => '0',
+ 'language' => 'en',
+ 'trid' => '2',
+))
+->values(array(
+ 'tid' => '12',
+ 'vid' => '3',
+ 'name' => 'fr - term 7 of vocabulary 3',
+ 'description' => '',
+ 'weight' => '0',
+ 'language' => 'fr',
+ 'trid' => '2',
+))
+->values(array(
+ 'tid' => '13',
+ 'vid' => '3',
+ 'name' => 'zu - term 7 of vocabulary 3',
+ 'description' => '',
+ 'weight' => '0',
+ 'language' => 'zu',
+ 'trid' => '2',
+))
+->values(array(
+ 'tid' => '14',
+ 'vid' => '5',
+ 'name' => 'Talos IV',
+ 'description' => 'The home of Captain Christopher Pike.',
+ 'weight' => '0',
+ 'language' => '',
+ 'trid' => '0',
+))
+->values(array(
+ 'tid' => '15',
+ 'vid' => '5',
+ 'name' => 'Vulcan',
+ 'description' => '',
+ 'weight' => '0',
+ 'language' => '',
+ 'trid' => '0',
+))
->execute();
$connection->schema()->createTable('term_hierarchy', array(
@@ -47143,6 +47321,34 @@ $connection->insert('term_hierarchy')
'parent' => '0',
))
->values(array(
+ 'tid' => '9',
+ 'parent' => '0',
+))
+->values(array(
+ 'tid' => '10',
+ 'parent' => '0',
+))
+->values(array(
+ 'tid' => '11',
+ 'parent' => '0',
+))
+->values(array(
+ 'tid' => '12',
+ 'parent' => '0',
+))
+->values(array(
+ 'tid' => '13',
+ 'parent' => '0',
+))
+->values(array(
+ 'tid' => '14',
+ 'parent' => '0',
+))
+->values(array(
+ 'tid' => '15',
+ 'parent' => '0',
+))
+->values(array(
'tid' => '3',
'parent' => '2',
))
@@ -48740,7 +48946,7 @@ $connection->insert('variable')
))
->values(array(
'name' => 'i18ntaxonomy_vocabulary',
- 'value' => 'a:3:{i:1;s:1:"3";i:2;s:1:"2";i:3;s:1:"1";}',
+ 'value' => 'a:4:{i:1;s:1:"3";i:2;s:1:"2";i:3;s:1:"3";i:5;s:1:"1";}',
))
->values(array(
'name' => 'i18n_lock_node_article',
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
index 54ea574..b37b45b 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
@@ -84,7 +84,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
'shortcut_set' => 1,
'action' => 23,
'menu' => 8,
- 'taxonomy_term' => 8,
+ 'taxonomy_term' => 15,
'taxonomy_vocabulary' => 7,
'tour' => 5,
'user' => 7,
@@ -112,7 +112,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeExecuteTestBase {
$counts['file'] = 8;
$counts['menu_link_content'] = 11;
$counts['node'] = 19;
- $counts['taxonomy_term'] = 9;
+ $counts['taxonomy_term'] = 16;
$counts['user'] = 8;
$counts['view'] = 16;
return $counts;
diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php
new file mode 100644
index 0000000..5348ee2
--- /dev/null
+++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermLocalizedTranslation.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace Drupal\taxonomy\Plugin\migrate\source\d6;
+
+use Drupal\migrate\Row;
+
+/**
+ * Gets i18n taxonomy terms from source database.
+ *
+ * @MigrateSource(
+ * id = "d6_term_localized_translation",
+ * source_module = "i18ntaxonomy"
+ * )
+ */
+class TermLocalizedTranslation extends Term {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ // Ideally, the query would return rows for each language for each taxonomy
+ // term with the translations for both the name and description or just the
+ // name translation or just the description translation. That query quickly
+ // became complex and would be difficult to maintain.
+ // Therefore, build a query based on i18nstrings table where each row has
+ // the translation for only one property, either name or description. The
+ // method prepareRow() is then used to obtain the translation for the other
+ // property.
+ $query = parent::query();
+ $query->addField('td', 'language', 'td.language');
+
+ // Add in the property, which is either name or description.
+ // Cast td.tid as char for PostgreSQL compatibility.
+ $query->leftJoin('i18n_strings', 'i18n', 'CAST(td.tid AS CHAR(255)) = i18n.objectid');
+ $query->isNotNull('i18n.lid');
+ $query->addField('i18n', 'lid');
+ $query->addField('i18n', 'property');
+
+ // Add in the translation for the property.
+ $query->innerJoin('locales_target', 'lt', 'i18n.lid = lt.lid');
+ $query->addField('lt', 'language', 'lt.language');
+ $query->addField('lt', 'translation');
+ return $query;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function prepareRow(Row $row) {
+ $language = $row->getSourceProperty('ltlanguage');
+ $row->setSourceProperty('language', $language);
+ $tid = $row->getSourceProperty('tid');
+
+ // If this row has been migrated it is a duplicate then skip it.
+ if ($this->idMap->lookupDestinationIds(['tid' => $tid, 'language' => $language])) {
+ return FALSE;
+ }
+
+ // Save the translation for this property.
+ $property = $row->getSourceProperty('property');
+ $row->setSourceProperty($property . '_translated', $row->getSourceProperty('translation'));
+
+ // Get the translation, if one exists, for the property not already in the
+ // row.
+ $other_property = ($property == 'name') ? 'description' : 'name';
+ $query = $this->select('i18n_strings', 'i18n')
+ ->fields('i18n', ['lid'])
+ ->condition('i18n.property', $other_property)
+ ->condition('i18n.objectid', $tid);
+ $query->leftJoin('locales_target', 'lt', 'i18n.lid = lt.lid');
+ $query->condition('lt.language', $language);
+ $query->addField('lt', 'translation');
+ $results = $query->execute()->fetchAssoc();
+ $row->setSourceProperty($other_property . '_translated', $results['translation']);
+
+ parent::prepareRow($row);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ $fields = [
+ 'language' => $this->t('Language for this term.'),
+ 'name_translated' => $this->t('Term name translation.'),
+ 'description_translated' => $this->t('Term description translation.'),
+ ];
+ return parent::fields() + $fields;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['language']['type'] = 'string';
+ $ids['language']['alias'] = 'lt';
+ return parent::getIds() + $ids;
+ }
+
+}
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
index 75c7924..20ecb63 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
@@ -104,7 +104,14 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
$this->assertArrayHasKey($tid, $tree_terms, "Term $tid exists in vocabulary tree");
$tree_term = $tree_terms[$tid];
- $this->assertEquals($values['parent'], $tree_term->parents, "Term $tid has correct parents in vocabulary tree");
+
+ // PostgreSQL, MySQL and SQLite may not return the parent terms in the
+ // same order so sort before testing.
+ $expected_parents = $values['parent'];
+ sort($expected_parents);
+ $actual_parents = $tree_term->parents;
+ sort($actual_parents);
+ $this->assertEquals($expected_parents, $actual_parents, "Term $tid has correct parents in vocabulary tree");
}
}
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermLocalizedTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermLocalizedTranslationTest.php
new file mode 100644
index 0000000..b051ce6
--- /dev/null
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermLocalizedTranslationTest.php
@@ -0,0 +1,142 @@
+<?php
+
+namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
+
+use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
+use Drupal\taxonomy\Entity\Term;
+use Drupal\taxonomy\TermInterface;
+
+/**
+ * Tests migration of localized translated taxonomy terms.
+ *
+ * @group migrate_drupal_6
+ */
+class MigrateTermLocalizedTranslationTest extends MigrateDrupal6TestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [
+ 'content_translation',
+ 'language',
+ 'menu_ui',
+ 'node',
+ 'taxonomy',
+ // Required for translation migrations.
+ 'migrate_drupal_multilingual',
+ ];
+
+ /**
+ * The cached taxonomy tree items, keyed by vid and tid.
+ *
+ * @var array
+ */
+ protected $treeData = [];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ $this->installEntitySchema('taxonomy_term');
+ $this->installConfig(static::$modules);
+ $this->executeMigrations([
+ 'language',
+ 'd6_node_type',
+ 'd6_field',
+ 'd6_taxonomy_vocabulary',
+ 'd6_field_instance',
+ 'd6_taxonomy_term',
+ 'd6_taxonomy_term_localized_translation',
+ ]);
+ }
+
+ /**
+ * Validates a migrated term contains the expected values.
+ *
+ * @param int $id
+ * Entity ID to load and check.
+ * @param string $expected_language
+ * The language code for this term.
+ * @param string $expected_label
+ * The label the migrated entity should have.
+ * @param string $expected_vid
+ * The parent vocabulary the migrated entity should have.
+ * @param string $expected_description
+ * The description the migrated entity should have.
+ * @param string $expected_format
+ * The format the migrated entity should have.
+ * @param int $expected_weight
+ * The weight the migrated entity should have.
+ * @param array $expected_parents
+ * The parent terms the migrated entity should have.
+ * @param int $expected_field_integer_value
+ * The value the migrated entity field should have.
+ * @param int $expected_term_reference_tid
+ * The term reference ID the migrated entity field should have.
+ */
+ protected function assertEntity($id, $expected_language, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, array $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) {
+ /** @var \Drupal\taxonomy\TermInterface $entity */
+ $entity = Term::load($id);
+ $this->assertInstanceOf(TermInterface::class, $entity);
+ $this->assertSame($expected_language, $entity->language()->getId());
+ $this->assertSame($expected_label, $entity->label());
+ $this->assertSame($expected_vid, $entity->bundle());
+ $this->assertSame($expected_description, $entity->getDescription());
+ $this->assertSame($expected_format, $entity->getFormat());
+ $this->assertSame($expected_weight, $entity->getWeight());
+ $this->assertHierarchy($expected_vid, $id, $expected_parents);
+ }
+
+ /**
+ * Asserts that a term is present in the tree storage, with the right parents.
+ *
+ * @param string $vid
+ * Vocabulary ID.
+ * @param int $tid
+ * ID of the term to check.
+ * @param array $parent_ids
+ * The expected parent term IDs.
+ */
+ protected function assertHierarchy($vid, $tid, array $parent_ids) {
+ if (!isset($this->treeData[$vid])) {
+ $tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
+ $this->treeData[$vid] = [];
+ foreach ($tree as $item) {
+ $this->treeData[$vid][$item->tid] = $item;
+ }
+ }
+
+ $this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree");
+ $term = $this->treeData[$vid][$tid];
+ $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree");
+ }
+
+ /**
+ * Tests the Drupal 6 i18n localized taxonomy term to Drupal 8 migration.
+ */
+ public function testTranslatedLocalizedTaxonomyTerms() {
+ $this->assertEntity(14, 'en', 'Talos IV', 'vocabulary_name_much_longer_than', 'The home of Captain Christopher Pike.', NULL, '0', []);
+ $this->assertEntity(15, 'en', 'Vulcan', 'vocabulary_name_much_longer_than', NULL, NULL, '0', []);
+
+ /** @var \Drupal\taxonomy\TermInterface $entity */
+ $entity = Term::load(14);
+ $this->assertTrue($entity->hasTranslation('fr'));
+ $translation = $entity->getTranslation('fr');
+ $this->assertSame('fr - Talos IV', $translation->label());
+ $this->assertSame('fr - The home of Captain Christopher Pike.', $translation->getDescription());
+
+ $this->assertTrue($entity->hasTranslation('zu'));
+ $translation = $entity->getTranslation('zu');
+ $this->assertSame('Talos IV', $translation->label());
+ $this->assertSame('zu - The home of Captain Christopher Pike.', $translation->getDescription());
+
+ $entity = Term::load(15);
+ $this->assertFalse($entity->hasTranslation('fr'));
+ $this->assertTrue($entity->hasTranslation('zu'));
+ $translation = $entity->getTranslation('zu');
+ $this->assertSame('zu - Vulcan', $translation->label());
+ $this->assertSame('', $translation->getDescription());
+ }
+
+}
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateVocabularyFieldInstanceTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateVocabularyFieldInstanceTest.php
index c29e3d1..46d60a6 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateVocabularyFieldInstanceTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateVocabularyFieldInstanceTest.php
@@ -81,13 +81,13 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
$field_id = 'node.story.field_vocabulary_3_i_2_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
- $this->assertFalse($field->isTranslatable());
+ $this->assertTrue($field->isTranslatable());
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
$field_type = FieldConfig::load('node.sponsor.field_type');
$this->assertInstanceOf(FieldConfig::class, $field_type);
- $this->assertFalse($field->isTranslatable());
+ $this->assertTrue($field->isTranslatable());
}
/**
diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermLocalizedTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermLocalizedTranslationTest.php
new file mode 100644
index 0000000..c2fea26
--- /dev/null
+++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermLocalizedTranslationTest.php
@@ -0,0 +1,179 @@
+<?php
+
+namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
+
+use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
+
+/**
+ * Tests D6 i18n term localized source plugin.
+ *
+ * @covers \Drupal\taxonomy\Plugin\migrate\source\d6\TermLocalizedTranslation
+ * @group taxonomy
+ */
+class TermLocalizedTranslationTest extends MigrateSqlSourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['taxonomy', 'migrate_drupal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+ $tests = [];
+
+ // The source data.
+ $tests[0]['source_data']['term_data'] = [
+ [
+ 'tid' => 1,
+ 'vid' => 5,
+ 'name' => 'name value 1',
+ 'description' => 'description value 1',
+ 'weight' => 0,
+ 'language' => NULL,
+ ],
+ [
+ 'tid' => 2,
+ 'vid' => 6,
+ 'name' => 'name value 2',
+ 'description' => 'description value 2',
+ 'weight' => 0,
+ 'language' => NULL,
+ ],
+ [
+ 'tid' => 3,
+ 'vid' => 6,
+ 'name' => 'name value 3',
+ 'description' => 'description value 3',
+ 'weight' => 0,
+ 'language' => NULL,
+ ],
+ [
+ 'tid' => 4,
+ 'vid' => 5,
+ 'name' => 'name value 4',
+ 'description' => 'description value 4',
+ 'weight' => 1,
+ 'language' => NULL,
+ ],
+ ];
+ $tests[0]['source_data']['term_hierarchy'] = [
+ [
+ 'tid' => 1,
+ 'parent' => 0,
+ ],
+ [
+ 'tid' => 2,
+ 'parent' => 0,
+ ],
+ [
+ 'tid' => 3,
+ 'parent' => 0,
+ ],
+ [
+ 'tid' => 4,
+ 'parent' => 1,
+ ],
+ ];
+ $tests[0]['source_data']['i18n_strings'] = [
+ [
+ 'lid' => 6,
+ 'objectid' => 1,
+ 'type' => 'term',
+ 'property' => 'name',
+ 'objectindex' => '1',
+ 'format' => 0,
+ ],
+ [
+ 'lid' => 7,
+ 'objectid' => 1,
+ 'type' => 'term',
+ 'property' => 'description',
+ 'objectindex' => '1',
+ 'format' => 0,
+ ],
+ [
+ 'lid' => 8,
+ 'objectid' => 3,
+ 'type' => 'term',
+ 'property' => 'name',
+ 'objectindex' => '3',
+ 'format' => 0,
+ ],
+ ];
+ $tests[0]['source_data']['locales_target'] = [
+ [
+ 'lid' => 6,
+ 'language' => 'fr',
+ 'translation' => 'fr - name value 1 translation',
+ 'plid' => 0,
+ 'plural' => 0,
+ 'i18n_status' => 0,
+ ],
+ [
+ 'lid' => 7,
+ 'language' => 'fr',
+ 'translation' => 'fr - description value 1 translation',
+ 'plid' => 0,
+ 'plural' => 0,
+ 'i18n_status' => 0,
+ ],
+ [
+ 'lid' => 8,
+ 'language' => 'zu',
+ 'translation' => 'zu - description value 2 translation',
+ 'plid' => 0,
+ 'plural' => 0,
+ 'i18n_status' => 0,
+ ],
+ ];
+
+ // The expected results.
+ $tests[0]['expected_data'] = [
+ [
+ 'tid' => 1,
+ 'vid' => 5,
+ 'name' => 'name value 1',
+ 'description' => 'description value 1',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'property' => 'name',
+ 'language' => 'fr',
+ 'name_translated' => 'fr - name value 1 translation',
+ 'description_translated' => 'fr - description value 1 translation',
+ ],
+ [
+ 'tid' => 1,
+ 'vid' => 5,
+ 'name' => 'name value 1',
+ 'description' => 'description value 1',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'property' => 'description',
+ 'language' => 'fr',
+ 'name_translated' => 'fr - name value 1 translation',
+ 'description_translated' => 'fr - description value 1 translation',
+ ],
+ [
+ 'tid' => 3,
+ 'vid' => 6,
+ 'name' => 'name value 3',
+ 'description' => 'description value 3',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'property' => 'name',
+ 'language' => 'zu',
+ 'name_translated' => 'zu - description value 2 translation',
+ 'description_translated' => NULL,
+ ],
+ ];
+
+ $tests[0]['expected_count'] = NULL;
+ // Empty configuration will return terms for all vocabularies.
+ $tests[0]['configuration'] = [];
+
+ return $tests;
+ }
+
+}