function ContextIntegrationTest::testAllowNullValue
Tests that NULL values for contexts are allowed if specified.
File
-
tests/
src/ Kernel/ ContextIntegrationTest.php, line 72
Class
- ContextIntegrationTest
- Tests the extended core context API with Rules.
Namespace
Drupal\Tests\rules\KernelCode
public function testAllowNullValue() {
// Configure a simple rule with the data set action which allows NULL
// values.
$action = $this->expressionManager
->createInstance('rules_action', ContextConfig::create()->setConfigKey('action_id', 'rules_data_set')
->map('data', 'null_variable')
->map('value', 'new_value')
->toArray());
$rule = $this->expressionManager
->createRule()
->addExpressionObject($action);
$component = RulesComponent::create($rule)->addContextDefinition('null_variable', ContextDefinition::create('string'))
->addContextDefinition('new_value', ContextDefinition::create('string'))
->setContextValue('null_variable', NULL)
->setContextValue('new_value', 'new value');
$component->execute();
$this->assertEquals('new value', $component->getState()
->getVariableValue('null_variable'));
}