コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->pageVariantStorage = $this->prophesize(ConfigEntityStorageInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getStorage('page_variant')->willReturn($this->pageVariantStorage);
     $this->currentPath = $this->prophesize(CurrentPathStack::class);
     $this->routeFilter = new VariantRouteFilter($this->entityTypeManager->reveal(), $this->currentPath->reveal());
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->panelsDisplay = $this->prophesize(PanelsDisplayVariant::class);
     $this->pageVariant = $this->prophesize(PageVariantInterface::class);
     $this->pageVariant->getVariantPlugin()->willReturn($this->panelsDisplay->reveal());
     $this->pageVariantNotPanels = $this->prophesize(PageVariantInterface::class);
     $this->pageVariantNotPanels->getContexts()->shouldNotBeCalled();
     $non_panels_variant = $this->prophesize(HttpStatusCodeDisplayVariant::class);
     $this->pageVariantNotPanels->getVariantPlugin()->willReturn($non_panels_variant->reveal());
     $this->storage = $this->prophesize(EntityStorageInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getStorage('page_variant')->willReturn($this->storage->reveal());
 }
コード例 #3
0
 /**
  * @covers ::onFieldDefinitionDelete
  */
 public function testOnFieldDefinitionDeleteSingleBundles()
 {
     $field_definition = $this->prophesize(FieldDefinitionInterface::class);
     $field_definition->getTargetEntityTypeId()->willReturn('test_entity_type');
     $field_definition->getTargetBundle()->willReturn('test_bundle');
     $field_definition->getName()->willReturn('test_field');
     $storage = $this->prophesize(DynamicallyFieldableEntityStorageInterface::class);
     $storage->onFieldDefinitionDelete($field_definition->reveal())->shouldBeCalledTimes(1);
     $this->entityTypeManager->getStorage('test_entity_type')->willReturn($storage->reveal());
     $entity = $this->prophesize(EntityTypeInterface::class);
     $this->setUpEntityManager(['test_entity_type' => $entity]);
     // Set up the stored bundle field map.
     $key_value_store = $this->prophesize(KeyValueStoreInterface::class);
     $this->keyValueFactory->get('entity.definitions.bundle_field_map')->willReturn($key_value_store->reveal());
     $key_value_store->get('test_entity_type')->willReturn(['test_field' => ['type' => 'test_type', 'bundles' => ['test_bundle' => 'test_bundle', 'second_bundle' => 'second_bundle']]]);
     $key_value_store->set('test_entity_type', ['test_field' => ['type' => 'test_type', 'bundles' => ['second_bundle' => 'second_bundle']]])->shouldBeCalled();
     $this->fieldDefinitionListener->onFieldDefinitionDelete($field_definition->reveal());
 }
コード例 #4
0
 /**
  * Prepares an entity that defines a field definition.
  *
  * @param bool $custom_invoke_all
  *   (optional) Whether the test will set up its own
  *   ModuleHandlerInterface::invokeAll() implementation. Defaults to FALSE.
  * @param string $field_definition_id
  *   (optional) The ID to use for the field definition. Defaults to 'id'.
  * @param array $entity_keys
  *   (optional) An array of entity keys for the mocked entity type. Defaults
  *   to an empty array.
  *
  * @return \Drupal\Core\Field\BaseFieldDefinition|\Prophecy\Prophecy\ProphecyInterface
  *   A field definition object.
  */
 protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $entity_keys = [])
 {
     $field_type_manager = $this->prophesize(FieldTypePluginManagerInterface::class);
     $field_type_manager->getDefaultStorageSettings('boolean')->willReturn([]);
     $field_type_manager->getDefaultFieldSettings('boolean')->willReturn([]);
     $this->container->get('plugin.manager.field.field_type')->willReturn($field_type_manager->reveal());
     $string_translation = $this->prophesize(TranslationInterface::class);
     $this->container->get('string_translation')->willReturn($string_translation->reveal());
     $entity_class = EntityManagerTestEntity::class;
     $field_definition = $this->prophesize()->willImplement(FieldDefinitionInterface::class)->willImplement(FieldStorageDefinitionInterface::class);
     $entity_class::$baseFieldDefinitions = [$field_definition_id => $field_definition->reveal()];
     $entity_class::$bundleFieldDefinitions = [];
     if (!$custom_invoke_all) {
         $this->moduleHandler->getImplementations(Argument::cetera())->willReturn([]);
     }
     // Mock the base field definition override.
     $override_entity_type = $this->prophesize(EntityTypeInterface::class);
     $this->entityType = $this->prophesize(EntityTypeInterface::class);
     $this->setUpEntityTypeDefinitions(['test_entity_type' => $this->entityType, 'base_field_override' => $override_entity_type]);
     $storage = $this->prophesize(ConfigEntityStorageInterface::class);
     $storage->loadMultiple(Argument::type('array'))->willReturn([]);
     $this->entityTypeManager->getStorage('base_field_override')->willReturn($storage->reveal());
     $this->entityType->getClass()->willReturn($entity_class);
     $this->entityType->getKeys()->willReturn($entity_keys + ['default_langcode' => 'default_langcode']);
     $this->entityType->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
     $this->entityType->isTranslatable()->willReturn(FALSE);
     $this->entityType->getProvider()->willReturn('the_provider');
     $this->entityType->id()->willReturn('the_entity_id');
     return $field_definition->reveal();
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     // Register plugin managers used by Rules, but mock some unwanted
     // dependencies requiring more stuff to loaded.
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     // Set all the modules as being existent.
     $this->enabledModules = new \ArrayObject();
     $this->enabledModules['rules'] = TRUE;
     $this->enabledModules['rules_test'] = TRUE;
     $enabled_modules = $this->enabledModules;
     $this->moduleHandler->moduleExists(Argument::type('string'))->will(function ($arguments) use($enabled_modules) {
         return [$arguments[0], $enabled_modules[$arguments[0]]];
     });
     // Wed don't care about alter() calls on the module handler.
     $this->moduleHandler->alter(Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn(NULL);
     $this->cacheBackend = new NullBackend('rules');
     $rules_directory = __DIR__ . '/../../..';
     $this->namespaces = new \ArrayObject(['Drupal\\rules' => $rules_directory . '/src', 'Drupal\\rules_test' => $rules_directory . '/tests/modules/rules_test/src', 'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData', 'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation']);
     $this->actionManager = new RulesActionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal());
     $this->conditionManager = new ConditionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal());
     $uuid_service = new Php();
     $this->rulesExpressionManager = new ExpressionManager($this->namespaces, $this->moduleHandler->reveal(), $uuid_service);
     $this->classResolver = $this->prophesize(ClassResolverInterface::class);
     $this->typedDataManager = new TypedDataManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal(), $this->classResolver->reveal());
     $this->rulesDataProcessorManager = new DataProcessorManager($this->namespaces, $this->moduleHandler->reveal());
     $this->aliasManager = $this->prophesize(AliasManagerInterface::class);
     // Keep the deprecated entity manager around because it is still used in a
     // few places.
     $this->entityManager = $this->prophesize(EntityManagerInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getDefinitions()->willReturn([]);
     // Setup a rules_component storage mock which returns nothing by default.
     $storage = $this->prophesize(ConfigEntityStorageInterface::class);
     $storage->loadMultiple(NULL)->willReturn([]);
     $this->entityTypeManager->getStorage('rules_component')->willReturn($storage->reveal());
     $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
     $this->entityFieldManager->getBaseFieldDefinitions()->willReturn([]);
     $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
     $this->entityTypeBundleInfo->getBundleInfo()->willReturn([]);
     $this->dataFetcher = new DataFetcher();
     $this->dataFilterManager = new DataFilterManager($this->namespaces, $this->moduleHandler->reveal());
     $this->placeholderResolver = new PlaceholderResolver($this->dataFetcher, $this->dataFilterManager);
     $container->set('entity.manager', $this->entityManager->reveal());
     $container->set('entity_type.manager', $this->entityTypeManager->reveal());
     $container->set('entity_field.manager', $this->entityFieldManager->reveal());
     $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
     $container->set('context.repository', new LazyContextRepository($container, []));
     $container->set('path.alias_manager', $this->aliasManager->reveal());
     $container->set('plugin.manager.rules_action', $this->actionManager);
     $container->set('plugin.manager.condition', $this->conditionManager);
     $container->set('plugin.manager.rules_expression', $this->rulesExpressionManager);
     $container->set('plugin.manager.rules_data_processor', $this->rulesDataProcessorManager);
     $container->set('typed_data_manager', $this->typedDataManager);
     $container->set('string_translation', $this->getStringTranslationStub());
     $container->set('uuid', $uuid_service);
     $container->set('typed_data.data_fetcher', $this->dataFetcher);
     $container->set('typed_data.placeholder_resolver', $this->placeholderResolver);
     \Drupal::setContainer($container);
     $this->container = $container;
 }