diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 3c94200..84802e4 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1914,7 +1914,6 @@ 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->created, 'custom', 'Y-m-d H:i O')); } else { if ($user->uid) { @@ -1924,7 +1923,11 @@ function comment_form($form, &$form_state, $comment) { $author = ($comment->name ? $comment->name : ''); } $status = (user_access('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED); - $date = ''; + } + + $date = ''; + if ($comment->id()) { + $date = !empty($comment->date) ? $comment->date : format_date($comment->created, 'custom', 'Y-m-d H:i:s O'); } // Add the author name field depending on the current user. diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 9e69ba6..a49a4f0 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -995,7 +995,7 @@ function testCommentPreview() { */ function testCommentEditPreviewSave() { $langcode = LANGUAGE_NONE; - $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval')); + $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'edit own comments')); $this->drupalLogin($this->admin_user); $this->setCommentPreview(DRUPAL_OPTIONAL); $this->setCommentForm(TRUE); @@ -1009,7 +1009,7 @@ function testCommentEditPreviewSave() { $edit['date'] = '2008-03-02 17:23 +0300'; $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'); + $expected_form_date = format_date($raw_date, 'custom', 'Y-m-d H:i:s O'); $comment = $this->postComment($this->node, $edit['subject'], $edit['comment_body[' . $langcode . '][0][value]'], TRUE); $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Preview')); @@ -1051,7 +1051,17 @@ function testCommentEditPreviewSave() { $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], 'Comment body loaded.'); $this->assertEqual($comment_loaded->name, $edit['name'], 'Name loaded.'); $this->assertEqual($comment_loaded->created, $raw_date, 'Date loaded.'); + $this->drupalLogout(); + // Check that the date and time of the comment are correct when edited by + // non-admin users. + $user_edit = array(); + $expected_created_time = $comment_loaded->created; + $this->drupalLogin($web_user); + $this->drupalPost('comment/' . $comment->id . '/edit', $user_edit, t('Save')); + $comment_loaded = comment_load($comment->id, TRUE); + $this->assertEqual($comment_loaded->created, $expected_created_time, 'Expected date and time for comment edited.'); + $this->drupalLogout(); } }