/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setup();
     require_once $this->root . '/core/includes/entity.inc';
     $this->namespaces['Drupal\\Core\\Entity'] = $this->root . '/core/lib/Drupal/Core/Entity';
     $language = $this->prophesize(LanguageInterface::class);
     $language->getId()->willReturn('en');
     $this->languageManager = $this->prophesize(LanguageManagerInterface::class);
     $this->languageManager->getCurrentLanguage()->willReturn($language->reveal());
     $this->languageManager->getLanguages()->willReturn([$language->reveal()]);
     // We need to support multiple entity types, including a test type:
     $type_info = ['test' => ['id' => 'test', 'label' => 'Test', 'entity_keys' => ['bundle' => 'bundle']], 'user' => ['id' => 'user', 'label' => 'Test User', 'entity_keys' => ['bundle' => 'user']], 'node' => ['id' => 'node', 'label' => 'Test Node', 'entity_keys' => ['bundle' => 'dummy']]];
     $type_array = [];
     foreach ($type_info as $type => $info) {
         $entity_type = new ContentEntityType($info);
         $type_array[$type] = $entity_type;
         $this->entityTypeManager->getDefinition($type)->willReturn($entity_type);
         $this->entityManager->getDefinition($type)->willReturn($entity_type);
     }
     // We need a user_role mock as well.
     $role_entity_info = ['id' => 'user_role', 'label' => 'Test Role'];
     $role_type = new ConfigEntityType($role_entity_info);
     $type_array['user_role'] = $role_type;
     $this->entityTypeManager->getDefinitions()->willReturn($type_array);
     $this->entityManager->getDefinitions()->willReturn($type_array);
     $this->entityAccess = $this->prophesize(EntityAccessControlHandlerInterface::class);
     $this->entityTypeManager->getAccessControlHandler(Argument::any())->willReturn($this->entityAccess->reveal());
     // The base field definitions for our test entity aren't used, and would
     // require additional mocking. It doesn't appear that any of our tests rely
     // on this for any other entity type that we are mocking.
     $this->entityFieldManager->getBaseFieldDefinitions(Argument::any())->willReturn([]);
     $this->entityManager->getBaseFieldDefinitions(Argument::any())->willReturn([]);
     // Return some dummy bundle information for now, so that the entity manager
     // does not call out to the config entity system to get bundle information.
     $this->entityTypeBundleInfo->getBundleInfo(Argument::any())->willReturn(['test' => ['label' => 'Test']]);
     $this->entityManager->getBundleInfo(Argument::any())->willReturn(['test' => ['label' => 'Test']]);
     $this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
     $this->fieldTypeManager = new FieldTypePluginManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal(), $this->typedDataManager);
     $this->container->set('plugin.manager.field.field_type', $this->fieldTypeManager);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setup();
     require_once $this->root . '/core/includes/entity.inc';
     $this->namespaces['Drupal\\Core\\Entity'] = $this->root . '/core/lib/Drupal/Core/Entity';
     $language = $this->prophesize(LanguageInterface::class);
     $language->getId()->willReturn('en');
     $this->languageManager = $this->prophesize(LanguageManagerInterface::class);
     $this->languageManager->getCurrentLanguage()->willReturn($language->reveal());
     $this->languageManager->getLanguages()->willReturn([$language->reveal()]);
     $entityType = new ContentEntityType(['id' => 'test', 'label' => 'Test', 'entity_keys' => ['bundle' => 'bundle']]);
     $this->entityManager->getDefinitions()->willReturn(['test' => $entityType]);
     $this->entityAccess = $this->prophesize(EntityAccessControlHandlerInterface::class);
     $this->entityManager->getAccessControlHandler(Argument::any())->willReturn($this->entityAccess->reveal());
     // The base field definitions for our test entity aren't used, and would
     // require additional mocking.
     $this->entityManager->getBaseFieldDefinitions('test')->willReturn([]);
     // Return some dummy bundle information for now, so that the entity manager
     // does not call out to the config entity system to get bundle information.
     $this->entityManager->getBundleInfo(Argument::any())->willReturn(['test' => ['label' => 'Test']]);
     $this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->container = $this->prophesize(ContainerInterface::class);
     \Drupal::setContainer($this->container->reveal());
     $this->typedDataManager = $this->prophesize(TypedDataManagerInterface::class);
     $this->typedDataManager->getDefinition('field_item:boolean')->willReturn(['class' => BooleanItem::class]);
     $this->container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     $this->moduleHandler->alter('entity_base_field_info', Argument::type('array'), Argument::any())->willReturn(NULL);
     $this->moduleHandler->alter('entity_bundle_field_info', Argument::type('array'), Argument::any(), Argument::type('string'))->willReturn(NULL);
     $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
     $language = new Language(['id' => 'en']);
     $this->languageManager = $this->prophesize(LanguageManagerInterface::class);
     $this->languageManager->getCurrentLanguage()->willReturn($language);
     $this->languageManager->getLanguages()->willReturn(['en' => (object) ['id' => 'en']]);
     $this->keyValueFactory = $this->prophesize(KeyValueFactoryInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeRepository = $this->prophesize(EntityTypeRepositoryInterface::class);
     $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
     $this->entityDisplayRepository = $this->prophesize(EntityDisplayRepositoryInterface::class);
     $this->entityFieldManager = new TestEntityFieldManager($this->entityTypeManager->reveal(), $this->entityTypeBundleInfo->reveal(), $this->entityDisplayRepository->reveal(), $this->typedDataManager->reveal(), $this->languageManager->reveal(), $this->keyValueFactory->reveal(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal());
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     $this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
     $this->moduleHandler->alter('entity_type', Argument::type('array'))->willReturn(NULL);
     $this->moduleHandler->alter('entity_base_field_info', Argument::type('array'), Argument::any())->willReturn(NULL);
     $this->moduleHandler->alter('entity_bundle_field_info', Argument::type('array'), Argument::any(), Argument::type('string'))->willReturn(NULL);
     $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
     $language = new Language(['id' => 'en']);
     $this->languageManager = $this->prophesize(LanguageManagerInterface::class);
     $this->languageManager->getCurrentLanguage()->willReturn($language);
     $this->languageManager->getLanguages()->willReturn(['en' => (object) ['id' => 'en']]);
     $this->typedDataManager = $this->prophesize(TypedDataManager::class);
     $this->typedDataManager->getDefinition('field_item:boolean')->willReturn(['class' => BooleanItem::class]);
     $this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
     $this->keyValueFactory = $this->prophesize(KeyValueFactoryInterface::class);
     $this->container = $this->prophesize(ContainerInterface::class);
     $this->container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal());
     $this->container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
     \Drupal::setContainer($this->container->reveal());
     $this->discovery = $this->prophesize(DiscoveryInterface::class);
     $translation_manager = $this->prophesize(TranslationInterface::class);
     $this->entityManager = new TestEntityManager(new \ArrayObject(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal(), $this->languageManager->reveal(), $translation_manager->reveal(), $this->getClassResolverStub(), $this->typedDataManager->reveal(), $this->keyValueFactory->reveal(), $this->eventDispatcher->reveal());
     $this->entityManager->setContainer($this->container->reveal());
     $this->entityManager->setDiscovery($this->discovery->reveal());
 }