function IntegrityCheckTest::testComplexTypeViolation

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

File

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

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->assertCount(1, $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());
}