function ConditionExpressionTest::testDataProcessor
Tests that context values get data processed with processor mappings.
File
-
tests/
src/ Unit/ ConditionExpressionTest.php, line 83
Class
- ConditionExpressionTest
- @coversDefaultClass \Drupal\rules\Plugin\RulesExpression\ConditionExpression @group Rules
Namespace
Drupal\Tests\rules\UnitCode
public function testDataProcessor() {
$this->conditionManager
->createInstance('test_condition', [
'negate' => FALSE,
])
->willReturn($this->trueCondition
->reveal())
->shouldBeCalledTimes(1);
$this->conditionManager
->getDefinition('test_condition')
->willReturn([
'label' => 'Test Condition',
])
->shouldBeCalledTimes(1);
$condition = new ConditionExpression([
'condition_id' => 'test_condition',
] + ContextConfig::create()->process('test', 'foo', [])
->toArray(), '', [
'label' => 'Test Condition',
], $this->conditionManager
->reveal(), $this->processorManager
->reveal(), $this->rulesDebugLogger
->reveal());
$this->trueCondition
->getContextDefinitions()
->willReturn([
'test' => $this->prophesize(ContextDefinitionInterface::class)
->reveal(),
])
->shouldBeCalledTimes(1);
$this->trueCondition
->getContextDefinition('test')
->willReturn($this->prophesize(ContextDefinitionInterface::class)
->reveal())
->shouldBeCalledTimes(1);
$this->trueCondition
->getProvidedContextDefinitions()
->willReturn([])
->shouldBeCalledTimes(1);
// Mock some original old value that will be replaced by the data processor.
$this->trueCondition
->getContextValue('test')
->willReturn('old_value')
->shouldBeCalled();
// The outcome of the data processor needs to get set on the condition.
$this->trueCondition
->setContextValue('test', 'new_value')
->shouldBeCalledTimes(1);
$this->trueCondition
->refineContextDefinitions([])
->shouldBeCalledTimes(1);
$data_processor = $this->prophesize(DataProcessorInterface::class);
$data_processor->process('old_value', Argument::any())
->willReturn('new_value')
->shouldBeCalledTimes(1);
$this->processorManager
->createInstance('foo', [])
->willReturn($data_processor->reveal())
->shouldBeCalledTimes(1);
// Build some mocked execution state.
$state = $this->prophesize(ExecutionStateInterface::class);
$prophecy = $state->getVariable('test');
/** @var \Prophecy\Prophecy\MethodProphecy $prophecy */
$prophecy->willReturn('old_value');
$this->assertTrue($condition->executeWithState($state->reveal()));
}