public function testTaxonomyTermHierarchy() { // Create two taxonomy terms.
$term1 =
$this->
createTerm($this->vocabulary
);
$term2 =
$this->
createTerm($this->vocabulary
);
// Get the taxonomy storage.
/** @var \Drupal\taxonomy\TermStorageInterface $taxonomy_storage */
$taxonomy_storage =
$this->container->
get('entity_type.manager'
)->
getStorage('taxonomy_term'
);
// Check that hierarchy is flat.
$this->
assertEquals(0,
$taxonomy_storage->
getVocabularyHierarchyType($this->vocabulary->
id()), 'Vocabulary is flat.'
);
// Edit $term2, setting $term1 as parent.
$edit =
[];
$edit['parent[]'
] =
[$term1->
id()];
$this->
drupalGet('taxonomy/term/' .
$term2->
id() . '/edit'
);
$this->
submitForm($edit, 'Save'
);
// Check the hierarchy.
$children =
$taxonomy_storage->
loadChildren($term1->
id());
$parents =
$taxonomy_storage->
loadParents($term2->
id());
$this->
assertTrue(isset($children[$term2->
id()]), 'Child found correctly.'
);