You are here

public function EntityQueryTest::testNestedConditionGroups in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testNestedConditionGroups()

Tests that nested condition groups work as expected.

File

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

Class

EntityQueryTest
Tests Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testNestedConditionGroups() {

  // Query for all entities of the first bundle that have either a red
  // triangle as a figure or the Turkish greeting as a greeting.
  $query = $this->storage
    ->getQuery()
    ->accessCheck(FALSE);
  $first_and = $query
    ->andConditionGroup()
    ->condition($this->figures . '.color', 'red')
    ->condition($this->figures . '.shape', 'triangle');
  $second_and = $query
    ->andConditionGroup()
    ->condition($this->greetings . '.value', 'merhaba')
    ->condition($this->greetings . '.format', 'format-tr');
  $or = $query
    ->orConditionGroup()
    ->condition($first_and)
    ->condition($second_and);
  $this->queryResults = $query
    ->condition($or)
    ->condition('type', reset($this->bundles))
    ->sort('id')
    ->execute();
  $this
    ->assertResult(4, 6, 12, 14);
}