You are here

public function LoopTest::testOutOfScopeVariable in Rules 8.3

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

File

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

Class

LoopTest
Test Rules execution with the loop plugin.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testOutOfScopeVariable() {
  $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'));
  $violations = RulesComponent::create($rule)
    ->addContextDefinition('string_list', ContextDefinition::create('string')
    ->setMultiple())
    ->checkIntegrity();
  $this
    ->assertEquals(1, iterator_count($violations));

  // The Exception message part of the output should be HTML-escaped.
  $this
    ->assertEquals("Data selector <em class=\"placeholder\">list_item</em> for context <em class=\"placeholder\">Text to concatenate</em> is invalid. Unable to get variable &#039;list_item&#039;; it is not defined.", (string) $violations[0]
    ->getMessage());
}