You are here

public function EntityQueryAggregateTest::testRepeatedExecution in Drupal 9

Same name and namespace in other branches
  1. 8 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 591

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,
    ],
  ]);
}