/** * Test that comments correctly invalidate the cache tag of their host entity. */ public function testCommentEntity() { $this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS'); $this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT'); // Create a "Hippopotamus" comment. $this->entityTestHippopotamidae = EntityTest::create(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'); }