class TermEntityQueryTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Kernel/TermEntityQueryTest.php \Drupal\Tests\taxonomy\Kernel\TermEntityQueryTest
- 10 core/modules/taxonomy/tests/src/Kernel/TermEntityQueryTest.php \Drupal\Tests\taxonomy\Kernel\TermEntityQueryTest
- 8.9.x core/modules/taxonomy/tests/src/Kernel/TermEntityQueryTest.php \Drupal\Tests\taxonomy\Kernel\TermEntityQueryTest
Verifies operation of a taxonomy-based Entity Query.
@group taxonomy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\taxonomy\Kernel\TermEntityQueryTest uses \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TermEntityQueryTest
File
-
core/
modules/ taxonomy/ tests/ src/ Kernel/ TermEntityQueryTest.php, line 13
Namespace
Drupal\Tests\taxonomy\KernelView source
class TermEntityQueryTest extends KernelTestBase {
use TaxonomyTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'field',
'filter',
'taxonomy',
'text',
'user',
];
/**
* Tests that a basic taxonomy entity query works.
*/
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());
// Create a second vocabulary and five more terms.
$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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.