function ExpressionSerializationTest::testRuleExpressionSerialization

Tests rule serialization.

File

tests/src/Unit/Integration/Engine/ExpressionSerializationTest.php, line 82

Class

ExpressionSerializationTest
Tests serializing expression objects.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testRuleExpressionSerialization() {
    $expression = $this->rulesExpressionManager
        ->createRule();
    $expression->addAction('rules_test_string', ContextConfig::create()->setValue('text', 'test'));
    $condition = $this->rulesExpressionManager
        ->createCondition('rules_test_false');
    $condition->negate(TRUE);
    $expression->addExpressionObject($condition);
    $serialized_expression = serialize($expression);
    // @phpcs:ignore DrupalPractice.FunctionCalls.InsecureUnserialize.InsecureUnserialize
    $expression = unserialize($serialized_expression);
    $result = RulesComponent::create($expression)->provideContext('concatenated')
        ->execute();
    $this->assertSame('testtest', $result['concatenated']);
}