function TermKernelTest::testMultipleParentDelete

Same name in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testMultipleParentDelete()
  2. 10 core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php \Drupal\Tests\taxonomy\Kernel\TermKernelTest::testMultipleParentDelete()
  3. 11.x 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\Kernel

Code

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->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.