summaryrefslogtreecommitdiff
path: root/modules/comment/comment.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/comment/comment.test')
-rw-r--r--modules/comment/comment.test118
1 files changed, 112 insertions, 6 deletions
diff --git a/modules/comment/comment.test b/modules/comment/comment.test
index db5788984..473f61acd 100644
--- a/modules/comment/comment.test
+++ b/modules/comment/comment.test
@@ -123,7 +123,7 @@ class CommentHelperCase extends DrupalWebTestCase {
* Form value.
*/
function setCommentForm($enabled) {
- $this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
+ $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
}
/**
@@ -143,7 +143,7 @@ class CommentHelperCase extends DrupalWebTestCase {
* Comments per page value.
*/
function setCommentsPerPage($number) {
- $this->setCommentSettings('comment_default_per_page_article', $number, 'Number of comments per page set to ' . $number . '.');
+ $this->setCommentSettings('comment_default_per_page', $number, 'Number of comments per page set to ' . $number . '.');
}
/**
@@ -244,7 +244,9 @@ class CommentInterfaceTest extends CommentHelperCase {
// Set comments to not have subject.
$this->drupalLogin($this->admin_user);
$this->setCommentPreview(TRUE);
+ $this->setCommentForm(TRUE);
$this->setCommentSubject(FALSE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, t('Comment paging changed.'));
$this->drupalLogout();
// Post comment without subject.
@@ -300,11 +302,10 @@ class CommentInterfaceTest extends CommentHelperCase {
$this->drupalGet('node');
$this->assertRaw('3 comments', t('Link to the 3 comments exist.'));
- // Pager
+ // Confirm a new comment is posted to the correct page.
$this->setCommentsPerPage(2);
$comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName());
- $this->drupalGet('node/' . $this->node->nid);
- $this->assertTrue($this->commentExists($comment) && $this->commentExists($comment_new_page), t('Page one exists. %s'));
+ $this->assertTrue($this->commentExists($comment_new_page), t('Page one exists. %s'));
$this->drupalGet('node/' . $this->node->nid, array('query' => 'page=1'));
$this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s'));
$this->setCommentsPerPage(50);
@@ -454,6 +455,93 @@ class CommentAnonymous extends CommentHelperCase {
}
}
+/**
+ * Verify pagination of comments.
+ */
+class CommentPagerTest extends CommentHelperCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => t('Comment paging settings'),
+ 'description' => t('Test paging of comments and their settings.'),
+ 'group' => t('Comment'),
+ );
+ }
+
+ /**
+ * Confirm comment paging works correctly with flat and threaded comments.
+ */
+ function testCommentPaging() {
+ $this->drupalLogin($this->admin_user);
+
+ // Set comment variables.
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentPreview(FALSE);
+
+ // Create a node and three comments.
+ $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+ $comments = array();
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
+ $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
+
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT_EXPANDED, t('Comment paging changed.'));
+
+ // Set comments to one per page so that we are able to test paging without
+ // needing to insert large numbers of comments.
+ $this->setCommentsPerPage(1);
+
+ // Check the first page of the node, and confirm the correct comments are
+ // shown.
+ $this->drupalGet('node/' . $node->nid);
+ $this->assertRaw(t('next'), t('Paging links found.'));
+ $this->assertTrue($this->commentExists($comments[0]), t('Comment 1 appears on page 1.'));
+ $this->assertFalse($this->commentExists($comments[1]), t('Comment 2 does not appear on page 1.'));
+ $this->assertFalse($this->commentExists($comments[2]), t('Comment 3 does not appear on page 1.'));
+
+ // Check the second page.
+ $this->drupalGet('node/' . $node->nid, array('query' => 'page=1'));
+ $this->assertTrue($this->commentExists($comments[1]), t('Comment 2 appears on page 2.'));
+ $this->assertFalse($this->commentExists($comments[0]), t('Comment 1 does not appear on page 2.'));
+ $this->assertFalse($this->commentExists($comments[2]), t('Comment 3 does not appear on page 2.'));
+
+ // Check the third page.
+ $this->drupalGet('node/' . $node->nid, array('query' => 'page=2'));
+ $this->assertTrue($this->commentExists($comments[2]), t('Comment 3 appears on page 3.'));
+ $this->assertFalse($this->commentExists($comments[0]), t('Comment 1 does not appear on page 3.'));
+ $this->assertFalse($this->commentExists($comments[1]), t('Comment 2 does not appear on page 3.'));
+
+ // Post a reply to the oldest comment and test again.
+ $replies = array();
+ $oldest_comment = reset($comments);
+ $this->drupalGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
+ $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), FALSE, TRUE);
+
+ $this->setCommentsPerPage(2);
+ // We are still in flat view - the replies should not be on the first page,
+ // even though they are replies to the oldest comment.
+ $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+ $this->assertFalse($this->commentExists($reply, TRUE), t('In flat mode, reply does not appear on page 1.'));
+
+ // If we switch to threaded mode, the replies on the oldest comment
+ // should be bumped to the first page and comment 6 should be bumped
+ // to the second page.
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, t('Switched to threaded mode.'));
+ $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+ $this->assertTrue($this->commentExists($reply, TRUE), t('In threaded mode, reply appears on page 1.'));
+ $this->assertFalse($this->commentExists($comments[1]), t('In threaded mode, comment 2 has been bumped off of page 1.'));
+
+ // If (# replies > # comments per page) in threaded expanded view,
+ // the overage should be bumped.
+ $reply2 = $this->postComment(NULL, $this->randomName(), $this->randomName(), FALSE, TRUE);
+ $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+ $this->assertFalse($this->commentExists($reply2, TRUE), t('In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.'));
+
+ $this->drupalLogout();
+ }
+}
+
class CommentApprovalTest extends CommentHelperCase {
public static function getInfo() {
return array(
@@ -595,10 +683,28 @@ class CommentBlockFunctionalTest extends CommentHelperCase {
$this->drupalPost('admin/build/block/configure/comment/recent', $block, t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
- // Test that all three comments are shown.
+ // Post an additional comment.
+ $comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
+
+ // Test that all four comments are shown.
$this->assertText($comment1->subject, t('Comment found in block.'));
$this->assertText($comment2->subject, t('Comment found in block.'));
$this->assertText($comment3->comment, t('Comment found in block.'));
+ $this->assertText($comment4->subject, t('Comment found in block.'));
+
+ // Test that links to comments work when comments are across pages.
+ $this->setCommentsPerPage(1);
+ $this->drupalGet('');
+ $this->clickLink($comment1->subject);
+ $this->assertText($comment1->subject, t('Comment link goes to correct page.'));
+ $this->drupalGet('');
+ $this->clickLink($comment2->subject);
+ $this->assertText($comment2->subject, t('Comment link goes to correct page.'));
+ $this->clickLink($comment4->subject);
+ $this->assertText($comment4->subject, t('Comment link goes to correct page.'));
+ // Check that when viewing a comment page from a link to the comment, that
+ // rel="canonical" is added to the head of the document.
+ $this->assertRaw('<link rel="canonical"', t('Canonical URL was found in the HTML head'));
}
}