function LoopTest::testWrongVariableInAction

Tests that a variable used in an action within the loop exists.

File

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

Class

LoopTest
Test Rules execution with the loop plugin.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testWrongVariableInAction() {
    $rule = $this->rulesExpressionManager
        ->createRule();
    $loop = $this->rulesExpressionManager
        ->createInstance('rules_loop', [
        'list' => 'string_list',
    ]);
    $loop->addAction('rules_test_string', ContextConfig::create()->map('text', 'unknown_variable'));
    $rule->addExpressionObject($loop);
    $violations = RulesComponent::create($rule)->addContextDefinition('string_list', ContextDefinition::create('string')->setMultiple())
        ->checkIntegrity();
    $this->assertCount(1, $violations);
    // The Exception message part of the output should be HTML-escaped.
    $this->assertEquals("Data selector <em class=\"placeholder\">unknown_variable</em> for context <em class=\"placeholder\">Text to concatenate</em> is invalid. Unable to get variable &#039;unknown_variable&#039;; it is not defined.", (string) $violations[0]->getMessage());
}