You are here

public function IntegrityCheckTest::testListTypeViolation in Rules 8.3

Tests that a list context is assigned something that matches.

File

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

Class

IntegrityCheckTest
Test the integrity check functionality during configuration time.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

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

  // The condition expects a list for the type context but we pass a node
  // which will trigger the violation.
  $condition = $this->rulesExpressionManager
    ->createCondition('rules_node_is_of_type', ContextConfig::create()
    ->map('node', 'node')
    ->map('types', 'node'));
  $rule
    ->addExpressionObject($condition);
  $violation_list = RulesComponent::create($rule)
    ->addContextDefinition('node', ContextDefinition::create('entity:node'))
    ->checkIntegrity();
  $this
    ->assertEquals(1, iterator_count($violation_list));
  $this
    ->assertEquals('Expected a list data type for context <em class="placeholder">Content types</em> but got a entity:node data type instead.', (string) $violation_list[0]
    ->getMessage());
  $this
    ->assertEquals($condition
    ->getUuid(), $violation_list[0]
    ->getUuid());
}