function ConfigEntityTest::testContextDefinitionExport
Make sure that expressions using context definitions can be exported.
File
-
tests/
src/ Kernel/ ConfigEntityTest.php, line 99
Class
- ConfigEntityTest
- Tests storage and loading of Rules config entities.
Namespace
Drupal\Tests\rules\KernelCode
public function testContextDefinitionExport() {
$component = RulesComponent::create($this->expressionManager
->createRule())
->addContextDefinition('test', ContextDefinition::create('string')->setLabel('Test string'));
$config_entity = $this->storage
->create([
'id' => 'test_rule',
])
->updateFromComponent($component);
$config_entity->save();
$loaded_entity = $this->storage
->load('test_rule');
// Create the Rules expression object from the configuration.
$expression = $loaded_entity->getExpression();
$this->assertInstanceOf(RuleExpression::class, $expression);
$context_definitions = $loaded_entity->getContextDefinitions();
$this->assertEquals($context_definitions['test']->getDataType(), 'string', 'Data type of context definition is correct.');
$this->assertEquals($context_definitions['test']->getLabel(), 'Test string', 'Label of context definition is correct.');
}