function LoopTest::testOutOfScopeVariableExecution

Tests that the loop list item variable is not available after the loop.

File

tests/src/Unit/Integration/Engine/LoopTest.php, line 303

Class

LoopTest
Test Rules execution with the loop plugin.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testOutOfScopeVariableExecution() {
    // Set the expected exception class and message.
    $this->expectException(EvaluationException::class);
    $this->expectExceptionMessage("Unable to get variable 'list_item'; it is not defined.");
    $rule = $this->rulesExpressionManager
        ->createRule();
    $loop = $this->rulesExpressionManager
        ->createInstance('rules_loop', [
        'list' => 'string_list',
    ]);
    $rule->addExpressionObject($loop);
    $rule->addAction('rules_test_string', ContextConfig::create()->map('text', 'list_item'));
    RulesComponent::create($rule)->addContextDefinition('string_list', ContextDefinition::create('string')->setMultiple())
        ->setContextValue('string_list', [
        'one',
        'two',
    ])
        ->execute();
}