function EntityQueryAggregateTest::testAlterHook
Tests that entity query alter hooks are invoked for aggregate queries.
Hook functions in field_test.module add additional conditions to the query removing entities with specific ids.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityQueryAggregateTest.php, line 630
Class
- EntityQueryAggregateTest
- Tests the Entity Query Aggregation API.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testAlterHook() : void {
$basicQuery = $this->entityStorage
->getAggregateQuery()
->accessCheck(FALSE)
->groupBy('id');
// Verify assumptions about the unaltered result.
$query = clone $basicQuery;
$this->queryResult = $query->execute();
$this->assertResults([
[
'id' => 1,
],
[
'id' => 2,
],
[
'id' => 3,
],
[
'id' => 4,
],
[
'id' => 5,
],
[
'id' => 6,
],
]);
// field_test_entity_query_alter() removes the entity with id '5'.
$query = clone $basicQuery;
$this->queryResult = $query->addTag('entity_query_alter_hook_test')
->execute();
$this->assertResults([
[
'id' => 1,
],
[
'id' => 2,
],
[
'id' => 3,
],
[
'id' => 4,
],
[
'id' => 6,
],
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.