? sites/all/modules/devel
? sites/default/files
? sites/default/settings.php
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.931
diff -u -p -r1.931 comment.module
--- modules/comment/comment.module	2 Jan 2011 23:54:05 -0000	1.931
+++ modules/comment/comment.module	3 Jan 2011 01:19:35 -0000
@@ -1489,7 +1489,7 @@ function comment_save($comment) {
       db_ignore_slave();
 
       // Update the {node_comment_statistics} table prior to executing hooks.
-       _comment_update_node_statistics($comment->nid);
+      _comment_update_node_statistics($comment->nid);
 
       field_attach_update('comment', $comment);
       // Allow modules to respond to the updating of a comment.
@@ -1929,11 +1929,9 @@ function comment_form($form, &$form_stat
       '#default_value' => $author,
       '#maxlength' => 60,
       '#size' => 30,
+      '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
+      '#autocomplete_path' => 'user/autocomplete',
     );
-    // If the comment is by a registered user, allow to autocomplete username.
-    if ($comment->registered_name != '') {
-      $form['author']['name']['#autocomplete_path'] = 'user/autocomplete';
-    }
   }
   elseif ($user->uid) {
     $form['author']['_author'] = array(
@@ -2114,18 +2112,21 @@ function comment_form_validate($form, &$
   entity_form_field_validate('comment', $form, $form_state);
 
   if (!empty($form_state['values']['cid'])) {
+    // Verify the name in case it is being changed from being anonymous.
+    $account = user_load_by_name($form_state['values']['name']);
+    $form_state['values']['uid'] = $account ? $account->uid : 0;
+
     if ($form_state['values']['date'] && strtotime($form_state['values']['date']) === FALSE) {
       form_set_error('date', t('You have to specify a valid date.'));
     }
-    if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account = user_load_by_name($form_state['values']['name'])) {
+    if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) {
       form_set_error('name', t('You have to specify a valid author.'));
     }
   }
-
-  // Validate anonymous comment author fields (if given).
-  if ($form_state['values']['is_anonymous']) {
-    // If the (original) author of this comment was an anonymous user, verify
-    // that no registered user with this name exists.
+  elseif ($form_state['values']['is_anonymous']) {
+    // Validate anonymous comment author fields (if given). If the (original)
+    // author of this comment was an anonymous user, verify that no registered
+    // user with this name exists.
     if ($form_state['values']['name']) {
       $query = db_select('users', 'u');
       $query->addField('u', 'uid', 'uid');
Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.98
diff -u -p -r1.98 comment.test
--- modules/comment/comment.test	2 Jan 2011 23:54:05 -0000	1.98
+++ modules/comment/comment.test	3 Jan 2011 01:19:35 -0000
@@ -303,6 +303,26 @@ class CommentInterfaceTest extends Comme
     $this->drupalLogin($this->admin_user);
     $this->setCommentSubject(TRUE);
     $this->setCommentPreview(DRUPAL_OPTIONAL);
+
+    // Test changing the comment author to "Anonymous".
+    $this->drupalGet('comment/' . $comment->id . '/edit');
+    $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => ''));
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, t('Comment author successfully changed to anonymous.'));
+
+    // Test changing the comment author to an unverified user.
+    $random_name = $this->randomName();
+    $this->drupalGet('comment/' . $comment->id . '/edit');
+    $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $random_name));
+    $this->drupalGet('node/' . $this->node->nid);
+    $this->assertText($random_name . ' (' . t('not verified') . ')', t('Comment author successfully changed to an unverified user.'));
+
+    // Test changing the comment author to a verified user.
+    $this->drupalGet('comment/' . $comment->id . '/edit');
+    $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name));
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, t('Comment author successfully changed to a registered user.'));
+
     $this->drupalLogout();
 
     // Reply to comment #2 creating comment #3 with optional preview and no
