You are here

public function CommentBundlesTest::testEntityIdField in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/tests/src/Kernel/CommentBundlesTest.php \Drupal\Tests\comment\Kernel\CommentBundlesTest::testEntityIdField()

Tests that the entity_id field is set correctly for each comment bundle.

File

core/modules/comment/tests/src/Kernel/CommentBundlesTest.php, line 61

Class

CommentBundlesTest
Tests that comment bundles behave as expected.

Namespace

Drupal\Tests\comment\Kernel

Code

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);
  }
}