/** * Registers bundle information for the mock entity type. * * @param array $bundle_info * The bundle information to register. */ protected function registerBundleInfo($bundle_info) { $this->entityManager->getBundleInfo($this->entityTypeId)->willReturn([$this->entityTypeId => $bundle_info]); }
/** * @covers ::getFieldMapByFieldType */ public function testGetFieldMapByFieldType() { // Set up a content entity type. $entity_type = $this->prophesize(ContentEntityTypeInterface::class); $entity_class = EntityManagerTestEntity::class; // Set up the entity type bundle info to return two bundles for the // fieldable entity type. $this->entityTypeBundleInfo->getBundleInfo('test_entity_type')->willReturn(['first_bundle' => 'first_bundle', 'second_bundle' => 'second_bundle'])->shouldBeCalled(); $this->moduleHandler->getImplementations('entity_base_field_info')->willReturn([])->shouldBeCalled(); // Define an ID field definition as a base field. $id_definition = $this->prophesize(FieldDefinitionInterface::class); $id_definition->getType()->willReturn('integer')->shouldBeCalled(); $base_field_definitions = ['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())->shouldBeCalled(); $key_value_store->getAll()->willReturn(['test_entity_type' => ['by_bundle' => ['type' => 'string', 'bundles' => ['second_bundle' => 'second_bundle']]]])->shouldBeCalled(); // Mock the base field definition override. $override_entity_type = $this->prophesize(EntityTypeInterface::class); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity_type, 'base_field_override' => $override_entity_type]); $entity_type->getClass()->willReturn($entity_class)->shouldBeCalled(); $entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode'])->shouldBeCalled(); $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE)->shouldBeCalled(); $entity_type->isTranslatable()->shouldBeCalled(); $entity_type->getProvider()->shouldBeCalled(); $override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE)->shouldBeCalled(); $integerFields = $this->entityFieldManager->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->entityFieldManager->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']); }