You are here

public function IntegrityCheckTest::testComplexTypeViolation in Rules 8.3

Tests that a complex data context is assigned something that matches.

File

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

Class

IntegrityCheckTest
Test the integrity check functionality during configuration time.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

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

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