function AndExpressionTest::testEvaluationOrder

Tests evaluation order with two conditions.

File

tests/src/Unit/AndExpressionTest.php, line 106

Class

AndExpressionTest
@coversDefaultClass \Drupal\rules\Plugin\RulesExpression\AndExpression @group Rules

Namespace

Drupal\Tests\rules\Unit

Code

public function testEvaluationOrder() {
    // The method on the false test condition must be called once.
    $this->falseConditionExpression
        ->executeWithState(Argument::type(ExecutionStateInterface::class))
        ->shouldBeCalledTimes(1);
    // Set weight to 1 so it will be evaluated second.
    $this->falseConditionExpression
        ->getWeight()
        ->willReturn(1);
    $second_condition = $this->prophesize(ConditionExpressionInterface::class);
    $second_condition->getUuid()
        ->willReturn('true_uuid2');
    $second_condition->getWeight()
        ->willReturn(0);
    // If the above false condition is evaluated first, the second condition
    // will not be called. If the evaluation order is correct, then it should
    // be called exactly once.
    $second_condition->executeWithState(Argument::type(ExecutionStateInterface::class))
        ->willReturn(TRUE)
        ->shouldBeCalledTimes(1);
    // Second condition should be called first, because of weight.
    $this->and
        ->addExpressionObject($this->falseConditionExpression
        ->reveal())
        ->addExpressionObject($second_condition->reveal());
    $this->assertFalse($this->and
        ->execute(), 'Correct execution order of conditions.');
}