コード例 #1
0
 /**
  * Helper to mock a context definition with a mocked data definition.
  *
  * @param string $data_type
  *   The data type, example "entity:node".
  * @param \Prophecy\Prophecy\ProphecyInterface $data_definition
  *   A prophecy that represents a data definition object.
  *
  * @return \Drupal\rules\Context\ContextDefinition
  *   The context definition with the data definition prophecy in it.
  */
 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 manger 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;
 }