You are here

public function ContextIntegrationTest::testRequiredNullValue in Rules 8.3

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

File

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

Class

ContextIntegrationTest
Tests the extended core context API with Rules.

Namespace

Drupal\Tests\rules\Kernel

Code

public function testRequiredNullValue() {

  // Configure a simple rule with one action. The required 'text' context is
  // set to be NULL.
  $action = $this->expressionManager
    ->createInstance('rules_action', ContextConfig::create()
    ->setConfigKey('action_id', 'rules_test_string')
    ->setValue('text', NULL)
    ->toArray());
  $rule = $this->expressionManager
    ->createRule();
  $rule
    ->addExpressionObject($action);
  try {
    $rule
      ->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');
  }
}