function ContextIntegrationTest::testRequiredNullMapping

Tests that a required context mapping that is NULL throws an exception.

File

tests/src/Kernel/ContextIntegrationTest.php, line 20

Class

ContextIntegrationTest
Tests the extended core context API with Rules.

Namespace

Drupal\Tests\rules\Kernel

Code

public function testRequiredNullMapping() {
    // Configure a simple rule with one action.
    $action = $this->expressionManager
        ->createInstance('rules_action', ContextConfig::create()->setConfigKey('action_id', 'rules_test_string')
        ->map('text', 'null_context')
        ->toArray());
    $rule = $this->expressionManager
        ->createRule()
        ->addExpressionObject($action);
    $component = RulesComponent::create($rule)->addContextDefinition('null_context', ContextDefinition::create('string'))
        ->setContextValue('null_context', NULL);
    try {
        $component->execute();
        $this->fail('No exception thrown when required context value is NULL');
    } catch (EvaluationException $e) {
        $this->assertTrue(TRUE, 'Exception thrown as expected when a required context is NULL');
    }
}