class OrExpressionTest in Rules 8.3
@coversDefaultClass \Drupal\rules\Plugin\RulesExpression\OrExpression @group Rules
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase
- class \Drupal\Tests\rules\Unit\OrExpressionTest
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase
Expanded class hierarchy of OrExpressionTest
File
- tests/
src/ Unit/ OrExpressionTest.php, line 14
Namespace
Drupal\Tests\rules\UnitView source
class OrExpressionTest extends RulesUnitTestBase {
/**
* The 'or' condition container being tested.
*
* @var \Drupal\rules\Engine\ConditionExpressionContainerInterface
*/
protected $or;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->or = new OrExpression([], '', [
'label' => 'Condition set (OR)',
], $this->expressionManager
->reveal(), $this->rulesDebugLogger
->reveal());
}
/**
* Tests one condition.
*/
public function testOneCondition() {
// The method on the test condition must be called once.
$this->trueConditionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
$this->or
->addExpressionObject($this->trueConditionExpression
->reveal());
$this
->assertTrue($this->or
->execute(), 'Single condition returns TRUE.');
}
/**
* Tests an empty OR.
*/
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.');
}
/**
* Tests two true conditions.
*/
public function testTwoConditions() {
// The method on the test condition must be called once.
$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.');
}
/**
* Tests two false conditions.
*/
public function testTwoFalseConditions() {
// The method on the test condition must be called once.
$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.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrExpressionTest:: |
protected | property | The 'or' condition container being tested. | |
OrExpressionTest:: |
protected | function |
Overrides RulesUnitTestBase:: |
|
OrExpressionTest:: |
public | function | Tests an empty OR. | |
OrExpressionTest:: |
public | function | Tests one condition. | |
OrExpressionTest:: |
public | function | Tests two true conditions. | |
OrExpressionTest:: |
public | function | Tests two false conditions. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RulesUnitTestBase:: |
protected | property | The mocked expression manager object. | 1 |
RulesUnitTestBase:: |
protected | property | A mocked condition that always evaluates to FALSE. | |
RulesUnitTestBase:: |
protected | property | The mocked expression manager object. | |
RulesUnitTestBase:: |
protected | property | A mocked dummy action object. | |
RulesUnitTestBase:: |
protected | property | A mocked dummy action object. | |
RulesUnitTestBase:: |
protected | property | A mocked condition that always evaluates to TRUE. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |