/** @var \Drupal\taxonomy\TermStorageInterface $storage */
$storage = \Drupal::
entityTypeManager()->
getStorage('taxonomy_term'
);
// Count parents of $term[2].
$parents =
$storage->
loadParents($term[2
]->
id());
$this->
assertCount(2,
$parents, 'The term has two parents.'
);
// Count parents of $term[3].
$parents =
$storage->
loadParents($term[3
]->
id());
$this->
assertCount(1,
$parents, 'The term has one parent.'
);
// Identify all ancestors of $term[2].
$ancestors =
$storage->
loadAllParents($term[2
]->
id());
$this->
assertCount(4,
$ancestors, 'The term has four ancestors including the term itself.'
);
// Identify all ancestors of $term[3].
$ancestors =
$storage->
loadAllParents($term[3
]->
id());
$this->
assertCount(5,
$ancestors, 'The term has five ancestors including the term itself.'
);
} /**
* Tests that a Term is renderable when unsaved (preview).
*/
public function testTermPreview() {