3 namespace Drupal\Tests\comment\Kernel;
5 use Drupal\comment\Entity\CommentType;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests that comment bundles behave as expected.
13 class CommentBundlesTest extends KernelTestBase {
18 public static $modules = ['comment', 'node', 'taxonomy', 'user'];
21 * Entity type ids to use for target_entity_type_id on comment bundles.
25 protected $targetEntityTypes;
28 * @var \Drupal\Core\Entity\EntityFieldManagerInterface
30 protected $entityFieldManager;
35 protected function setUp() {
38 $this->entityFieldManager = $this->container->get('entity_field.manager');
40 $this->installEntitySchema('comment');
42 // Create multiple comment bundles,
43 // each of which has a different target entity type.
44 $this->targetEntityTypes = [
45 'comment' => 'Comment',
47 'taxonomy_term' => 'Taxonomy Term',
49 foreach ($this->targetEntityTypes as $id => $label) {
51 'id' => 'comment_on_' . $id,
52 'label' => 'Comment on ' . $label,
53 'target_entity_type_id' => $id,
59 * Test that the entity_id field is set correctly for each comment bundle.
61 public function testEntityIdField() {
62 $field_definitions = [];
64 foreach (array_keys($this->targetEntityTypes) as $id) {
65 $bundle = 'comment_on_' . $id;
66 $field_definitions[$bundle] = $this->entityFieldManager
67 ->getFieldDefinitions('comment', $bundle);
69 // Test that the value of the entity_id field for each bundle is correct.
70 foreach ($field_definitions as $bundle => $definition) {
71 $entity_type_id = str_replace('comment_on_', '', $bundle);
72 $target_type = $definition['entity_id']->getSetting('target_type');
73 $this->assertEquals($entity_type_id, $target_type);
75 // Verify that the target type remains correct
76 // in the deeply-nested object properties.
77 $nested_target_type = $definition['entity_id']->getItemDefinition()->getFieldDefinition()->getSetting('target_type');
78 $this->assertEquals($entity_type_id, $nested_target_type);