public function LoopTest::testWrongVariableInAction in Rules 8.3
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\EngineCode
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
->assertEquals(1, iterator_count($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 'unknown_variable'; it is not defined.", (string) $violations[0]
->getMessage());
}