class OrExpressionTest
@coversDefaultClass \Drupal\rules\Plugin\RulesExpression\OrExpression @group Rules
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\rules\Unit\OrExpressionTest extends \Drupal\Tests\rules\Unit\RulesUnitTestBase
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase extends \Drupal\Tests\UnitTestCase
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
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
OrExpressionTest::$or | protected | property | The 'or' condition container being tested. | |||
OrExpressionTest::setUp | protected | function | Overrides RulesUnitTestBase::setUp | |||
OrExpressionTest::testEmptyOr | public | function | Tests an empty OR. | |||
OrExpressionTest::testOneCondition | public | function | Tests one condition. | |||
OrExpressionTest::testTwoConditions | public | function | Tests two true conditions. | |||
OrExpressionTest::testTwoFalseConditions | public | function | Tests two false conditions. | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RulesUnitTestBase::$expressionManager | protected | property | The mocked expression manager object. | 1 | ||
RulesUnitTestBase::$falseConditionExpression | protected | property | A mocked condition that always evaluates to FALSE. | |||
RulesUnitTestBase::$rulesDebugLogger | protected | property | The mocked expression manager object. | |||
RulesUnitTestBase::$testActionExpression | protected | property | A mocked dummy action object. | |||
RulesUnitTestBase::$testFirstActionExpression | protected | property | A mocked dummy action object. | |||
RulesUnitTestBase::$trueConditionExpression | protected | property | A mocked condition that always evaluates to TRUE. | |||
UnitTestCase::$randomGenerator | protected | property | The random generator. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | |||
UnitTestCase::setUpBeforeClass | public static | function |