You are here

public function IntegrityCheckTest::testUnknownVariable in Rules 8.3

Tests that a wrongly configured variable name triggers a violation.

File

tests/src/Unit/Integration/Engine/IntegrityCheckTest.php, line 36

Class

IntegrityCheckTest
Test the integrity check functionality during configuration time.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testUnknownVariable() {
  $rule = $this->rulesExpressionManager
    ->createRule();
  $action = $this->rulesExpressionManager
    ->createAction('rules_entity_save', ContextConfig::create()
    ->map('entity', 'unknown_variable'));
  $rule
    ->addExpressionObject($action);
  $violation_list = RulesComponent::create($rule)
    ->checkIntegrity();
  $this
    ->assertEquals(1, iterator_count($violation_list));
  $violation = $violation_list[0];

  // 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\">Entity</em> is invalid. Unable to get variable &#039;unknown_variable&#039;; it is not defined.", (string) $violation
    ->getMessage());
  $this
    ->assertEquals($action
    ->getUuid(), $violation
    ->getUuid());
}