function RulesComponentActionTest::testContextDefinitions

Tests that context definitions are available on the derived action.

File

tests/src/Unit/Integration/RulesAction/RulesComponentActionTest.php, line 77

Class

RulesComponentActionTest
Tests for exposing Rules components as action plugins.

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testContextDefinitions() {
    $rule = $this->rulesExpressionManager
        ->createRule();
    $rule->addAction('rules_entity_save', ContextConfig::create()->map('entity', 'entity'))
        ->addAction('rules_test_string', ContextConfig::create()->setValue('text', 'x'));
    $rules_config = new RulesComponentConfig([
        'id' => 'test_rule',
        'label' => 'Test rule',
    ], 'rules_component');
    $rules_config->setExpression($rule);
    $context_definitions = [
        'entity' => ContextDefinition::create('entity'),
    ];
    $rules_config->setContextDefinitions($context_definitions);
    $provided_definitions = [
        'concatenated' => ContextDefinition::create('string'),
    ];
    $rules_config->setProvidedContextDefinitions($provided_definitions);
    $this->prophesizeStorage([
        $rules_config,
    ]);
    $definition = $this->actionManager
        ->getDefinition('rules_component:test_rule');
    $this->assertEquals($context_definitions, $definition['context_definitions']);
    $this->assertEquals($provided_definitions, $definition['provides']);
}