OrExpressionTest.php in Rules 8.3
File
tests/src/Unit/OrExpressionTest.php
View source
<?php
namespace Drupal\Tests\rules\Unit;
use Drupal\rules\Context\ExecutionStateInterface;
use Drupal\rules\Engine\ConditionExpressionInterface;
use Drupal\rules\Plugin\RulesExpression\OrExpression;
use Prophecy\Argument;
class OrExpressionTest extends RulesUnitTestBase {
protected $or;
protected function setUp() : void {
parent::setUp();
$this->or = new OrExpression([], '', [
'label' => 'Condition set (OR)',
], $this->expressionManager
->reveal(), $this->rulesDebugLogger
->reveal());
}
public function testOneCondition() {
$this->trueConditionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
$this->or
->addExpressionObject($this->trueConditionExpression
->reveal());
$this
->assertTrue($this->or
->execute(), 'Single condition returns TRUE.');
}
public function testEmptyOr() {
$property = new \ReflectionProperty($this->or, 'conditions');
$property
->setAccessible(TRUE);
$this
->assertEmpty($property
->getValue($this->or));
$this
->assertTrue($this->or
->execute(), 'Empty OR returns TRUE.');
}
public function testTwoConditions() {
$this->trueConditionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
$second_condition = $this
->prophesize(ConditionExpressionInterface::class);
$second_condition
->getUuid()
->willReturn('true_uuid2');
$second_condition
->getWeight()
->willReturn(0);
$second_condition
->executeWithState(Argument::type(ExecutionStateInterface::class))
->willReturn(TRUE)
->shouldNotBeCalled();
$this->or
->addExpressionObject($this->trueConditionExpression
->reveal())
->addExpressionObject($second_condition
->reveal());
$this
->assertTrue($this->or
->execute(), 'Two conditions returns TRUE.');
}
public function testTwoFalseConditions() {
$this->falseConditionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
$second_condition = $this
->prophesize(ConditionExpressionInterface::class);
$second_condition
->getUuid()
->willReturn('false_uuid2');
$second_condition
->getWeight()
->willReturn(0);
$second_condition
->executeWithState(Argument::type(ExecutionStateInterface::class))
->willReturn(FALSE)
->shouldBeCalledTimes(1);
$this->or
->addExpressionObject($this->falseConditionExpression
->reveal())
->addExpressionObject($second_condition
->reveal());
$this
->assertFalse($this->or
->execute(), 'Two false conditions return FALSE.');
}
}