public function EntityQueryTest::testConditionCount in Drupal 9
Same name and namespace in other branches
- 8 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 600
Class
- EntityQueryTest
- Tests Entity Query functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testConditionCount() {
// 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
->assertEquals(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
->assertEquals(2, $or_condition_group
->count());
}