function ConfigEntityQueryTest::testCount

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testCount()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testCount()
  3. 11.x 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 431

Class

ConfigEntityQueryTest
Tests Config Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testCount() : void {
  // Test count on no conditions.
  $count = $this->entityStorage
    ->getQuery()
    ->count()
    ->execute();
  $this->assertCount($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->assertSame(2, $count);
}

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