function VocabularyUiTest::testTaxonomyAdminDeletingVocabulary

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php \Drupal\Tests\taxonomy\Functional\VocabularyUiTest::testTaxonomyAdminDeletingVocabulary()
  2. 10 core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php \Drupal\Tests\taxonomy\Functional\VocabularyUiTest::testTaxonomyAdminDeletingVocabulary()
  3. 11.x core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php \Drupal\Tests\taxonomy\Functional\VocabularyUiTest::testTaxonomyAdminDeletingVocabulary()

Deleting a vocabulary.

File

core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php, line 135

Class

VocabularyUiTest
Tests the taxonomy vocabulary interface.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTaxonomyAdminDeletingVocabulary() {
    // Create a vocabulary.
    $vid = mb_strtolower($this->randomMachineName());
    $edit = [
        'name' => $this->randomMachineName(),
        'vid' => $vid,
    ];
    $this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
    $this->assertText(t('Created new vocabulary'), 'New vocabulary was created.');
    // Check the created vocabulary.
    $this->container
        ->get('entity_type.manager')
        ->getStorage('taxonomy_vocabulary')
        ->resetCache();
    $vocabulary = Vocabulary::load($vid);
    $this->assertNotEmpty($vocabulary, 'Vocabulary found.');
    // Delete the vocabulary.
    $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id());
    $this->clickLink(t('Delete'));
    $this->assertRaw(t('Are you sure you want to delete the vocabulary %name?', [
        '%name' => $vocabulary->label(),
    ]), '[confirm deletion] Asks for confirmation.');
    $this->assertText(t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), '[confirm deletion] Inform that all terms will be deleted.');
    // Confirm deletion.
    $this->drupalPostForm(NULL, NULL, t('Delete'));
    $this->assertRaw(t('Deleted vocabulary %name.', [
        '%name' => $vocabulary->label(),
    ]), 'Vocabulary deleted.');
    $this->container
        ->get('entity_type.manager')
        ->getStorage('taxonomy_vocabulary')
        ->resetCache();
    $this->assertNull(Vocabulary::load($vid), 'Vocabulary not found.');
}

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