Chris@0: drupalLogin($this->drupalCreateUser(['administer taxonomy'])); Chris@0: $this->vocabulary = $this->createVocabulary(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that a basic taxonomy entity query works. Chris@0: */ Chris@0: public function testTaxonomyEfq() { Chris@0: $terms = []; Chris@0: for ($i = 0; $i < 5; $i++) { Chris@0: $term = $this->createTerm($this->vocabulary); Chris@0: $terms[$term->id()] = $term; Chris@0: } Chris@0: $result = \Drupal::entityQuery('taxonomy_term')->execute(); Chris@0: sort($result); Chris@0: $this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.'); Chris@0: $tid = reset($result); Chris@0: $ids = (object) [ Chris@0: 'entity_type' => 'taxonomy_term', Chris@0: 'entity_id' => $tid, Chris@0: 'bundle' => $this->vocabulary->id(), Chris@0: ]; Chris@0: $term = _field_create_entity_from_ids($ids); Chris@0: $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.'); Chris@0: Chris@0: // Create a second vocabulary and five more terms. Chris@0: $vocabulary2 = $this->createVocabulary(); Chris@0: $terms2 = []; Chris@0: for ($i = 0; $i < 5; $i++) { Chris@0: $term = $this->createTerm($vocabulary2); Chris@0: $terms2[$term->id()] = $term; Chris@0: } Chris@0: Chris@0: $result = \Drupal::entityQuery('taxonomy_term') Chris@0: ->condition('vid', $vocabulary2->id()) Chris@0: ->execute(); Chris@0: sort($result); Chris@0: $this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', ['%name' => $vocabulary2->label()])); Chris@0: $tid = reset($result); Chris@0: $ids = (object) [ Chris@0: 'entity_type' => 'taxonomy_term', Chris@0: 'entity_id' => $tid, Chris@0: 'bundle' => $vocabulary2->id(), Chris@0: ]; Chris@0: $term = _field_create_entity_from_ids($ids); Chris@0: $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.'); Chris@0: } Chris@0: Chris@0: }