/**
  * Tests partial state setup until an expression is reached in the tree.
  */
 public function testPreparingUntil()
 {
     // Setup a rule with 2 actions.
     $rule = $this->rulesExpressionManager->createRule();
     $rule->addAction('rules_variable_add', ContextConfig::create()->setValue('type', 'string')->setValue('value', '')->provideAs('variable_added', 'result1'));
     $second_action = $this->rulesExpressionManager->createAction('rules_variable_add')->setConfiguration(ContextConfig::create()->setValue('type', 'string')->setValue('value', '')->provideAs('variable_added', 'result2')->toArray());
     $rule->addExpressionObject($second_action);
     $state = ExecutionMetadataState::create();
     // Preparing the state until the second action means the variable of the
     // first action is available, but the second is not yet.
     $found = $rule->prepareExecutionMetadataState($state, $second_action);
     $this->assertTrue($state->hasDataDefinition('result1'));
     $this->assertFalse($state->hasDataDefinition('result2'));
     $this->assertTrue($found);
 }
 /**
  * Gets the metadata state with all context definitions as variables in it.
  *
  * Describes the metadata state before execution - only context definitions
  * are set as variables.
  *
  * @return \Drupal\rules\Engine\ExecutionMetadataStateInterface
  *   The execution metadata state populated with context definitions.
  */
 public function getMetadataState()
 {
     $data_definitions = [];
     foreach ($this->contextDefinitions as $name => $context_definition) {
         $data_definitions[$name] = $context_definition->getDataDefinition();
     }
     return ExecutionMetadataState::create($data_definitions);
 }
Exemple #3
0
 /**
  * Verifies that the given expression is valid with the defined context.
  *
  * @return \Drupal\rules\Engine\IntegrityViolationList
  *   A list object containing \Drupal\rules\Engine\IntegrityViolation objects.
  */
 public function checkIntegrity()
 {
     $data_definitions = [];
     foreach ($this->contextDefinitions as $name => $context_definition) {
         $data_definitions[$name] = $context_definition->getDataDefinition();
     }
     $metadata_state = ExecutionMetadataState::create($data_definitions);
     return $this->expression->checkIntegrity($metadata_state);
 }