3 namespace Drupal\Tests\taxonomy\Functional;
6 * Verifies operation of a taxonomy-based Entity Query.
10 class EfqTest extends TaxonomyTestBase {
13 * Vocabulary for testing.
15 * @var \Drupal\taxonomy\VocabularyInterface
17 protected $vocabulary;
19 protected function setUp() {
21 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
22 $this->vocabulary = $this->createVocabulary();
26 * Tests that a basic taxonomy entity query works.
28 public function testTaxonomyEfq() {
30 for ($i = 0; $i < 5; $i++) {
31 $term = $this->createTerm($this->vocabulary);
32 $terms[$term->id()] = $term;
34 $result = \Drupal::entityQuery('taxonomy_term')->execute();
36 $this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
37 $tid = reset($result);
39 'entity_type' => 'taxonomy_term',
41 'bundle' => $this->vocabulary->id(),
43 $term = _field_create_entity_from_ids($ids);
44 $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
46 // Create a second vocabulary and five more terms.
47 $vocabulary2 = $this->createVocabulary();
49 for ($i = 0; $i < 5; $i++) {
50 $term = $this->createTerm($vocabulary2);
51 $terms2[$term->id()] = $term;
54 $result = \Drupal::entityQuery('taxonomy_term')
55 ->condition('vid', $vocabulary2->id())
58 $this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', ['%name' => $vocabulary2->label()]));
59 $tid = reset($result);
61 'entity_type' => 'taxonomy_term',
63 'bundle' => $vocabulary2->id(),
65 $term = _field_create_entity_from_ids($ids);
66 $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');