From ef244365561d38987bb92bd0ab33bfc331156408 Mon Sep 17 00:00:00 2001 From: Angie Byron <webchick@24967.no-reply.drupal.org> Date: Tue, 28 Dec 2010 18:19:23 +0000 Subject: [PATCH] #1005004 by markabur, bfroehle: Fixed critical Editing a comment destroys its creation date --- modules/comment/comment.module | 2 +- modules/comment/comment.test | 39 +++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/modules/comment/comment.module b/modules/comment/comment.module index fe3584b17fff..01f7f9443089 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1910,7 +1910,7 @@ function comment_form($form, &$form_state, $comment) { if ($is_admin) { $author = (!$comment->uid && $comment->name ? $comment->name : $comment->registered_name); $status = (isset($comment->status) ? $comment->status : COMMENT_NOT_PUBLISHED); - $date = (!empty($comment->date) ? $comment->date : format_date($comment->changed, 'custom', 'Y-m-d H:i O')); + $date = (!empty($comment->date) ? $comment->date : format_date($comment->created, 'custom', 'Y-m-d H:i O')); } else { if ($user->uid) { diff --git a/modules/comment/comment.test b/modules/comment/comment.test index fbef5d7a8944..dad144c77e17 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -519,9 +519,9 @@ class CommentPreviewTest extends CommentHelperCase { } /** - * Test comment edit and preview. + * Test comment edit, preview, and save. */ - function testCommentEditPreview() { + function testCommentEditPreviewSave() { $langcode = LANGUAGE_NONE; $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval')); $this->drupalLogin($this->admin_user); @@ -535,7 +535,9 @@ class CommentPreviewTest extends CommentHelperCase { $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16); $edit['name'] = $web_user->name; $edit['date'] = '2008-03-02 17:23 +0300'; - $expected_date = format_date(strtotime($edit['date'])); + $raw_date = strtotime($edit['date']); + $expected_text_date = format_date($raw_date); + $expected_form_date = format_date($raw_date, 'custom', 'Y-m-d H:i O'); $comment = $this->postComment($this->node, $edit['subject'], $edit['comment_body[' . $langcode . '][0][value]'], TRUE); $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Preview')); @@ -544,13 +546,40 @@ class CommentPreviewTest extends CommentHelperCase { $this->assertText($edit['subject'], t('Subject displayed.')); $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], t('Comment displayed.')); $this->assertText($edit['name'], t('Author displayed.')); - $this->assertText($expected_date, t('Date displayed.')); + $this->assertText($expected_text_date, t('Date displayed.')); - // Check that the title and body fields are displayed with the correct values. + // Check that the subject, comment, author and date 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.')); $this->assertFieldByName('name', $edit['name'], t('Author field displayed.')); $this->assertFieldByName('date', $edit['date'], t('Date field displayed.')); + + // Check that saving a comment produces a success message. + $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Save')); + $this->assertText(t('Your comment has been posted.'), t('Comment posted.')); + + // Check that the comment fields are correct after loading the saved comment. + $this->drupalGet('comment/' . $comment->id . '/edit'); + $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.')); + $this->assertFieldByName('name', $edit['name'], t('Author field displayed.')); + $this->assertFieldByName('date', $expected_form_date, t('Date field displayed.')); + + // Submit the form using the displayed values. + $displayed = array(); + $displayed['subject'] = (string) current($this->xpath("//input[@id='edit-subject']/@value")); + $displayed['comment_body[' . $langcode . '][0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-" . $langcode . "-0-value']")); + $displayed['name'] = (string) current($this->xpath("//input[@id='edit-name']/@value")); + $displayed['date'] = (string) current($this->xpath("//input[@id='edit-date']/@value")); + $this->drupalPost('comment/' . $comment->id . '/edit', $displayed, t('Save')); + + // Check that the saved comment is still correct. + $comment_loaded = comment_load($comment->id); + $this->assertEqual($comment_loaded->subject, $edit['subject'], t('Subject loaded.')); + $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], t('Comment body loaded.')); + $this->assertEqual($comment_loaded->name, $edit['name'], t('Name loaded.')); + $this->assertEqual($comment_loaded->created, $raw_date, t('Date loaded.')); + } } -- GitLab