function TaxonomyVocabularyTestCase::testTaxonomyVocabularyLoadReturnFalse
Ensure that when an invalid vocabulary vid is loaded, it is possible to load the same vid successfully if it subsequently becomes valid.
File
-
modules/
taxonomy/ taxonomy.test, line 224
Class
- TaxonomyVocabularyTestCase
- Tests for taxonomy vocabulary functions.
Code
function testTaxonomyVocabularyLoadReturnFalse() {
// Load a vocabulary that doesn't exist.
$vocabularies = taxonomy_get_vocabularies();
$vid = count($vocabularies) + 1;
$vocabulary = taxonomy_vocabulary_load($vid);
// This should not return an object because no such vocabulary exists.
$this->assertTrue(empty($vocabulary), 'No object loaded.');
// Create a new vocabulary.
$this->createVocabulary();
// Load the vocabulary with the same $vid from earlier.
// This should return a vocabulary object since it now matches a real vid.
$vocabulary = taxonomy_vocabulary_load($vid);
$this->assertTrue(!empty($vocabulary) && is_object($vocabulary), 'Vocabulary is an object.');
$this->assertEqual($vocabulary->vid, $vid, 'Valid vocabulary vid is the same as our previously invalid one.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.