Backup of db before drupal security update
[yaffs-website] / web / core / modules / taxonomy / tests / src / Functional / EfqTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional;
4
5 /**
6  * Verifies operation of a taxonomy-based Entity Query.
7  *
8  * @group taxonomy
9  */
10 class EfqTest extends TaxonomyTestBase {
11
12   /**
13    * Vocabulary for testing.
14    *
15    * @var \Drupal\taxonomy\VocabularyInterface
16    */
17   protected $vocabulary;
18
19   protected function setUp() {
20     parent::setUp();
21     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
22     $this->vocabulary = $this->createVocabulary();
23   }
24
25   /**
26    * Tests that a basic taxonomy entity query works.
27    */
28   public function testTaxonomyEfq() {
29     $terms = [];
30     for ($i = 0; $i < 5; $i++) {
31       $term = $this->createTerm($this->vocabulary);
32       $terms[$term->id()] = $term;
33     }
34     $result = \Drupal::entityQuery('taxonomy_term')->execute();
35     sort($result);
36     $this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
37     $tid = reset($result);
38     $ids = (object) [
39       'entity_type' => 'taxonomy_term',
40       'entity_id' => $tid,
41       'bundle' => $this->vocabulary->id(),
42     ];
43     $term = _field_create_entity_from_ids($ids);
44     $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
45
46     // Create a second vocabulary and five more terms.
47     $vocabulary2 = $this->createVocabulary();
48     $terms2 = [];
49     for ($i = 0; $i < 5; $i++) {
50       $term = $this->createTerm($vocabulary2);
51       $terms2[$term->id()] = $term;
52     }
53
54     $result = \Drupal::entityQuery('taxonomy_term')
55       ->condition('vid', $vocabulary2->id())
56       ->execute();
57     sort($result);
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);
60     $ids = (object) [
61       'entity_type' => 'taxonomy_term',
62       'entity_id' => $tid,
63       'bundle' => $vocabulary2->id(),
64     ];
65     $term = _field_create_entity_from_ids($ids);
66     $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
67   }
68
69 }