function RulesEngineTest::testProvidedVariables
Tests that a condition can provide a value and another one can consume it.
File
-
tests/
src/ Kernel/ RulesEngineTest.php, line 98
Class
- RulesEngineTest
- Test using the Rules API to create and evaluate rules.
Namespace
Drupal\Tests\rules\KernelCode
public function testProvidedVariables() {
$rule = $this->expressionManager
->createRule();
// The first condition provides a "provided_text" variable.
$rule->addCondition('rules_test_provider');
// The second condition consumes the variable.
$rule->addCondition('rules_test_string_condition', ContextConfig::create()->map('text', 'provided_text'));
$rule->addAction('rules_test_debug_log');
$component = RulesComponent::create($rule);
$violations = $component->checkIntegrity();
$this->assertCount(0, $violations);
$component->execute();
// Test that the action logged something.
$this->assertRulesDebugLogEntryExists('action called');
}