public function TermKernelTest::testMultipleParentDelete in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testMultipleParentDelete()
Deleting a parent of a term with multiple parents does not delete the term.
File
- core/
modules/ taxonomy/ tests/ src/ Kernel/ TermKernelTest.php, line 47
Class
- TermKernelTest
- Kernel tests for taxonomy term functions.
Namespace
Drupal\Tests\taxonomy\KernelCode
public function testMultipleParentDelete() {
$vocabulary = $this
->createVocabulary();
$parent_term1 = $this
->createTerm($vocabulary);
$parent_term2 = $this
->createTerm($vocabulary);
$child_term = $this
->createTerm($vocabulary);
$child_term->parent = [
$parent_term1
->id(),
$parent_term2
->id(),
];
$child_term
->save();
$child_term_id = $child_term
->id();
$parent_term1
->delete();
$term_storage = $this->container
->get('entity_type.manager')
->getStorage('taxonomy_term');
$term_storage
->resetCache([
$child_term_id,
]);
$child_term = Term::load($child_term_id);
$this
->assertTrue(!empty($child_term), 'Child term is not deleted if only one of its parents is removed.');
$parent_term2
->delete();
$term_storage
->resetCache([
$child_term_id,
]);
$child_term = Term::load($child_term_id);
$this
->assertTrue(empty($child_term), 'Child term is deleted if all of its parents are removed.');
}