summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-09 00:55:50 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-09 00:55:50 +0000
commit70d6b3360ee72a850bf86cc3cdae3ed59d857aea (patch)
treef5544ec1a30cf374f8358e4c316f07a10c5211f6
parent0355caac417d92973f4913efbb19342ae352bf2e (diff)
downloadbrdo-70d6b3360ee72a850bf86cc3cdae3ed59d857aea.tar.gz
brdo-70d6b3360ee72a850bf86cc3cdae3ed59d857aea.tar.bz2
#524652 follow-up by tic2000 and yched: Fix comment preview bug and add tests.
-rw-r--r--modules/comment/comment.module8
-rw-r--r--modules/comment/comment.test77
2 files changed, 81 insertions, 4 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 6b54c4961..06f13dea1 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -1882,10 +1882,10 @@ function comment_preview($comment) {
$comment->format = $comment->comment_format;
// Attach the user and time information.
- if (!empty($edit['author'])) {
- $account = user_load_by_name($edit['author']);
+ if (!empty($comment->author)) {
+ $account = user_load_by_name($comment->author);
}
- elseif ($user->uid && !isset($edit['is_anonymous'])) {
+ elseif ($user->uid && !isset($comment->is_anonymous)) {
$account = $user;
}
@@ -1897,7 +1897,7 @@ function comment_preview($comment) {
$comment->name = variable_get('anonymous', t('Anonymous'));
}
- $comment->timestamp = !empty($edit['timestamp']) ? $edit['timestamp'] : REQUEST_TIME;
+ $comment->timestamp = !empty($comment->timestamp) ? $comment->timestamp : REQUEST_TIME;
$comment->in_preview = TRUE;
$comment_build = comment_build($comment);
$comment_build += array(
diff --git a/modules/comment/comment.test b/modules/comment/comment.test
index 588d7ae82..039dbfe6f 100644
--- a/modules/comment/comment.test
+++ b/modules/comment/comment.test
@@ -361,6 +361,83 @@ class CommentInterfaceTest extends CommentHelperCase {
}
}
+/**
+ * Test previewing comments.
+ */
+class CommentPreviewTest extends CommentHelperCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment preview',
+ 'description' => 'Test comment preview.',
+ 'group' => 'Comment',
+ );
+ }
+
+ /**
+ * Test comment preview.
+ */
+ function testCommentPreview() {
+ // As admin user, configure comment settings.
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(TRUE);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $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.
+ $this->drupalLogin($this->web_user);
+ $edit = array();
+ $edit['subject'] = $this->randomName(8);
+ $edit['comment'] = $this->randomName(16);
+ $this->drupalPost('node/' . $this->node->nid, $edit, t('Preview'));
+
+ // Check that the preview is displaying the title and body.
+ $this->assertTitle(t('Preview comment | Drupal'), t('Page title is "Preview comment".'));
+ $this->assertText($edit['subject'], t('Subject displayed.'));
+ $this->assertText($edit['comment'], t('Comment displayed.'));
+
+ // 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', $edit['comment'], t('Comment field displayed.'));
+ }
+
+ /**
+ * Test comment edit and preview.
+ */
+ function testCommentEditPreview() {
+ $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'post comments without approval'));
+ $this->drupalLogin($this->admin_user);
+ $this->setCommentPreview(TRUE);
+ $this->setCommentForm(TRUE);
+ $this->setCommentSubject(TRUE);
+ $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
+
+ $edit = array();
+ $edit['subject'] = $this->randomName(8);
+ $edit['comment'] = $this->randomName(16);
+ $edit['author'] = $web_user->name;
+ $edit['date'] = '2008-03-02 17:23 +0300';
+ $expected_date = format_date(strtotime($edit['date']));
+ $comment = $this->postComment($this->node, $edit['subject'], $edit['comment'], TRUE);
+ $this->drupalPost('comment/edit/' . $comment->id, $edit, t('Preview'));
+
+ // Check that the preview is displaying the subject, comment, author and date correctly.
+ $this->assertTitle(t('Preview comment | Drupal'), t('Page title is "Preview comment".'));
+ $this->assertText($edit['subject'], t('Subject displayed.'));
+ $this->assertText($edit['comment'], t('Comment displayed.'));
+ $this->assertText($edit['author'], t('Author displayed.'));
+ $this->assertText($expected_date, t('Date displayed.'));
+
+ // 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', $edit['comment'], t('Comment field displayed.'));
+ $this->assertFieldByName('author', $edit['author'], t('Author field displayed.'));
+ $this->assertFieldByName('date', $edit['date'], t('Date field displayed.'));
+ }
+
+}
+
class CommentAnonymous extends CommentHelperCase {
public static function getInfo() {
return array(