You are here

function VocabularyCrudTest::testTaxonomyVocabularyLoadStaticReset in Zircon Profile 8

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

Ensure that the vocabulary static reset works correctly.

File

core/modules/taxonomy/src/Tests/VocabularyCrudTest.php, line 71
Contains \Drupal\taxonomy\Tests\VocabularyCrudTest.

Class

VocabularyCrudTest
Tests loading, saving and deleting vocabularies.

Namespace

Drupal\taxonomy\Tests

Code

function testTaxonomyVocabularyLoadStaticReset() {
  $original_vocabulary = Vocabulary::load($this->vocabulary
    ->id());
  $this
    ->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.');
  $this
    ->assertEqual($this->vocabulary
    ->label(), $original_vocabulary
    ->label(), 'Vocabulary loaded successfully.');

  // Change the name and description.
  $vocabulary = $original_vocabulary;
  $vocabulary
    ->set('name', $this
    ->randomMachineName());
  $vocabulary
    ->set('description', $this
    ->randomMachineName());
  $vocabulary
    ->save();

  // Load the vocabulary.
  $new_vocabulary = Vocabulary::load($original_vocabulary
    ->id());
  $this
    ->assertEqual($new_vocabulary
    ->label(), $vocabulary
    ->label(), 'The vocabulary was loaded.');

  // Delete the vocabulary.
  $this->vocabulary
    ->delete();
  $vocabularies = Vocabulary::loadMultiple();
  $this
    ->assertTrue(!isset($vocabularies[$this->vocabulary
    ->id()]), 'The vocabulary was deleted.');
}