X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FKernel%2FCommentBundlesTest.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FKernel%2FCommentBundlesTest.php;h=d9072334095f1183cd306a95023d4c4cbc5c0748;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php b/web/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php new file mode 100644 index 000000000..d90723340 --- /dev/null +++ b/web/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php @@ -0,0 +1,83 @@ +entityFieldManager = $this->container->get('entity_field.manager'); + + $this->installEntitySchema('comment'); + + // Create multiple comment bundles, + // each of which has a different target entity type. + $this->targetEntityTypes = [ + 'comment' => 'Comment', + 'node' => 'Node', + 'taxonomy_term' => 'Taxonomy Term', + ]; + foreach ($this->targetEntityTypes as $id => $label) { + CommentType::create([ + 'id' => 'comment_on_' . $id, + 'label' => 'Comment on ' . $label, + 'target_entity_type_id' => $id, + ])->save(); + } + } + + /** + * Test that the entity_id field is set correctly for each comment bundle. + */ + public function testEntityIdField() { + $field_definitions = []; + + foreach (array_keys($this->targetEntityTypes) as $id) { + $bundle = 'comment_on_' . $id; + $field_definitions[$bundle] = $this->entityFieldManager + ->getFieldDefinitions('comment', $bundle); + } + // Test that the value of the entity_id field for each bundle is correct. + foreach ($field_definitions as $bundle => $definition) { + $entity_type_id = str_replace('comment_on_', '', $bundle); + $target_type = $definition['entity_id']->getSetting('target_type'); + $this->assertEquals($entity_type_id, $target_type); + + // Verify that the target type remains correct + // in the deeply-nested object properties. + $nested_target_type = $definition['entity_id']->getItemDefinition()->getFieldDefinition()->getSetting('target_type'); + $this->assertEquals($entity_type_id, $nested_target_type); + } + + } + +}