You are here

protected function EntityQueryAggregateTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php \Drupal\system\Tests\Entity\EntityQueryAggregateTest::setUp()

Performs setup tasks before each individual test method is run.

Overrides EntityUnitTestBase::setUp

File

core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php, line 45
Contains \Drupal\system\Tests\Entity\EntityQueryAggregateTest.

Class

EntityQueryAggregateTest
Tests the Entity Query Aggregation API.

Namespace

Drupal\system\Tests\Entity

Code

protected function setUp() {
  parent::setUp();
  $this->entityStorage = $this->entityManager
    ->getStorage('entity_test');
  $this->factory = $this->container
    ->get('entity.query');

  // Add some fieldapi fields to be used in the test.
  for ($i = 1; $i <= 2; $i++) {
    $field_name = 'field_test_' . $i;
    entity_create('field_storage_config', array(
      'field_name' => $field_name,
      'entity_type' => 'entity_test',
      'type' => 'integer',
      'cardinality' => 2,
    ))
      ->save();
    entity_create('field_config', array(
      'field_name' => $field_name,
      'entity_type' => 'entity_test',
      'bundle' => 'entity_test',
    ))
      ->save();
  }
  $entity = $this->entityStorage
    ->create(array(
    'id' => 1,
    'user_id' => 1,
    'field_test_1' => 1,
    'field_test_2' => 2,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $entity = $this->entityStorage
    ->create(array(
    'id' => 2,
    'user_id' => 2,
    'field_test_1' => 1,
    'field_test_2' => 7,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $entity = $this->entityStorage
    ->create(array(
    'id' => 3,
    'user_id' => 2,
    'field_test_1' => 2,
    'field_test_2' => 1,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $entity = $this->entityStorage
    ->create(array(
    'id' => 4,
    'user_id' => 2,
    'field_test_1' => 2,
    'field_test_2' => 8,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $entity = $this->entityStorage
    ->create(array(
    'id' => 5,
    'user_id' => 3,
    'field_test_1' => 2,
    'field_test_2' => 2,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $entity = $this->entityStorage
    ->create(array(
    'id' => 6,
    'user_id' => 3,
    'field_test_1' => 3,
    'field_test_2' => 8,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->save();
}