summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-10-15 04:57:55 (GMT)
committerwebchick2013-10-15 04:57:55 (GMT)
commit945efa05c35d6ecfc20a63570d50a4fad7eb1354 (patch)
tree664b116a7bdc4e74e6827d0eb0227decc135f6a7
parentf31fbaa21aff385d86866b3985cd5db08ed14190 (diff)
Issue #1374090 by droplet, Pancho, G.I.Joe, marthinal, brenda003, jfhovinne: Fixed Editing a comment still changes creation date.
-rw-r--r--core/modules/comment/lib/Drupal/comment/CommentFormController.php7
-rw-r--r--core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php13
2 files changed, 17 insertions, 3 deletions
diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php
index ecbe5b2..50e7caf 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php
@@ -110,7 +110,6 @@ class CommentFormController extends ContentEntityFormController {
if ($is_admin) {
$author = $comment->name->value;
$status = (isset($comment->status->value) ? $comment->status->value : COMMENT_NOT_PUBLISHED);
- $date = (!empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value));
if (empty($form_state['comment_preview'])) {
$form['#title'] = $this->t('Edit comment %title', array(
'%title' => $comment->subject->value,
@@ -125,7 +124,11 @@ class CommentFormController extends ContentEntityFormController {
$author = ($comment->name->value ? $comment->name->value : '');
}
$status = ($this->currentUser->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED);
- $date = '';
+ }
+
+ $date = '';
+ if ($comment->id()) {
+ $date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value);
}
// Add the author name field depending on the current user.
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php
index f940c4a..387c2a3 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php
@@ -102,7 +102,7 @@ class CommentPreviewTest extends CommentTestBase {
* Tests comment edit, preview, and save.
*/
function testCommentEditPreviewSave() {
- $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);
@@ -164,6 +164,17 @@ class CommentPreviewTest extends CommentTestBase {
$this->assertEqual($comment_loaded->comment_body->value, $edit['comment_body[0][value]'], 'Comment body loaded.');
$this->assertEqual($comment_loaded->name->value, $edit['name'], 'Name loaded.');
$this->assertEqual($comment_loaded->created->value, $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->value;
+ $this->drupalLogin($web_user);
+ $this->drupalPostForm('comment/' . $comment->id() . '/edit', $user_edit, t('Save'));
+ $comment_loaded = comment_load($comment->id(), TRUE);
+ $this->assertEqual($comment_loaded->created->value, $expected_created_time, 'Expected date and time for comment edited.');
+ $this->drupalLogout();
}
}