Esempio n. 1
0
 /**
  * Constructs a new class instance.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param array $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\rules\Engine\ExpressionManagerInterface $expression_manager
  *   The rules expression plugin manager.
  * @param \Drupal\rules\Engine\RulesEventManager $event_manager
  *   The Rules event manager.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ExpressionManagerInterface $expression_manager, RulesEventManager $event_manager)
 {
     // @todo Reaction rules should also work with multiple events.
     if (isset($configuration['event'])) {
         $event_definition = $event_manager->getDefinition($configuration['event']);
         if (!empty($event_definition['context'])) {
             $plugin_definition['context'] = $event_definition['context'];
         }
     }
     parent::__construct($configuration, $plugin_id, $plugin_definition, $expression_manager);
 }
Esempio n. 2
0
 /**
  * Tests that nested rules are properly executed.
  *
  * @covers ::execute
  */
 public function testNestedRules()
 {
     $this->testActionExpression->executeWithState(Argument::type(ExecutionStateInterface::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();
 }
Esempio n. 3
0
 /**
  * Tests that provided context definitons are created from configuration.
  */
 public function testProvidedDefinitionFromConfig()
 {
     $rule = new Rule(['provided_definitions' => ['node' => ContextDefinition::create('entity:node')->setLabel('node')->toArray()]], 'rules_rule', [], $this->expressionManager->reveal());
     $provided_definition = $rule->getProvidedContextDefinition('node');
     $this->assertSame($provided_definition->getDataType(), 'entity:node');
 }