public function ViewsContentCacheTest::testCommentAdded in Views content cache 7.3
Same name and namespace in other branches
- 6.2 tests/views_content_cache.test \ViewsContentCacheTest::testCommentAdded()
Test that when a comment is added to a article the timestamp is recorded.
We'll create a node and then post a comment on it, making sure that:
- The comment segment has no timestamp associated with it before we begin.
- The global comment segment is updated when posting a comment.
- The comment segment for stories is updated.
- The comment segment for pages is not updated.
File
- tests/
views_content_cache.test, line 63 - Provides the Views content cache tests.
Class
- ViewsContentCacheTest
- @file Provides the Views content cache tests.
Code
public function testCommentAdded() {
$cid = array(
'comment' => array(
'changed',
),
);
$this
->assertFalse(views_content_cache_update_get($cid, TRUE), t('Ensure that the no timestamp has been set against the global comment cache segment.'));
// Create the node we'll be posting against.
$this->node = $this
->drupalCreateNode(array(
'type' => 'article',
));
// We intentionally use time() instead of REQUEST_TIME here.
$timestamp_before = time();
$this->comment = $this
->postComment($this->node, $this
->randomName(32));
$timestamp_after = time();
// Now need to make sure that views content cache recorded the correct time:
// In the global comment segment.
$cid = array(
'comment' => array(
'changed',
),
);
$updated = views_content_cache_update_get($cid, TRUE);
$result = $updated <= $timestamp_after && $updated >= $timestamp_before;
$this
->assertTrue($result, t('Ensure that the timestamp against the global comment cache segment is updated.'));
// In the article node comment segment.
$cid = array(
'node' => array(
'article',
),
'comment' => array(
'changed',
),
);
$updated = views_content_cache_update_get($cid, TRUE);
$result = $updated <= $timestamp_after && $updated >= $timestamp_before;
$this
->assertTrue($result, t('Ensure that the timestamp against the article node comment cache segment is updated.'));
// In the article only node comment segment.
$cid = array(
'node' => array(
'article',
),
'node_only' => array(
'node_changed',
),
);
$updated = views_content_cache_update_get($cid, TRUE);
$this
->assertFalse($updated, t('Ensure that the timestamp against the article only node comment cache segment is not updated.'));
// In the page node comment segment.
$cid = array(
'node' => array(
'page',
),
'comment' => array(
'changed',
),
);
$updated = views_content_cache_update_get($cid, TRUE);
$this
->assertFalse($updated, t('Ensure that the timestamp against the page node comment cache segment is not updated.'));
}