function EntityQueryAggregateTest::testCloneAggregateIsolation
Same name and namespace in other branches
- main core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php \Drupal\KernelTests\Core\Entity\EntityQueryAggregateTest::testCloneAggregateIsolation()
Tests that cloning an aggregate query isolates its aggregate conditions.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityQueryAggregateTest.php, line 668
Class
- EntityQueryAggregateTest
- Tests the Entity Query Aggregation API.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testCloneAggregateIsolation() : void {
// Original query: groups with id count > 1 are user 2 (3 rows) and user 3
// (2 rows).
$original = $this->entityStorage
->getAggregateQuery()
->accessCheck(FALSE)
->aggregate('id', 'count')
->groupBy('user_id')
->conditionAggregate('id', 'count', 1, '>');
$clone = clone $original;
// Tightening the clone must not affect the original's conditions.
$clone->conditionAggregate('id', 'count', 2, '>');
$this->queryResult = $original->execute();
$this->assertCount(2, $this->queryResult);
$this->assertResults([
[
'user_id' => 2,
'id_count' => 3,
],
[
'user_id' => 3,
'id_count' => 2,
],
]);
$this->queryResult = $clone->execute();
$this->assertCount(1, $this->queryResult);
$this->assertResults([
[
'user_id' => 2,
'id_count' => 3,
],
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.