function TaxonomyEFQTestCase::testTaxonomyEFQ in Drupal 7
Tests that a basic taxonomy EntityFieldQuery works.
File
- modules/
taxonomy/ taxonomy.test, line 1955 - Tests for taxonomy.module.
Class
- TaxonomyEFQTestCase
- Tests the functionality of EntityFieldQuery for taxonomy entities.
Code
function testTaxonomyEFQ() {
$terms = array();
for ($i = 0; $i < 5; $i++) {
$term = $this
->createTerm($this->vocabulary);
$terms[$term->tid] = $term;
}
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'taxonomy_term');
$result = $query
->execute();
$result = $result['taxonomy_term'];
asort($result);
$this
->assertEqual(array_keys($terms), array_keys($result), 'Taxonomy terms were retrieved by EntityFieldQuery.');
// Create a second vocabulary and five more terms.
$vocabulary2 = $this
->createVocabulary();
$terms2 = array();
for ($i = 0; $i < 5; $i++) {
$term = $this
->createTerm($vocabulary2);
$terms2[$term->tid] = $term;
}
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'taxonomy_term');
$query
->entityCondition('bundle', $vocabulary2->machine_name);
$result = $query
->execute();
$result = $result['taxonomy_term'];
asort($result);
$this
->assertEqual(array_keys($terms2), array_keys($result), format_string('Taxonomy terms from the %name vocabulary were retrieved by EntityFieldQuery.', array(
'%name' => $vocabulary2->name,
)));
}