function RulesEngineTest::testRenamingOfProvidedVariables

Tests that provided variables can be renamed with configuration.

File

tests/src/Kernel/RulesEngineTest.php, line 123

Class

RulesEngineTest
Test using the Rules API to create and evaluate rules.

Namespace

Drupal\Tests\rules\Kernel

Code

public function testRenamingOfProvidedVariables() {
    $rule = $this->expressionManager
        ->createRule();
    // The condition provides a "provided_text" variable.
    $rule->addCondition('rules_test_provider', ContextConfig::create()->provideAs('provided_text', 'newname'));
    $state = ExecutionState::create();
    $rule->executeWithState($state);
    // Check that the newly named variable exists and has the provided value.
    $variable = $state->getVariable('newname');
    $this->assertEquals($variable->getValue(), 'test value');
}