function CommentCacheTagsTest::createEntity

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php \Drupal\Tests\comment\Functional\CommentCacheTagsTest::createEntity()
  2. 8.9.x core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php \Drupal\Tests\comment\Functional\CommentCacheTagsTest::createEntity()
  3. 10 core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php \Drupal\Tests\comment\Functional\CommentCacheTagsTest::createEntity()

Overrides EntityCacheTagsTestBase::createEntity

File

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

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.