You are here

public function PrepareExecutionMetadataStateTest::testPreparingUntil in Rules 8.3

Tests partial state setup until an expression is reached in the tree.

File

tests/src/Unit/Integration/Engine/PrepareExecutionMetadataStateTest.php, line 38

Class

PrepareExecutionMetadataStateTest
Tests that the setup of the execution metadata state for an expression works.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

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);
}