You are here

public function ConfigEntityQueryTest::testCount in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testCount()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testCount()

Tests count query.

File

core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php, line 429

Class

ConfigEntityQueryTest
Tests Config Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testCount() {

  // Test count on no conditions.
  $count = $this->entityStorage
    ->getQuery()
    ->count()
    ->execute();
  $this
    ->assertIdentical($count, count($this->entities));

  // Test count on a complex query.
  $query = $this->entityStorage
    ->getQuery('OR');
  $and_condition_1 = $query
    ->andConditionGroup()
    ->condition('id', 1)
    ->condition('label', $this->entities[0]->label);
  $and_condition_2 = $query
    ->andConditionGroup()
    ->condition('id', '2')
    ->condition('label', $this->entities[1]->label);
  $count = $query
    ->condition($and_condition_1)
    ->condition($and_condition_2)
    ->count()
    ->execute();
  $this
    ->assertIdentical($count, 2);
}