function EntityQueryAggregateTest::setUp

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

Overrides EntityKernelTestBase::setUp

File

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

Class

EntityQueryAggregateTest
Tests the Entity Query Aggregation API.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function setUp() : void {
    parent::setUp();
    $this->entityStorage = $this->entityTypeManager
        ->getStorage('entity_test');
    // Add some fieldapi fields to be used in the test.
    for ($i = 1; $i <= 2; $i++) {
        $field_name = 'field_test_' . $i;
        FieldStorageConfig::create([
            'field_name' => $field_name,
            'entity_type' => 'entity_test',
            'type' => 'integer',
            'cardinality' => 2,
        ])->save();
        FieldConfig::create([
            'field_name' => $field_name,
            'entity_type' => 'entity_test',
            'bundle' => 'entity_test',
        ])->save();
    }
    $entity = $this->entityStorage
        ->create([
        'id' => 1,
        'user_id' => 1,
        'field_test_1' => 1,
        'field_test_2' => 2,
    ]);
    $entity->enforceIsNew();
    $entity->save();
    $entity = $this->entityStorage
        ->create([
        'id' => 2,
        'user_id' => 2,
        'field_test_1' => 1,
        'field_test_2' => 7,
    ]);
    $entity->enforceIsNew();
    $entity->save();
    $entity = $this->entityStorage
        ->create([
        'id' => 3,
        'user_id' => 2,
        'field_test_1' => 2,
        'field_test_2' => 1,
    ]);
    $entity->enforceIsNew();
    $entity->save();
    $entity = $this->entityStorage
        ->create([
        'id' => 4,
        'user_id' => 2,
        'field_test_1' => 2,
        'field_test_2' => 8,
    ]);
    $entity->enforceIsNew();
    $entity->save();
    $entity = $this->entityStorage
        ->create([
        'id' => 5,
        'user_id' => 3,
        'field_test_1' => 2,
        'field_test_2' => 2,
    ]);
    $entity->enforceIsNew();
    $entity->save();
    $entity = $this->entityStorage
        ->create([
        'id' => 6,
        'user_id' => 3,
        'field_test_1' => 3,
        'field_test_2' => 8,
    ]);
    $entity->enforceIsNew();
    $entity->save();
}

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