You are here

public function IntegrityCheckTest::testMissingRequiredContext in Rules 8.3

Tests that an absent required context triggers a violation.

File

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

Class

IntegrityCheckTest
Test the integrity check functionality during configuration time.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testMissingRequiredContext() {
  $rule = $this->rulesExpressionManager
    ->createRule();

  // The condition is completely un-configured, missing 2 required contexts.
  $condition = $this->rulesExpressionManager
    ->createCondition('rules_node_is_of_type');
  $rule
    ->addExpressionObject($condition);
  $violation_list = RulesComponent::create($rule)
    ->checkIntegrity();
  $this
    ->assertEquals(2, iterator_count($violation_list));
  $this
    ->assertEquals('The required context <em class="placeholder">Node</em> is missing.', (string) $violation_list[0]
    ->getMessage());
  $this
    ->assertEquals('The required context <em class="placeholder">Content types</em> is missing.', (string) $violation_list[1]
    ->getMessage());
  $this
    ->assertEquals($condition
    ->getUuid(), $violation_list[0]
    ->getUuid());
  $this
    ->assertEquals($condition
    ->getUuid(), $violation_list[1]
    ->getUuid());
}