TermEntityQueryTest.php in Drupal 10
File
core/modules/taxonomy/tests/src/Kernel/TermEntityQueryTest.php
View source
<?php
namespace Drupal\Tests\taxonomy\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class TermEntityQueryTest extends KernelTestBase {
use TaxonomyTestTrait;
protected static $modules = [
'field',
'filter',
'taxonomy',
'text',
'user',
];
public function testTermEntityQuery() {
$this
->installEntitySchema('taxonomy_term');
$vocabulary = $this
->createVocabulary();
$terms = [];
for ($i = 0; $i < 5; $i++) {
$term = $this
->createTerm($vocabulary);
$terms[$term
->id()] = $term;
}
$result = \Drupal::entityQuery('taxonomy_term')
->accessCheck(FALSE)
->execute();
sort($result);
$this
->assertEquals(array_keys($terms), $result);
$tid = reset($result);
$ids = (object) [
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'bundle' => $vocabulary
->id(),
];
$term = _field_create_entity_from_ids($ids);
$this
->assertEquals($tid, $term
->id());
$vocabulary2 = $this
->createVocabulary();
$terms2 = [];
for ($i = 0; $i < 5; $i++) {
$term = $this
->createTerm($vocabulary2);
$terms2[$term
->id()] = $term;
}
$result = \Drupal::entityQuery('taxonomy_term')
->accessCheck(FALSE)
->condition('vid', $vocabulary2
->id())
->execute();
sort($result);
$this
->assertEquals(array_keys($terms2), $result);
$tid = reset($result);
$ids = (object) [
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'bundle' => $vocabulary2
->id(),
];
$term = _field_create_entity_from_ids($ids);
$this
->assertEquals($tid, $term
->id());
}
}