You are here

protected function CommentCacheTagsTest::createEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php \Drupal\Tests\comment\Functional\CommentCacheTagsTest::createEntity()

Creates the entity to be tested.

Return value

\Drupal\Core\Entity\EntityInterface The entity to be tested.

Overrides EntityCacheTagsTestBase::createEntity

File

core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php, line 62

Class

CommentCacheTagsTest
Tests the Comment entity's cache tags.

Namespace

Drupal\Tests\comment\Functional

Code

protected function createEntity() {

  // Create a "bar" bundle for the "entity_test" entity type and create.
  $bundle = 'bar';
  entity_test_create_bundle($bundle, NULL, 'entity_test');

  // Create a comment field on this bundle.
  $this
    ->addDefaultCommentField('entity_test', 'bar', 'comment');

  // Display comments in a flat list; threaded comments are not render cached.
  $field = FieldConfig::loadByName('entity_test', 'bar', 'comment');
  $field
    ->setSetting('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT);
  $field
    ->save();

  // Create a "Camelids" test entity that the comment will be assigned to.
  $this->entityTestCamelid = EntityTest::create([
    'name' => 'Camelids',
    'type' => 'bar',
  ]);
  $this->entityTestCamelid
    ->save();

  // Create a "Llama" comment.
  $comment = Comment::create([
    'subject' => 'Llama',
    'comment_body' => [
      'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
      'format' => 'plain_text',
    ],
    'entity_id' => $this->entityTestCamelid
      ->id(),
    'entity_type' => 'entity_test',
    'field_name' => 'comment',
    'status' => CommentInterface::PUBLISHED,
  ]);
  $comment
    ->save();
  return $comment;
}