You are here

public function TermKernelTest::testMultipleParentDelete in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Tests/TermKernelTest.php \Drupal\taxonomy\Tests\TermKernelTest::testMultipleParentDelete()

Deleting a parent of a term with multiple parents does not delete the term.

File

core/modules/taxonomy/src/Tests/TermKernelTest.php, line 55
Contains \Drupal\taxonomy\Tests\TermKernelTest.

Class

TermKernelTest
Kernel tests for taxonomy term functions.

Namespace

Drupal\taxonomy\Tests

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 = array(
    $parent_term1
      ->id(),
    $parent_term2
      ->id(),
  );
  $child_term
    ->save();
  $child_term_id = $child_term
    ->id();
  $parent_term1
    ->delete();
  $term_storage = $this->container
    ->get('entity.manager')
    ->getStorage('taxonomy_term');
  $term_storage
    ->resetCache(array(
    $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(array(
    $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.');
}