You are here

protected function RulesEntityIntegrationTestBase::getContextDefinitionFor in Rules 8.3

Helper to mock a context definition with a mocked data definition.

Parameters

string $data_type: The data type, example "entity:node".

\Prophecy\Prophecy\ProphecyInterface $data_definition: A prophecy that represents a data definition object.

Return value

\Drupal\rules\Context\ContextDefinition The context definition with the data definition prophecy in it.

1 call to RulesEntityIntegrationTestBase::getContextDefinitionFor()
LoopTest::testPropertyPathList in tests/src/Unit/Integration/Engine/LoopTest.php
Tests that a list can be chosen with a property path selector.

File

tests/src/Unit/Integration/RulesEntityIntegrationTestBase.php, line 149

Class

RulesEntityIntegrationTestBase
Base class for Rules integration tests with entities.

Namespace

Drupal\Tests\rules\Unit\Integration

Code

protected function getContextDefinitionFor($data_type, ProphecyInterface $data_definition) {

  // Mock all the setter calls on the data definition that can be ignored.
  $data_definition
    ->setLabel(Argument::any())
    ->willReturn($data_definition
    ->reveal());
  $data_definition
    ->setDescription(Argument::any())
    ->willReturn($data_definition
    ->reveal());
  $data_definition
    ->setRequired(Argument::any())
    ->willReturn($data_definition
    ->reveal());
  $data_definition
    ->setLabel(Argument::any())
    ->willReturn($data_definition
    ->reveal());
  $data_definition
    ->setConstraints(Argument::any())
    ->willReturn($data_definition
    ->reveal());
  $data_definition
    ->getConstraints()
    ->willReturn([]);
  $data_definition
    ->getDataType()
    ->willReturn($data_type);
  $original_definition = $this->typedDataManager
    ->getDefinition($data_type);
  $data_definition
    ->getClass()
    ->willReturn($original_definition['class']);
  $context_definition = ContextDefinition::create($data_type);

  // Inject a fake typed data manager that will return our data definition
  // prophecy if asked for it in the ContextDefinition class.
  $typed_data_manager = $this
    ->prophesize(TypedDataManagerInterface::class);
  $typed_data_manager
    ->createDataDefinition($data_type)
    ->willReturn($data_definition
    ->reveal());
  $context_definition
    ->setTypedDataManager($typed_data_manager
    ->reveal());
  return $context_definition;
}