You are here

public function IntegrityCheckTest::testInputRestriction in Rules 8.3

Tests the input restriction on contexts.

File

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

Class

IntegrityCheckTest
Test the integrity check functionality during configuration time.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testInputRestriction() {
  $rule = $this->rulesExpressionManager
    ->createRule();
  $action = $this->rulesExpressionManager
    ->createAction('rules_entity_fetch_by_id', ContextConfig::create()
    ->map('type', 'variable_1')
    ->setValue('entity_id', 1));
  $rule
    ->addExpressionObject($action);
  $violation_list = RulesComponent::create($rule)
    ->addContextDefinition('variable_1', ContextDefinition::create('string'))
    ->checkIntegrity();
  $this
    ->assertEquals(1, iterator_count($violation_list));
  $this
    ->assertEquals('The context <em class="placeholder">Entity type</em> may not be configured using a selector.', (string) $violation_list[0]
    ->getMessage());
  $this
    ->assertEquals($action
    ->getUuid(), $violation_list[0]
    ->getUuid());
}