function VocabularyCrudTest::testTaxonomyVocabularyDeleteWithTerms

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testTaxonomyVocabularyDeleteWithTerms()
  2. 8.9.x core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testTaxonomyVocabularyDeleteWithTerms()
  3. 10 core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php \Drupal\Tests\taxonomy\Kernel\VocabularyCrudTest::testTaxonomyVocabularyDeleteWithTerms()

Tests deleting a taxonomy that contains terms.

File

core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php, line 47

Class

VocabularyCrudTest
Tests loading, saving and deleting vocabularies.

Namespace

Drupal\Tests\taxonomy\Kernel

Code

public function testTaxonomyVocabularyDeleteWithTerms() : void {
    $vocabulary = $this->createVocabulary();
    $query = \Drupal::entityQuery('taxonomy_term')->accessCheck(FALSE)
        ->count();
    // Assert that there are no terms left.
    $this->assertEquals(0, $query->execute());
    $terms = [];
    for ($i = 0; $i < 5; $i++) {
        $terms[$i] = $this->createTerm($vocabulary);
    }
    // Set up hierarchy. term 2 is a child of 1 and 4 a child of 1 and 2.
    $terms[2]->parent = [
        $terms[1]->id(),
    ];
    $terms[2]->save();
    $terms[4]->parent = [
        $terms[1]->id(),
        $terms[2]->id(),
    ];
    $terms[4]->save();
    // Assert that there are now 5 terms.
    $this->assertEquals(5, $query->execute());
    $vocabulary->delete();
    // Assert that there are no terms left.
    $this->assertEquals(0, $query->execute());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.