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