You are here

public function ConditionTest::testComplex in Apigee Edge 8

Tests a complex condition.

File

tests/src/Unit/ConditionTest.php, line 141

Class

ConditionTest
Entity query condition tests.

Namespace

Drupal\Tests\apigee_edge\Unit

Code

public function testComplex() {
  $data0 = $this
    ->randomData();
  $data1 = $this
    ->randomData();
  $value00 = $data0[0];
  $value01 = $data0[1];
  $value10 = $data1[0];
  $value11 = $data1[1];
  $cond0 = $this
    ->mockCondition();
  $cond0
    ->condition('id', $value00);
  $cond0
    ->condition('foo_bar', $value01);
  $cond1 = $this
    ->mockCondition();
  $cond1
    ->condition('id', $value10);
  $cond1
    ->condition('foo_bar', $value11);
  $cond = $this
    ->mockCondition('OR');
  $cond
    ->condition($cond0);
  $cond
    ->condition($cond1);
  $this
    ->assertFilters($cond, function (EntityInterface $item) use ($value00, $value01, $value10, $value11) : bool {
    $id = $item
      ->id();
    $foobar = $item
      ->getFooBar();
    return $id == $value00 && $foobar == $value01 || $id == $value10 && $foobar == $value11;
  });
}