class ActionSetExpressionTest in Rules 8.3
@coversDefaultClass \Drupal\rules\Plugin\RulesExpression\ActionSetExpression @group Rules
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase
- class \Drupal\Tests\rules\Unit\ActionSetExpressionTest
- class \Drupal\Tests\rules\Unit\RulesUnitTestBase
Expanded class hierarchy of ActionSetExpressionTest
File
- tests/
src/ Unit/ ActionSetExpressionTest.php, line 15
Namespace
Drupal\Tests\rules\UnitView source
class ActionSetExpressionTest extends RulesUnitTestBase {
/**
* The action set being tested.
*
* @var \Drupal\rules\Plugin\RulesExpression\ActionSetExpression
*/
protected $actionSet;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// TestActionSetExpression is defined below.
$this->actionSet = new TestActionSetExpression([], '', [], $this->expressionManager
->reveal(), $this->rulesDebugLogger
->reveal());
}
/**
* Tests that an action in the set fires.
*/
public function testActionExecution() {
// The execute method on the test action must be called once.
$this->testActionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
$this->actionSet
->addExpressionObject($this->testActionExpression
->reveal())
->execute();
}
/**
* Tests that two actions in the set fire both.
*/
public function testTwoActionExecution() {
// The execute method on the test action must be called once.
$this->testActionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
// The execute method on the second action must be called once.
$second_action = $this
->prophesize(ActionExpressionInterface::class);
$second_action
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
$second_action
->getUuid()
->willReturn('uuid2');
$second_action
->getWeight()
->willReturn(0);
$this->actionSet
->addExpressionObject($this->testActionExpression
->reveal())
->addExpressionObject($second_action
->reveal())
->execute();
}
/**
* Tests that nested action sets work.
*/
public function testNestedActionExecution() {
// The execute method on the test action must be called twice.
$this->testActionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(2);
$inner = new ActionSetExpression([], '', [], $this->expressionManager
->reveal(), $this->rulesDebugLogger
->reveal());
$inner
->addExpressionObject($this->testActionExpression
->reveal());
$this->actionSet
->addExpressionObject($this->testActionExpression
->reveal())
->addExpressionObject($inner)
->execute();
}
/**
* Tests that a nested action can be retrieved by UUID.
*/
public function testLookupAction() {
$this->actionSet
->addExpressionObject($this->testActionExpression
->reveal());
$uuid = $this->testActionExpression
->reveal()
->getUuid();
$lookup_action = $this->actionSet
->getExpression($uuid);
$this
->assertSame($this->testActionExpression
->reveal(), $lookup_action);
$this
->assertFalse($this->actionSet
->getExpression('invalid UUID'));
}
/**
* Tests deleting an action from the container.
*/
public function testDeletingAction() {
$this->actionSet
->addExpressionObject($this->testActionExpression
->reveal());
$second_action = $this
->prophesize(ActionExpression::class);
$this->actionSet
->addExpressionObject($second_action
->reveal());
// Get the UUID of the first action added.
$uuid = $this->testActionExpression
->reveal()
->getUuid();
$this
->assertTrue($this->actionSet
->deleteExpression($uuid));
// Now only the second action remains.
foreach ($this->actionSet as $action) {
$this
->assertSame($second_action
->reveal(), $action);
}
}
/**
* Tests evaluation order with two actions.
*/
public function testEvaluationOrder() {
// The execute method on the second action must be called once.
$this->testActionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
// The execute method on the test action must be called once.
$this->testFirstActionExpression
->executeWithState(Argument::type(ExecutionStateInterface::class))
->shouldBeCalledTimes(1);
// The 'first' action should be called first, because of weight,
// even though it is added second.
$this->actionSet
->addExpressionObject($this->testActionExpression
->reveal())
->addExpressionObject($this->testFirstActionExpression
->reveal());
// The $result variable is a test-only variable to hold the return value
// of test actions, which normally don't return a value. We do this so we
// can verify the order of execution.
$this
->assertEquals([
'action_uuid0',
'action_uuid1',
], $this->actionSet
->execute());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionSetExpressionTest:: |
protected | property | The action set being tested. | |
ActionSetExpressionTest:: |
protected | function |
Overrides RulesUnitTestBase:: |
|
ActionSetExpressionTest:: |
public | function | Tests that an action in the set fires. | |
ActionSetExpressionTest:: |
public | function | Tests deleting an action from the container. | |
ActionSetExpressionTest:: |
public | function | Tests evaluation order with two actions. | |
ActionSetExpressionTest:: |
public | function | Tests that a nested action can be retrieved by UUID. | |
ActionSetExpressionTest:: |
public | function | Tests that nested action sets work. | |
ActionSetExpressionTest:: |
public | function | Tests that two actions in the set fire both. | |
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. |