コード例 #1
0
 /**
  * Tests the getAllBundleInfo() method.
  *
  * @covers ::getAllBundleInfo
  */
 public function testGetAllBundleInfo()
 {
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->getLabel()->willReturn('Apple');
     $apple->getBundleOf()->willReturn(NULL);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->getLabel()->willReturn('Banana');
     $banana->getBundleOf()->willReturn(NULL);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
     $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () {
         $this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled();
     })->shouldBeCalled();
     $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();
     $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
     $expected = ['apple' => ['apple' => ['label' => 'Apple']], 'banana' => ['banana' => ['label' => 'Banana']]];
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $this->entityTypeBundleInfo->clearCachedBundles();
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame('cached data', $bundle_info);
 }
コード例 #2
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']);
 }
コード例 #3
0
 /**
  * @covers ::getAllBundleInfo
  */
 public function testGetAllBundleInfoWithEntityBundleInfo()
 {
     // Ensure that EntityTypeBundleInfo::getAllBundleInfo() does not add
     // additional bundles if hook_entity_bundle_info() defines some and the
     // entity_type does not define a bundle entity type.
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn(['banana' => ['fig' => ['label' => 'Fig banana']]]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->getLabel()->willReturn('Apple');
     $apple->getBundleEntityType()->willReturn(NULL);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->getLabel()->willReturn('Banana');
     $banana->getBundleEntityType()->willReturn(NULL);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $expected = ['banana' => ['fig' => ['label' => 'Fig banana']], 'apple' => ['apple' => ['label' => 'Apple']]];
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
 }
コード例 #4
0
 /**
  * @covers ::getExtraFields
  */
 function testGetExtraFields()
 {
     $this->setUpEntityTypeDefinitions();
     $entity_type_id = $this->randomMachineName();
     $bundle = $this->randomMachineName();
     $language_code = 'en';
     $hook_bundle_extra_fields = [$entity_type_id => [$bundle => ['form' => ['foo_extra_field' => ['label' => 'Foo']]]]];
     $processed_hook_bundle_extra_fields = $hook_bundle_extra_fields;
     $processed_hook_bundle_extra_fields[$entity_type_id][$bundle] += ['display' => []];
     $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $language_code;
     $language = new Language(['id' => $language_code]);
     $this->languageManager->getCurrentLanguage()->willReturn($language)->shouldBeCalledTimes(1);
     $this->cacheBackend->get($cache_id)->shouldBeCalled();
     $this->moduleHandler->invokeAll('entity_extra_field_info')->willReturn($hook_bundle_extra_fields);
     $this->moduleHandler->alter('entity_extra_field_info', $hook_bundle_extra_fields)->shouldBeCalled();
     $this->cacheBackend->set($cache_id, $processed_hook_bundle_extra_fields[$entity_type_id][$bundle], Cache::PERMANENT, ['entity_field_info'])->shouldBeCalled();
     $this->assertSame($processed_hook_bundle_extra_fields[$entity_type_id][$bundle], $this->entityFieldManager->getExtraFields($entity_type_id, $bundle));
 }