function VocabularyCrudTest::testTaxonomyVocabularyLoadMultiple in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/taxonomy/src/Tests/VocabularyCrudTest.php \Drupal\taxonomy\Tests\VocabularyCrudTest::testTaxonomyVocabularyLoadMultiple()
Tests for loading multiple vocabularies.
File
- core/
modules/ taxonomy/ src/ Tests/ VocabularyCrudTest.php, line 95 - Contains \Drupal\taxonomy\Tests\VocabularyCrudTest.
Class
- VocabularyCrudTest
- Tests loading, saving and deleting vocabularies.
Namespace
Drupal\taxonomy\TestsCode
function testTaxonomyVocabularyLoadMultiple() {
// Delete any existing vocabularies.
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$vocabulary
->delete();
}
// Create some vocabularies and assign weights.
$vocabulary1 = $this
->createVocabulary();
$vocabulary1
->set('weight', 0);
$vocabulary1
->save();
$vocabulary2 = $this
->createVocabulary();
$vocabulary2
->set('weight', 1);
$vocabulary2
->save();
$vocabulary3 = $this
->createVocabulary();
$vocabulary3
->set('weight', 2);
$vocabulary3
->save();
// Check if third party settings exist.
$this
->assertEqual('bar', $vocabulary1
->getThirdPartySetting('taxonomy_crud', 'foo'), 'Third party settings were added to the vocabulary.');
$this
->assertEqual('bar', $vocabulary2
->getThirdPartySetting('taxonomy_crud', 'foo'), 'Third party settings were added to the vocabulary.');
$this
->assertEqual('bar', $vocabulary3
->getThirdPartySetting('taxonomy_crud', 'foo'), 'Third party settings were added to the vocabulary.');
// Fetch the names for all vocabularies, confirm that they are keyed by
// machine name.
$names = taxonomy_vocabulary_get_names();
$this
->assertEqual($names[$vocabulary1
->id()], $vocabulary1
->id(), 'Vocabulary 1 name found.');
// Fetch the vocabularies with entity_load_multiple(), specifying IDs.
// Ensure they are returned in the same order as the original array.
$vocabularies = Vocabulary::loadMultiple(array(
$vocabulary3
->id(),
$vocabulary2
->id(),
$vocabulary1
->id(),
));
$loaded_order = array_keys($vocabularies);
$expected_order = array(
$vocabulary3
->id(),
$vocabulary2
->id(),
$vocabulary1
->id(),
);
$this
->assertIdentical($loaded_order, $expected_order);
// Test loading vocabularies by their properties.
$controller = $this->container
->get('entity.manager')
->getStorage('taxonomy_vocabulary');
// Fetch vocabulary 1 by name.
$vocabulary = current($controller
->loadByProperties(array(
'name' => $vocabulary1
->label(),
)));
$this
->assertEqual($vocabulary
->id(), $vocabulary1
->id(), 'Vocabulary loaded successfully by name.');
// Fetch vocabulary 2 by name and ID.
$vocabulary = current($controller
->loadByProperties(array(
'name' => $vocabulary2
->label(),
'vid' => $vocabulary2
->id(),
)));
$this
->assertEqual($vocabulary
->id(), $vocabulary2
->id(), 'Vocabulary loaded successfully by name and ID.');
}