function RulesComponentTest::testRuleExecutionWithContext
Tests executing a rule providing context based upon given context.
File
-
tests/
src/ Unit/ Integration/ Engine/ RulesComponentTest.php, line 22
Class
- RulesComponentTest
- Tests the Rules component class.
Namespace
Drupal\Tests\rules\Unit\Integration\EngineCode
public function testRuleExecutionWithContext() {
$rule = $this->rulesExpressionManager
->createRule();
$rule->addAction('rules_test_string', ContextConfig::create()->map('text', 'text'));
$result = RulesComponent::create($rule)->addContextDefinition('text', ContextDefinition::create('string'))
->provideContext('concatenated')
->setContextValue('text', 'foo')
->execute();
// Ensure the provided context is returned.
$this->assertArrayHasKey('concatenated', $result);
// cspell:ignore foofoo
$this->assertEquals('foofoo', $result['concatenated']);
}