function IntegrityCheckTest::testPrimitiveTypeViolation

Tests that a primitive context is assigned something that matches.

File

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

Class

IntegrityCheckTest
Test the integrity check functionality during configuration time.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testPrimitiveTypeViolation() {
    $rule = $this->rulesExpressionManager
        ->createRule();
    // The condition expects a string but we pass a list, which will trigger the
    // violation.
    $condition = $this->rulesExpressionManager
        ->createCondition('rules_test_string_condition', ContextConfig::create()->map('text', '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 string data type for context <em class="placeholder">Text to compare</em> but got a list data type instead.', (string) $violation_list[0]->getMessage());
    $this->assertEquals($condition->getUuid(), $violation_list[0]->getUuid());
}