summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-01-31 05:00:17 (GMT)
committer webchick2012-01-31 05:00:17 (GMT)
commitd5984e1e81f0101c52293b7e217a19c6ad343ff7 (patch)
treec5e397a1d1cf8b88ec1be601bb9b7f868d6c6a1c
parent64e79ac197eb695a3d11426f39267f33d4a87249 (diff)
Issue #1110650 follow-up by grendzy, oriol_e9g, sun: Fixed comment-by-anonymous class never appears.
-rw-r--r--core/modules/comment/comment.module22
-rw-r--r--core/modules/comment/comment.test114
2 files changed, 117 insertions, 19 deletions
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 37f1c05..70218a5 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -2149,24 +2149,26 @@ function template_preprocess_comment(&$variables) {
else {
$variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';
}
+
// Gather comment classes.
- if ($comment->uid == 0) {
+ // 'comment-published' class is not needed, it is either 'comment-preview' or
+ // 'comment-unpublished'.
+ if ($variables['status'] != 'comment-published') {
+ $variables['classes_array'][] = $variables['status'];
+ }
+ if ($variables['new']) {
+ $variables['classes_array'][] = 'comment-new';
+ }
+ if (!$comment->uid) {
$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';
- }
}
}
diff --git a/core/modules/comment/comment.test b/core/modules/comment/comment.test
index 9a77853..dd74d13 100644
--- a/core/modules/comment/comment.test
+++ b/core/modules/comment/comment.test
@@ -291,8 +291,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();
@@ -379,11 +377,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,111 @@ class CommentInterfaceTest extends CommentHelperCase {
}
/**
+ * Tests CSS classes on comments.
+ */
+ function testCommentClasses() {
+ // Create all permutations for comments, users, and nodes.
+ $parameters = array(
+ 'node_uid' => array(0, $this->web_user->uid),
+ 'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
+ 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
+ 'user' => array('anonymous', 'authenticated', 'admin'),
+ );
+ $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(
+ 'nid' => $node->nid,
+ 'uid' => $case['comment_uid'],
+ 'status' => $case['comment_status'],
+ 'subject' => $this->randomName(),
+ 'language' => LANGUAGE_NONE,
+ 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
+ ));
+ comment_save($comment);
+
+ // Adjust the current/viewing user.
+ switch ($case['user']) {
+ case 'anonymous':
+ $this->drupalLogout();
+ $case['user_uid'] = 0;
+ break;
+
+ case 'authenticated':
+ $this->drupalLogin($this->web_user);
+ $case['user_uid'] = $this->web_user->uid;
+ break;
+
+ case 'admin':
+ $this->drupalLogin($this->admin_user);
+ $case['user_uid'] = $this->admin_user->uid;
+ break;
+ }
+ // Request the node with the comment.
+ $this->drupalGet('node/' . $node->nid);
+
+ // Verify classes if the comment is visible for the current user.
+ if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+ // Verify the comment-by-anonymous class.
+ $comments = $this->xpath('//*[contains(@class, "comment-by-anonymous")]');
+ if ($case['comment_uid'] == 0) {
+ $this->assertTrue(count($comments) == 1, 'comment-by-anonymous class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-by-anonymous class not found.');
+ }
+
+ // Verify the comment-by-node-author class.
+ $comments = $this->xpath('//*[contains(@class, "comment-by-node-author")]');
+ if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
+ $this->assertTrue(count($comments) == 1, 'comment-by-node-author class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-by-node-author class not found.');
+ }
+
+ // Verify the comment-by-viewer class.
+ $comments = $this->xpath('//*[contains(@class, "comment-by-viewer")]');
+ if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user_uid']) {
+ $this->assertTrue(count($comments) == 1, 'comment-by-viewer class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-by-viewer class not found.');
+ }
+ }
+
+ // Verify the comment-unpublished class.
+ $comments = $this->xpath('//*[contains(@class, "comment-unpublished")]');
+ if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') {
+ $this->assertTrue(count($comments) == 1, 'comment-unpublished class found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-unpublished class not found.');
+ }
+
+ // Verify the comment-new class.
+ if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
+ $comments = $this->xpath('//*[contains(@class, "comment-new")]');
+ if ($case['user'] != 'anonymous') {
+ $this->assertTrue(count($comments) == 1, 'comment-new class found.');
+
+ // Request the node again. The comment-new class should disappear.
+ $this->drupalGet('node/' . $node->nid);
+ $comments = $this->xpath('//*[contains(@class, "comment-new")]');
+ $this->assertFalse(count($comments), 'comment-new class not found.');
+ }
+ else {
+ $this->assertFalse(count($comments), 'comment-new class not found.');
+ }
+ }
+ }
+ }
+
+ /**
* Tests the node comment statistics.
*/
function testCommentNodeCommentStatistics() {
@@ -982,8 +1080,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);