function VocabularyTest::testTaxonomyAdminDeletingVocabulary

Deleting a vocabulary.

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php, line 126
Definition of Drupal\taxonomy\Tests\VocabularyTest.

Class

VocabularyTest
Tests the taxonomy vocabulary interface.

Namespace

Drupal\taxonomy\Tests

Code

function testTaxonomyAdminDeletingVocabulary() {

  // Create a vocabulary.
  $edit = array(
    'name' => $this
      ->randomName(),
    'machine_name' => drupal_strtolower($this
      ->randomName()),
  );
  $this
    ->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
  $this
    ->assertText(t('Created new vocabulary'), 'New vocabulary was created.');

  // Check the created vocabulary.
  $vocabularies = taxonomy_vocabulary_load_multiple();
  $vid = $vocabularies[count($vocabularies) - 1]->vid;
  entity_get_controller('taxonomy_vocabulary')
    ->resetCache();
  $vocabulary = taxonomy_vocabulary_load($vid);
  $this
    ->assertTrue($vocabulary, 'Vocabulary found in database.');

  // Delete the vocabulary.
  $edit = array();
  $this
    ->drupalPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/edit', $edit, t('Delete'));
  $this
    ->assertRaw(t('Are you sure you want to delete the vocabulary %name?', array(
    '%name' => $vocabulary->name,
  )), '[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
    ->drupalPost(NULL, NULL, t('Delete'));
  $this
    ->assertRaw(t('Deleted vocabulary %name.', array(
    '%name' => $vocabulary->name,
  )), 'Vocabulary deleted.');
  entity_get_controller('taxonomy_vocabulary')
    ->resetCache();
  $this
    ->assertFalse(taxonomy_vocabulary_load($vid), t('Vocabulary is not found in the database'));
}