You are here

public function LoopTest::testItemNameConflict in Rules 8.3

Test the integrity check for loop item names that conflict with others.

File

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

Class

LoopTest
Test Rules execution with the loop plugin.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testItemNameConflict() {
  $rule = $this->rulesExpressionManager
    ->createRule();
  $loop = $this->rulesExpressionManager
    ->createInstance('rules_loop', [
    'list' => 'string_list',
    'list_item' => 'existing_name',
  ]);
  $rule
    ->addExpressionObject($loop);
  $violations = RulesComponent::create($rule)
    ->addContextDefinition('string_list', ContextDefinition::create('string')
    ->setMultiple())
    ->addContextDefinition('existing_name', ContextDefinition::create('string'))
    ->checkIntegrity();
  $this
    ->assertEquals(1, iterator_count($violations));
  $this
    ->assertEquals('List item name <em class="placeholder">existing_name</em> conflicts with an existing variable.', (string) $violations[0]
    ->getMessage());
}