function ConfigEntityTest::testConfigRule

Tests saving the nested config of a rule and then loading it again.

File

tests/src/Kernel/ConfigEntityTest.php, line 76

Class

ConfigEntityTest
Tests storage and loading of Rules config entities.

Namespace

Drupal\Tests\rules\Kernel

Code

public function testConfigRule() {
    // Create a simple rule with one action and one condition.
    $rule = $this->expressionManager
        ->createRule();
    $rule->addCondition('rules_test_true');
    $rule->addAction('rules_test_debug_log');
    $config_entity = $this->storage
        ->create([
        'id' => 'test_rule',
    ])
        ->setExpression($rule);
    $config_entity->save();
    $loaded_entity = $this->storage
        ->load('test_rule');
    // Create the Rules expression object from the configuration.
    $expression = $loaded_entity->getExpression();
    $expression->execute();
    // Test that the action logged something.
    $this->assertRulesDebugLogEntryExists('action called');
}