Chris@0: entityFieldManager = $this->container->get('entity_field.manager'); Chris@0: Chris@0: $this->installEntitySchema('comment'); Chris@0: Chris@0: // Create multiple comment bundles, Chris@0: // each of which has a different target entity type. Chris@0: $this->targetEntityTypes = [ Chris@0: 'comment' => 'Comment', Chris@0: 'node' => 'Node', Chris@0: 'taxonomy_term' => 'Taxonomy Term', Chris@0: ]; Chris@0: foreach ($this->targetEntityTypes as $id => $label) { Chris@0: CommentType::create([ Chris@0: 'id' => 'comment_on_' . $id, Chris@0: 'label' => 'Comment on ' . $label, Chris@0: 'target_entity_type_id' => $id, Chris@0: ])->save(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test that the entity_id field is set correctly for each comment bundle. Chris@0: */ Chris@0: public function testEntityIdField() { Chris@0: $field_definitions = []; Chris@0: Chris@0: foreach (array_keys($this->targetEntityTypes) as $id) { Chris@0: $bundle = 'comment_on_' . $id; Chris@0: $field_definitions[$bundle] = $this->entityFieldManager Chris@0: ->getFieldDefinitions('comment', $bundle); Chris@0: } Chris@0: // Test that the value of the entity_id field for each bundle is correct. Chris@0: foreach ($field_definitions as $bundle => $definition) { Chris@0: $entity_type_id = str_replace('comment_on_', '', $bundle); Chris@0: $target_type = $definition['entity_id']->getSetting('target_type'); Chris@0: $this->assertEquals($entity_type_id, $target_type); Chris@0: Chris@0: // Verify that the target type remains correct Chris@0: // in the deeply-nested object properties. Chris@0: $nested_target_type = $definition['entity_id']->getItemDefinition()->getFieldDefinition()->getSetting('target_type'); Chris@0: $this->assertEquals($entity_type_id, $nested_target_type); Chris@0: } Chris@0: Chris@0: } Chris@0: Chris@0: }