public function RulesEngineTest::testActionProvidedContext in Rules 8.3
Tests that multiple actions can consume and provide context variables.
File
- tests/
src/ Kernel/ RulesEngineTest.php, line 140
Class
- RulesEngineTest
- Test using the Rules API to create and evaluate rules.
Namespace
Drupal\Tests\rules\KernelCode
public function testActionProvidedContext() {
// @todo Convert the test to make use of actions instead of conditions.
$rule = $this->expressionManager
->createRule();
// The condition provides a "provided_text" variable.
$rule
->addCondition('rules_test_provider');
// The action provides a "concatenated" variable.
$rule
->addAction('rules_test_string', ContextConfig::create()
->map('text', 'provided_text'));
// Add the same action again which will provide a "concatenated2" variable
// now.
$rule
->addAction('rules_test_string', ContextConfig::create()
->map('text', 'concatenated')
->provideAs('concatenated', 'concatenated2'));
$state = ExecutionState::create();
$rule
->executeWithState($state);
// Check that the created variables exists and have the provided values.
$concatenated = $state
->getVariable('concatenated');
$this
->assertEquals($concatenated
->getValue(), 'test valuetest value');
$concatenated2 = $state
->getVariable('concatenated2');
$this
->assertEquals($concatenated2
->getValue(), 'test valuetest valuetest valuetest value');
}