public function ConfigEntityQueryTest::testCount in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testCount()
- 9 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\EntityCode
public function testCount() {
  // 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);
}