Пример #1
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->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $this->translationManager = $this->prophesize(TranslationInterface::class);
     $this->entityTypeManager = new TestEntityTypeManager(new \ArrayObject(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal(), $this->translationManager->reveal(), $this->getClassResolverStub());
     $this->discovery = $this->prophesize(DiscoveryInterface::class);
     $this->entityTypeManager->setDiscovery($this->discovery->reveal());
 }
 /**
  * {@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->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::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(TypedDataManagerInterface::class);
     $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $container = $this->prophesize(ContainerInterface::class);
     $container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal());
     //$container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
     \Drupal::setContainer($container->reveal());
     $this->entityTypeBundleInfo = new EntityTypeBundleInfo($this->entityTypeManager->reveal(), $this->languageManager->reveal(), $this->moduleHandler->reveal(), $this->typedDataManager->reveal(), $this->cacheBackend->reveal());
 }
Пример #3
0
 /**
  * @covers ::getFieldMapByFieldType
  */
 public function testGetFieldMapByFieldType()
 {
     // Set up a content entity type.
     $entity_type = $this->prophesize(ContentEntityTypeInterface::class);
     $entity_class = EntityManagerTestEntity::class;
     // Set up the module handler to return two bundles for the fieldable entity
     // type.
     $this->moduleHandler->getImplementations('entity_base_field_info')->willReturn([]);
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn(['test_entity_type' => ['first_bundle' => [], 'second_bundle' => []]]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     // Define an ID field definition as a base field.
     $id_definition = $this->prophesize(FieldDefinitionInterface::class);
     $id_definition->getType()->willReturn('integer');
     $base_field_definitions = array('id' => $id_definition->reveal());
     $entity_class::$baseFieldDefinitions = $base_field_definitions;
     // 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->getAll()->willReturn(['test_entity_type' => ['by_bundle' => ['type' => 'string', 'bundles' => ['second_bundle' => 'second_bundle']]]]);
     // Mock the base field definition override.
     $override_entity_type = $this->prophesize(EntityTypeInterface::class);
     $this->setUpEntityManager(array('test_entity_type' => $entity_type, 'base_field_override' => $override_entity_type));
     $entity_type->getClass()->willReturn($entity_class);
     $entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode']);
     $entity_type->id()->willReturn('test_entity_type');
     $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
     $entity_type->getBundleOf()->shouldBeCalled();
     $entity_type->isTranslatable()->shouldBeCalled();
     $entity_type->getProvider()->shouldBeCalled();
     $override_entity_type->getClass()->willReturn($entity_class);
     $override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
     $override_entity_type->getHandlerClass('storage')->willReturn(TestConfigEntityStorage::class);
     $override_entity_type->getBundleOf()->shouldBeCalled();
     $override_entity_type->getLabel()->shouldBeCalled();
     $integerFields = $this->entityManager->getFieldMapByFieldType('integer');
     $this->assertCount(1, $integerFields['test_entity_type']);
     $this->assertArrayNotHasKey('non_fieldable', $integerFields);
     $this->assertArrayHasKey('id', $integerFields['test_entity_type']);
     $this->assertArrayNotHasKey('by_bundle', $integerFields['test_entity_type']);
     $stringFields = $this->entityManager->getFieldMapByFieldType('string');
     $this->assertCount(1, $stringFields['test_entity_type']);
     $this->assertArrayNotHasKey('non_fieldable', $stringFields);
     $this->assertArrayHasKey('by_bundle', $stringFields['test_entity_type']);
     $this->assertArrayNotHasKey('id', $stringFields['test_entity_type']);
 }