function EntityQueryAggregateTest::testRepeatedExecution

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php \Drupal\KernelTests\Core\Entity\EntityQueryAggregateTest::testRepeatedExecution()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php \Drupal\KernelTests\Core\Entity\EntityQueryAggregateTest::testRepeatedExecution()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php \Drupal\KernelTests\Core\Entity\EntityQueryAggregateTest::testRepeatedExecution()

Tests preparing a query and executing twice.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php, line 594

Class

EntityQueryAggregateTest
Tests the Entity Query Aggregation API.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testRepeatedExecution() {
    $query = $this->entityStorage
        ->getAggregateQuery()
        ->accessCheck(FALSE)
        ->groupBy('user_id');
    $this->queryResult = $query->execute();
    $this->assertResults([
        [
            'user_id' => 1,
        ],
        [
            'user_id' => 2,
        ],
        [
            'user_id' => 3,
        ],
    ]);
    $entity = $this->entityStorage
        ->create([
        'id' => 7,
        'user_id' => 4,
        'field_test_1' => 42,
        'field_test_2' => 68,
    ]);
    $entity->enforceIsNew();
    $entity->save();
    $this->queryResult = $query->execute();
    $this->assertResults([
        [
            'user_id' => 1,
        ],
        [
            'user_id' => 2,
        ],
        [
            'user_id' => 3,
        ],
        [
            'user_id' => 4,
        ],
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.