public function CommentCacheTagsTest::testCommentEntity in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/comment/src/Tests/CommentCacheTagsTest.php \Drupal\comment\Tests\CommentCacheTagsTest::testCommentEntity()
Test that comments correctly invalidate the cache tag of their host entity.
File
- core/
modules/ comment/ src/ Tests/ CommentCacheTagsTest.php, line 99 - Contains \Drupal\comment\Tests\CommentCacheTagsTest.
Class
- CommentCacheTagsTest
- Tests the Comment entity's cache tags.
Namespace
Drupal\comment\TestsCode
public function testCommentEntity() {
$this
->verifyPageCache($this->entityTestCamelid
->urlInfo(), 'MISS');
$this
->verifyPageCache($this->entityTestCamelid
->urlInfo(), 'HIT');
// Create a "Hippopotamus" comment.
$this->entityTestHippopotamidae = entity_create('entity_test', array(
'name' => 'Hippopotamus',
'type' => 'bar',
));
$this->entityTestHippopotamidae
->save();
$this
->verifyPageCache($this->entityTestHippopotamidae
->urlInfo(), 'MISS');
$this
->verifyPageCache($this->entityTestHippopotamidae
->urlInfo(), 'HIT');
$hippo_comment = Comment::create(array(
'subject' => 'Hippopotamus',
'comment_body' => array(
'value' => 'The common hippopotamus (Hippopotamus amphibius), or hippo, is a large, mostly herbivorous mammal in sub-Saharan Africa',
'format' => 'plain_text',
),
'entity_id' => $this->entityTestHippopotamidae
->id(),
'entity_type' => 'entity_test',
'field_name' => 'comment',
'status' => CommentInterface::PUBLISHED,
));
$hippo_comment
->save();
// Ensure that a new comment only invalidates the commented entity.
$this
->verifyPageCache($this->entityTestCamelid
->urlInfo(), 'HIT');
$this
->verifyPageCache($this->entityTestHippopotamidae
->urlInfo(), 'MISS');
$this
->assertText($hippo_comment
->getSubject());
// Ensure that updating an existing comment only invalidates the commented
// entity.
$this->entity
->save();
$this
->verifyPageCache($this->entityTestCamelid
->urlInfo(), 'MISS');
$this
->verifyPageCache($this->entityTestHippopotamidae
->urlInfo(), 'HIT');
}