function TaxonomyEFQTestCase::testTaxonomyEFQ

Tests that a basic taxonomy EntityFieldQuery works.

File

modules/taxonomy/taxonomy.test, line 2079

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,
    )));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.