/** * Tests that removing expressions by indices works. */ public function testDeletingExpressions() { // Create a rule with 2 conditions and 2 actions. $this->rule->addExpressionObject($this->trueConditionExpression->reveal()); $this->rule->addExpressionObject($this->falseConditionExpression->reveal()); $this->rule->addExpressionObject($this->testActionExpression->reveal()); $second_action = $this->prophesize(RulesAction::class); $second_action->getUuid()->willReturn('action_uuid2'); $this->rule->addExpressionObject($second_action->reveal()); // Delete the first action. $uuid = $this->testActionExpression->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(2, count($this->rule->getConditions()->getIterator())); $this->assertEquals(1, count($this->rule->getActions()->getIterator())); // Delete the second condition. $uuid = $this->falseConditionExpression->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(1, count($this->rule->getConditions()->getIterator())); $this->assertEquals(1, count($this->rule->getActions()->getIterator())); // Delete the remaining action. $uuid = $second_action->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(1, count($this->rule->getConditions()->getIterator())); $this->assertEquals(0, count($this->rule->getActions()->getIterator())); // Delete the remaining condition, rule should be empty now. $uuid = $this->trueConditionExpression->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(0, count($this->rule->getConditions()->getIterator())); $this->assertEquals(0, count($this->rule->getActions()->getIterator())); }
/** * Tests that nested rules are properly executed. * * @covers ::execute */ public function testNestedRules() { $this->testActionExpression->executeWithState(Argument::type(RulesStateInterface::class))->shouldBeCalledTimes(1); $nested = new Rule([], 'rules_rule', [], $this->expressionManager->reveal()); // We need to replace the action and conditon container to not have the same // instances as in the outer rule. $nested->setConditions(new RulesAnd([], 'rules_and', [], $this->expressionManager->reveal())); $nested->setActions(new ActionSet([], 'rules_action_set', [], $this->expressionManager->reveal())); $nested->addExpressionObject($this->trueConditionExpression->reveal())->addExpressionObject($this->testActionExpression->reveal()); $this->rule->addExpressionObject($this->trueConditionExpression->reveal())->addExpressionObject($nested)->execute(); }