You are here

public function RuleExpressionTest::testNestedRules in Rules 8.3

Tests that nested rules are properly executed.

@covers ::execute

File

tests/src/Unit/RuleExpressionTest.php, line 188

Class

RuleExpressionTest
@coversDefaultClass \Drupal\rules\Plugin\RulesExpression\RuleExpression @group Rules

Namespace

Drupal\Tests\rules\Unit

Code

public function testNestedRules() {
  $this->testActionExpression
    ->executeWithState(Argument::type(ExecutionStateInterface::class))
    ->shouldBeCalledTimes(1);
  $nested = new RuleExpression([], 'rules_rule', [
    'label' => 'Rule',
  ], $this->expressionManager
    ->reveal(), $this->rulesDebugLogger
    ->reveal());

  // We need to replace the action and condition container to not have the
  // same instances as in the outer rule.
  $nested
    ->setConditions(new AndExpression([], 'rules_and', [
    'label' => 'Condition set (AND)',
  ], $this->expressionManager
    ->reveal(), $this->rulesDebugLogger
    ->reveal()));
  $nested
    ->setActions(new ActionSetExpression([], 'rules_action_set', [], $this->expressionManager
    ->reveal(), $this->rulesDebugLogger
    ->reveal()));
  $nested
    ->addExpressionObject($this->trueConditionExpression
    ->reveal())
    ->addExpressionObject($this->testActionExpression
    ->reveal());
  $this->rule
    ->addExpressionObject($this->trueConditionExpression
    ->reveal())
    ->addExpressionObject($nested)
    ->execute();
}