class RulesConditionContainerTest in Rules 8.3
@coversDefaultClass \Drupal\rules\Engine\ConditionExpressionContainer @group Rules
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase
- class \Drupal\Tests\rules\Unit\RulesConditionContainerTest
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase
Expanded class hierarchy of RulesConditionContainerTest
File
- tests/
src/ Unit/ RulesConditionContainerTest.php, line 14
Namespace
Drupal\Tests\rules\UnitView source
class RulesConditionContainerTest extends RulesUnitTestBase {
/**
* Creates a mocked condition container.
*
* @param array $methods
* The methods to mock.
* @param string $class
* The name of the created mock class.
*
* @return \Drupal\rules\Engine\ConditionExpressionContainerInterface
* The mocked condition container.
*/
protected function getMockConditionContainer(array $methods = [], $class = 'RulesConditionContainerMock') {
return $this
->getMockForAbstractClass(ConditionExpressionContainer::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], $class, TRUE, TRUE, TRUE, $methods);
}
/**
* Tests adding conditions to the condition container.
*
* @covers ::addExpressionObject
*/
public function testAddExpressionObject() {
$container = $this
->getMockConditionContainer();
$container
->addExpressionObject($this->trueConditionExpression
->reveal());
$property = new \ReflectionProperty($container, 'conditions');
$property
->setAccessible(TRUE);
$this
->assertEquals([
$this->trueConditionExpression
->reveal(),
], array_values($property
->getValue($container)));
}
/**
* Tests negating the result of the condition container.
*
* @covers ::negate
* @covers ::isNegated
*/
public function testNegate() {
$container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [], '', FALSE);
$this
->assertFalse($container
->isNegated());
$this
->assertTrue($container
->execute());
$container
->negate(TRUE);
$this
->assertTrue($container
->isNegated());
$this
->assertFalse($container
->execute());
}
/**
* Tests executing the condition container.
*
* @covers ::execute
*/
public function testExecute() {
$container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [], '', FALSE);
$this
->assertTrue($container
->execute());
}
/**
* Tests that an expression can be retrieved by UUID.
*/
public function testLookupExpression() {
$container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], '', TRUE);
$container
->addExpressionObject($this->trueConditionExpression
->reveal());
$uuid = $this->trueConditionExpression
->reveal()
->getUuid();
$this
->assertSame($this->trueConditionExpression
->reveal(), $container
->getExpression($uuid));
$this
->assertFalse($container
->getExpression('invalid UUID'));
}
/**
* Tests that a nested expression can be retrieved by UUID.
*/
public function testLookupNestedExpression() {
$container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], '', TRUE);
$container
->addExpressionObject($this->trueConditionExpression
->reveal());
$nested_container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], '', TRUE);
$nested_container
->addExpressionObject($this->falseConditionExpression
->reveal());
$container
->addExpressionObject($nested_container);
$uuid = $this->falseConditionExpression
->reveal()
->getUuid();
$this
->assertSame($this->falseConditionExpression
->reveal(), $container
->getExpression($uuid));
}
/**
* Tests deleting a condition from the container.
*/
public function testDeletingCondition() {
$container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], '', TRUE);
$container
->addExpressionObject($this->trueConditionExpression
->reveal());
$container
->addExpressionObject($this->falseConditionExpression
->reveal());
// Delete the first condition.
$uuid = $this->trueConditionExpression
->reveal()
->getUuid();
$this
->assertTrue($container
->deleteExpression($uuid));
foreach ($container as $condition) {
$this
->assertSame($this->falseConditionExpression
->reveal(), $condition);
}
$this
->assertFalse($container
->deleteExpression('invalid UUID'));
}
/**
* Tests deleting a nested condition from the container.
*/
public function testDeletingNestedCondition() {
$container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], '', TRUE);
$container
->addExpressionObject($this->trueConditionExpression
->reveal());
$nested_container = $this
->getMockForAbstractClass(RulesConditionContainerTestStub::class, [
[],
'test_id',
[],
$this
->prophesize(ExpressionManagerInterface::class)
->reveal(),
$this
->prophesize(LoggerChannelInterface::class)
->reveal(),
], '', TRUE);
$nested_container
->addExpressionObject($this->falseConditionExpression
->reveal());
$container
->addExpressionObject($nested_container);
$uuid = $this->falseConditionExpression
->reveal()
->getUuid();
$this
->assertTrue($container
->deleteExpression($uuid));
$this
->assertEquals(0, count($nested_container
->getIterator()));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
RulesConditionContainerTest:: |
protected | function | Creates a mocked condition container. | |
RulesConditionContainerTest:: |
public | function | Tests adding conditions to the condition container. | |
RulesConditionContainerTest:: |
public | function | Tests deleting a condition from the container. | |
RulesConditionContainerTest:: |
public | function | Tests deleting a nested condition from the container. | |
RulesConditionContainerTest:: |
public | function | Tests executing the condition container. | |
RulesConditionContainerTest:: |
public | function | Tests that an expression can be retrieved by UUID. | |
RulesConditionContainerTest:: |
public | function | Tests that a nested expression can be retrieved by UUID. | |
RulesConditionContainerTest:: |
public | function | Tests negating the result of the condition container. | |
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. | |
RulesUnitTestBase:: |
protected | function |
Overrides UnitTestCase:: |
4 |
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. |