function ViewsContentCacheTest::testCommentAdded in Views content cache 6.2
Same name and namespace in other branches
- 7.3 tests/views_content_cache.test \ViewsContentCacheTest::testCommentAdded()
Test that when a comment is added to a story 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 58
Class
Code
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' => 'story',
));
$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 story node comment segment.
$cid = array(
'node' => array(
'story',
),
'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 story node comment cache segment is updated.'));
// In the story only node comment segment.
$cid = array(
'node' => array(
'story',
),
'node_only' => array(
'node_changed',
),
);
$updated = views_content_cache_update_get($cid, TRUE);
$this
->assertFalse($updated, t('Ensure that the timestamp against the story 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.'));
}