Commit a1b02adf authored by alexpott's avatar alexpott

Issue #2744639 by vasi, mikeryan, boromino, stevector: Taxonomy term hierarchy migration incomplete

parent eadde8da
......@@ -13,10 +13,19 @@ process:
name: name
description: description
weight: weight
# Only attempt to stub real (non-zero) parents.
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration
migration: d6_taxonomy_term
parent:
plugin: migration
migration: d6_taxonomy_term
source: parent
plugin: default_value
default_value: 0
source: '@parent_id'
changed: timestamp
destination:
plugin: entity:taxonomy_term
......
......@@ -14,10 +14,19 @@ process:
'description/value': description
'description/format': format
weight: weight
# Only attempt to stub real (non-zero) parents.
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration
migration: d7_taxonomy_term
parent:
plugin: migration
migration: d7_taxonomy_term
source: parent
plugin: default_value
default_value: 0
source: '@parent_id'
changed: timestamp
destination:
plugin: entity:taxonomy_term
......
......@@ -69,6 +69,17 @@ public function testTaxonomyTerms() {
),
);
$terms = Term::loadMultiple(array_keys($expected_results));
// Find each term in the tree.
$storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$vids = array_unique(array_column($expected_results, 'vid'));
$tree_terms = [];
foreach ($vids as $vid) {
foreach ($storage->loadTree($vid) as $term) {
$tree_terms[$term->tid] = $term;
}
}
foreach ($expected_results as $tid => $values) {
/** @var Term $term */
$term = $terms[$tid];
......@@ -86,6 +97,10 @@ public function testTaxonomyTerms() {
}
$this->assertIdentical($parents, $values['parent']);
}
$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");
}
}
......
......@@ -15,6 +15,13 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = array('taxonomy', 'text');
/**
* The cached taxonomy tree items, keyed by vid and tid.
*
* @var array
*/
protected $treeData = [];
/**
* {@inheritdoc}
*/
......@@ -52,6 +59,7 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d
$this->assertEquals($expected_format, $entity->getFormat());
$this->assertEqual($expected_weight, $entity->getWeight());
$this->assertIdentical($expected_parents, $this->getParentIDs($id));
$this->assertHierarchy($expected_vid, $id, $expected_parents);
}
/**
......@@ -81,4 +89,28 @@ protected function getParentIDs($tid) {
return array_keys(\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid));
}
/**
* Assert that a term is present in the tree storage, with the right parents.
*
* @param string $vid
* Vocabular 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");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment