function TermKernelTest::testMultipleParentDelete
Same name in other branches
- 9 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testMultipleParentDelete()
- 8.9.x core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testMultipleParentDelete()
- 10 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 52
Class
- TermKernelTest
- Kernel tests for taxonomy term functions.
Namespace
Drupal\Tests\taxonomy\KernelCode
public function testMultipleParentDelete() : void {
$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->assertNotEmpty($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->assertEmpty($child_term, 'Child term is deleted if all of its parents are removed.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.