function EntityQueryTest::testConditionCount

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testConditionCount()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testConditionCount()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testConditionCount()

Tests that condition count returns expected number of conditions.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php, line 621

Class

EntityQueryTest
Tests Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testConditionCount() : void {
  // Query for all entities of the first bundle that
  // have red as a color AND are triangle shaped.
  $query = $this->storage
    ->getQuery()
    ->accessCheck(FALSE);
  // Add an AND condition group with 2 conditions in it.
  $and_condition_group = $query->andConditionGroup()
    ->condition($this->figures . '.color', 'red')
    ->condition($this->figures . '.shape', 'triangle');
  // We added 2 conditions so count should be 2.
  $this->assertSame(2, $and_condition_group->count());
  // Add an OR condition group with 2 conditions in it.
  $or_condition_group = $query->orConditionGroup()
    ->condition($this->figures . '.color', 'red')
    ->condition($this->figures . '.shape', 'triangle');
  // We added 2 conditions so count should be 2.
  $this->assertSame(2, $or_condition_group->count());
}

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