1 taxonomy.test TaxonomyVocabularyUnitTest::testTaxonomyVocabularyLoadMultiple()

Tests for loading multiple vocabularies.

File

core/modules/taxonomy/tests/taxonomy.test, line 351
Tests for taxonomy.module.

Class

TaxonomyVocabularyUnitTest
Tests for taxonomy vocabulary functions.

Code

function testTaxonomyVocabularyLoadMultiple() {

  // Delete any existing vocabularies.
  foreach (taxonomy_vocabulary_load_multiple(FALSE) as $vocabulary) {
    taxonomy_vocabulary_delete($vocabulary->machine_name);
  }

  // Create some vocabularies and assign weights.
  $vocabulary1 = $this->createVocabulary();
  $vocabulary1->weight = 0;
  taxonomy_vocabulary_save($vocabulary1);
  $vocabulary2 = $this->createVocabulary();
  $vocabulary2->weight = 1;
  taxonomy_vocabulary_save($vocabulary2);
  $vocabulary3 = $this->createVocabulary();
  $vocabulary3->weight = 2;
  taxonomy_vocabulary_save($vocabulary3);

  // Fetch the names for all vocabularies, confirm that they are keyed by
  // machine name.
  $vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
  $this->assertEqual($vocabularies[$vocabulary1->machine_name]->name, $vocabulary1->name, 'Vocabulary 1 name found.');

  // Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple(FALSE).
  // Confirm that the vocabularies are ordered by weight.
  $this->assertEqual(array_shift($vocabularies)->machine_name, $vocabulary1->machine_name, 'Vocabulary was found in the vocabularies array.');
  $this->assertEqual(array_shift($vocabularies)->machine_name, $vocabulary2->machine_name, 'Vocabulary was found in the vocabularies array.');
  $this->assertEqual(array_shift($vocabularies)->machine_name, $vocabulary3->machine_name, 'Vocabulary was found in the vocabularies array.');
}