diff --git a/core/modules/comment/comment.test b/core/modules/comment/comment.test index 2e96ba3..a7c29e5 100644 --- a/core/modules/comment/comment.test +++ b/core/modules/comment/comment.test @@ -331,8 +331,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(); @@ -419,11 +417,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.')); @@ -473,6 +466,110 @@ class CommentInterfaceTest extends CommentHelperCase { } /** + * Tests the comment classes. + */ + function testCommentClasses() { + $langcode = LANGUAGE_NONE; + // Create all comment/user/node permutations. + $parameters = array( + 'comment_uid' => array(0, $this->web_user->uid), + 'node_uid' => array(0, $this->web_user->uid, $this->admin_user->uid), + 'user' => array(drupal_anonymous_user(), $this->web_user, $this->admin_user), + '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 = (object) 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. + if ($case['user']->uid == 0) { + // Anonymous user. + $this->drupalLogout(); + } + else { + $this->drupalLogin($case['user']); + } + + // 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']->uid == $this->admin_user->uid) { + $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']->uid == $this->admin_user->uid) { + $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']->uid == $this->admin_user->uid) { + $viewer_class = $this->xpath('//div[contains(@class, "comment-by-viewer")]'); + if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user']->uid) { + $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']->uid == $this->admin_user->uid) { + $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']->uid == $this->admin_user->uid) { + $new_class = $this->xpath('//div[contains(@class, "comment-new")]'); + if ($case['user']->uid > 0) { + $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() { @@ -970,8 +1067,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);