You are here

public function EntityQueryTest::testNestedConditionGroups in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityQueryTest.php \Drupal\system\Tests\Entity\EntityQueryTest::testNestedConditionGroups()

Tests that nested condition groups work as expected.

File

core/modules/system/src/Tests/Entity/EntityQueryTest.php, line 494
Contains \Drupal\system\Tests\Entity\EntityQueryTest.

Class

EntityQueryTest
Tests Entity Query functionality.

Namespace

Drupal\system\Tests\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->factory
    ->get('entity_test_mulrev');
  $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(6, 14);
}