diff options
Diffstat (limited to 'modules/comment')
-rw-r--r-- | modules/comment/comment.module | 10 | ||||
-rw-r--r-- | modules/comment/comment.test | 113 |
2 files changed, 120 insertions, 3 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 2793ea3b5..69388337b 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -76,7 +76,7 @@ function comment_help($path, $arg) { switch ($path) { case 'admin/help#comment': $output = '<h3>' . t('About') . '</h3>'; - $output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the online handbook entry for <a href="@comment">Comment module</a>.', array('@comment' => 'http://drupal.org/handbook/modules/comment/')) . '</p>'; + $output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the online handbook entry for <a href="@comment">Comment module</a>.', array('@comment' => 'http://drupal.org/documentation/modules/comment/')) . '</p>'; $output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<dl>'; $output .= '<dt>' . t('Default and custom settings') . '</dt>'; @@ -1499,8 +1499,11 @@ function comment_save($comment) { $max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid))->fetchField(); // Strip the "/" from the end of the thread. $max = rtrim($max, '/'); + // We need to get the value at the correct depth. + $parts = explode('.', $max); + $firstsegment = $parts[0]; // Finally, build the thread field for this new comment. - $thread = int2vancode(vancode2int($max) + 1) . '/'; + $thread = int2vancode(vancode2int($firstsegment) + 1) . '/'; } else { // This is a comment with a parent comment, so increase the part of the @@ -2062,6 +2065,9 @@ function comment_preview($comment) { if (!empty($account->uid)) { $comment->uid = $account->uid; $comment->name = check_plain($account->name); + $comment->signature = $account->signature; + $comment->signature_format = $account->signature_format; + $comment->picture = $account->picture; } elseif (empty($comment->name)) { $comment->name = variable_get('anonymous', t('Anonymous')); diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 970cc83ae..4c6755522 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -956,8 +956,18 @@ class CommentPreviewTest extends CommentHelperCase { $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.')); $this->drupalLogout(); - // As web user, fill in node creation form and preview node. + // Login as web user and add a signature and a user picture. $this->drupalLogin($this->web_user); + variable_set('user_signatures', 1); + variable_set('user_pictures', 1); + $test_signature = $this->randomName(); + $edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>'; + $edit['signature[format]'] = 'filtered_html'; + $image = current($this->drupalGetTestFiles('image')); + $edit['files[picture_upload]'] = drupal_realpath($image->uri); + $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save')); + + // As the web user, fill in the comment form and preview the comment. $edit = array(); $edit['subject'] = $this->randomName(8); $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16); @@ -971,6 +981,12 @@ class CommentPreviewTest extends CommentHelperCase { // Check that the title and body fields are displayed with the correct values. $this->assertFieldByName('subject', $edit['subject'], t('Subject field displayed.')); $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], t('Comment field displayed.')); + + // Check that the signature is displaying with the correct text format. + $this->assertLink($test_signature); + + // Check that the user picture is displayed. + $this->assertFieldByXPath("//div[contains(@class, 'comment-preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.'); } /** @@ -2085,3 +2101,98 @@ class CommentFieldsTest extends CommentHelperCase { $this->drupalPost('node/' . $this->node->nid, $edit, t('Save')); } } + +/** + * Tests comment threading. + */ +class CommentThreadingTestCase extends CommentHelperCase { + public static function getInfo() { + return array( + 'name' => 'Comment Threading', + 'description' => 'Test to make sure the comment number increments properly.', + 'group' => 'Comment', + ); + } + + /** + * Tests the comment threading. + */ + function testCommentThreading() { + $langcode = LANGUAGE_NONE; + // Set comments to have a subject with preview disabled. + $this->drupalLogin($this->admin_user); + $this->setCommentPreview(DRUPAL_DISABLED); + $this->setCommentForm(TRUE); + $this->setCommentSubject(TRUE); + $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.')); + $this->drupalLogout(); + + // Create a node. + $this->drupalLogin($this->web_user); + $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid)); + + // Post comment #1. + $this->drupalLogin($this->web_user); + $subject_text = $this->randomName(); + $comment_text = $this->randomName(); + $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); + $comment_loaded = comment_load($comment->id); + $this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.'); + $this->assertEqual($comment_loaded->thread, '01/'); + + // Reply to comment #1 creating comment #2. + $this->drupalLogin($this->web_user); + $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); + $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); + $reply_loaded = comment_load($reply->id); + $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.'); + $this->assertEqual($reply_loaded->thread, '01.00/'); + + // Reply to comment #2 creating comment #3. + $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id); + $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); + $reply_loaded = comment_load($reply->id); + $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.'); + $this->assertEqual($reply_loaded->thread, '01.00.00/'); + + // Reply to comment #1 creating comment #4. + $this->drupalLogin($this->web_user); + $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); + $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); + $reply_loaded = comment_load($reply->id); + $this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.'); + $this->assertEqual($reply_loaded->thread, '01.01/'); + + // Post comment #2 overall comment #5. + $this->drupalLogin($this->web_user); + $subject_text = $this->randomName(); + $comment_text = $this->randomName(); + $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); + $comment_loaded = comment_load($comment->id); + $this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.'); + $this->assertEqual($comment_loaded->thread, '02/'); + + // Reply to comment #5 creating comment #6. + $this->drupalLogin($this->web_user); + $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); + $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); + $reply_loaded = comment_load($reply->id); + $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.'); + $this->assertEqual($reply_loaded->thread, '02.00/'); + + // Reply to comment #6 creating comment #7. + $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id); + $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); + $reply_loaded = comment_load($reply->id); + $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.'); + $this->assertEqual($reply_loaded->thread, '02.00.00/'); + + // Reply to comment #5 creating comment #8. + $this->drupalLogin($this->web_user); + $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); + $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); + $reply_loaded = comment_load($reply->id); + $this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.'); + $this->assertEqual($reply_loaded->thread, '02.01/'); + } +} |