diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index d69ea94..82d8541 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -2129,24 +2129,25 @@ function template_preprocess_comment(&$variables) {
   else {
     $variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';
   }
-  // Gather comment classes.
+
+  // Gather comment classes. Published class is not needed, it is either
+  // 'comment-preview' or 'comment-unpublished'.
+  if ($variables['status'] != 'comment-published') {
+    $variables['classes_array'][] = $variables['status'];
+  }
   if ($comment->uid == 0) {
     $variables['classes_array'][] = 'comment-by-anonymous';
   }
   else {
-    // Published class is not needed. It is either 'comment-preview' or 'comment-unpublished'.
-    if ($variables['status'] != 'comment-published') {
-      $variables['classes_array'][] = $variables['status'];
-    }
-    if ($comment->uid === $variables['node']->uid) {
+    if ($comment->uid == $variables['node']->uid) {
       $variables['classes_array'][] = 'comment-by-node-author';
     }
-    if ($comment->uid === $variables['user']->uid) {
+    if ($comment->uid == $variables['user']->uid) {
       $variables['classes_array'][] = 'comment-by-viewer';
     }
-    if ($variables['new']) {
-      $variables['classes_array'][] = 'comment-new';
-    }
+  }
+  if ($variables['new']) {
+    $variables['classes_array'][] = 'comment-new';
   }
 }
 
diff --git a/core/modules/comment/comment.test b/core/modules/comment/comment.test
index 3911a29..a5678a4 100644
--- a/core/modules/comment/comment.test
+++ b/core/modules/comment/comment.test
@@ -341,8 +341,6 @@ class CommentInterfaceTest extends CommentHelperCase {
     $comment = $this->postComment($this->node, $comment_text);
     $comment_loaded = comment_load($comment->id);
     $this->assertTrue($this->commentExists($comment), t('Comment found.'));
-    $by_viewer_class = $this->xpath('//a[@id=:comment_id]/following-sibling::div[1][contains(@class, "comment-by-viewer")]', array(':comment_id' => 'comment-' . $comment->id));
-    $this->assertTrue(!empty($by_viewer_class), t('HTML class for comments by viewer found.'));
 
     // Set comments to have subject and preview to required.
     $this->drupalLogout();
@@ -429,11 +427,6 @@ class CommentInterfaceTest extends CommentHelperCase {
     $this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s'));
     $this->setCommentsPerPage(50);
 
-    // Create comment #5 to assert HTML class.
-    $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
-    $by_node_author_class = $this->xpath('//a[@id=:comment_id]/following-sibling::div[1][contains(@class, "comment-by-node-author")]', array(':comment_id' => 'comment-' . $comment->id));
-    $this->assertTrue(!empty($by_node_author_class), t('HTML class for node author found.'));
-
     // Attempt to post to node with comments disabled.
     $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_HIDDEN));
     $this->assertTrue($this->node, t('Article node created.'));
@@ -483,6 +476,116 @@ class CommentInterfaceTest extends CommentHelperCase {
   }
 
   /**
+   * Tests the comment classes.
+   */
+  function testCommentClasses() {
+    // Create all comment/user/node permutations.
+    $parameters = array(
+      'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
+      'node_uid' => array(0, $this->web_user->uid),
+      'user' => array('anonymous', 'autheticated', 'admin'),
+      'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
+    );
+    $permutations = $this->generatePermutations($parameters);
+
+    foreach ($permutations as $case) {
+      // Create a new node.
+      $node = $this->drupalCreateNode(array('type' => 'article', 'uid' => $case['node_uid']));
+
+      // Add a comment.
+      $comment = entity_create('comment', array(
+        'cid' => NULL,
+        'nid' => $node->nid,
+        'node_type' => $node->type,
+        'pid' => 0,
+        'uid' => $case['comment_uid'],
+        'status' => $case['comment_status'],
+        'subject' => $this->randomName(),
+        'hostname' => ip_address(),
+        'language' => LANGUAGE_NONE,
+        'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
+      ));
+      comment_save($comment);
+
+      // Set the viewer user.
+      switch ($case['user']) {
+        case 'autheticated':
+          $this->drupalLogin($this->web_user);
+          $case['user_id'] = $this->web_user->uid;
+          break;
+        case 'admin':
+          $this->drupalLogin($this->admin_user);
+          $case['user_id'] = $this->admin_user->uid;
+          break;
+        default:
+          // Anonymous user.
+          $this->drupalLogout();
+          $case['user_id'] = 0;
+      }
+
+      // Recover the node with the comment.
+      $this->drupalGet('node/' . $node->nid);
+
+      // Check for the comment-by-anonymous class.
+      if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+        $anonymous_class = $this->xpath('//div[contains(@class, "comment-by-anonymous")]');
+        if ($case['comment_uid'] == 0) {
+          $this->assertTrue(!empty($anonymous_class), 'comment-by-anonymous classt found.');
+        }
+        else {
+          $this->assertFalse($anonymous_class, 'comment-by-anonymous class not found.');
+        }
+      }
+
+      // Check for the comment-by-node-author class.
+      if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+        $author_class = $this->xpath('//div[contains(@class, "comment-by-node-author")]');
+        if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
+          $this->assertTrue(!empty($author_class), 'comment-by-node-author class found.');
+        }
+        else {
+          $this->assertFalse($author_class, 'comment-by-node-author class not found.');
+        }
+      }
+
+      // Check for the comment-by-viewer class.
+      if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+        $viewer_class = $this->xpath('//div[contains(@class, "comment-by-viewer")]');
+        if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user_id']) {
+          $this->assertTrue(!empty($viewer_class), 'comment-by-viewer class found.');
+        }
+        else {
+          $this->assertFalse($viewer_class, 'comment-by-viewer class not found.');
+        }
+      }
+
+      // Check for the comment-unpublished class.
+      $unpublished_class = $this->xpath('//div[contains(@class, "comment-unpublished")]');
+      if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') {
+        $this->assertTrue(!empty($unpublished_class), 'comment-unpublished class found.');
+      }
+      else {
+        $this->assertFalse($unpublished_class, 'comment-unpublished class not found.');
+      }
+
+      // Check for the comment-new class.
+      if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+        $new_class = $this->xpath('//div[contains(@class, "comment-new")]');
+        if ($case['user'] != 'anonymous') {
+          $this->assertTrue(!empty($new_class), 'comment-new class found.');
+          // Recover again the node. The comment-new class should disappear.
+          $this->drupalGet('node/' . $node->nid);
+          $new_class = $this->xpath('//div[contains(@class, "comment-new")]');
+          $this->assertFalse($new_class, 'comment-new class not found.');
+        }
+        else {
+          $this->assertFalse($new_class, 'comment-new class not found.');
+        }
+      }
+    }
+  }
+
+  /**
    * Tests the node comment statistics.
    */
   function testCommentNodeCommentStatistics() {
@@ -982,8 +1085,6 @@ class CommentAnonymous extends CommentHelperCase {
     // Post anonymous comment without contact info.
     $anonymous_comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
     $this->assertTrue($this->commentExists($anonymous_comment1), t('Anonymous comment without contact info found.'));
-    $anonymous_class = $this->xpath('//a[@id=:comment_id]/following-sibling::div[1][contains(@class, "comment-by-anonymous")]', array(':comment_id' => 'comment-' . $anonymous_comment1->id));
-    $this->assertTrue(!empty($anonymous_class), t('HTML class for anonymous comments found.'));
 
     // Allow contact info.
     $this->drupalLogin($this->admin_user);
