public function RulesEngineTest::testProvidedVariables in Rules 8.3
Tests that a condition can provide a value and another one can consume it.
File
- tests/
src/ Kernel/ RulesEngineTest.php, line 96
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
->assertEquals(0, iterator_count($violations));
$component
->execute();
// Test that the action logged something.
$this
->assertRulesDebugLogEntryExists('action called');
}