You are here

public function PrepareExecutionMetadataStateTest::testPrepareInLoop in Rules 8.3

Tests that state preparation also works for actions in a loop.

File

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

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 testPrepareInLoop() {
  $rule = $this->rulesExpressionManager
    ->createRule();
  $loop = $this->rulesExpressionManager
    ->createInstance('rules_loop', [
    'list' => 'string_list',
  ]);
  $action = $this->rulesExpressionManager
    ->createAction('rules_test_string')
    ->setConfiguration(ContextConfig::create()
    ->setValue('text', 'x')
    ->toArray());
  $loop
    ->addExpressionObject($action);
  $rule
    ->addExpressionObject($loop);
  $state = RulesComponent::create($rule)
    ->addContextDefinition('string_list', ContextDefinition::create('string')
    ->setMultiple())
    ->getMetadataState();
  $found = $rule
    ->prepareExecutionMetadataState($state, $action);
  $this
    ->assertTrue($state
    ->hasDataDefinition('list_item'));
  $this
    ->assertTrue($found);
}