summaryrefslogtreecommitdiff
path: root/modules/comment
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2012-01-30 20:59:06 -0800
committerwebchick <webchick@24967.no-reply.drupal.org>2012-01-30 20:59:06 -0800
commit07c5fbae1dd1e4e46f57e0353f471c7ad30067eb (patch)
treedf4b7be2fd07af0b5564078cf56b2e81e1a77f4b /modules/comment
parentbbede7f65093c4f85a99dc94282809436effc799 (diff)
downloadbrdo-07c5fbae1dd1e4e46f57e0353f471c7ad30067eb.tar.gz
brdo-07c5fbae1dd1e4e46f57e0353f471c7ad30067eb.tar.bz2
Issue #1110650 follow-up by grendzy, oriol_e9g, sun: Fixed comment-by-anonymous class never appears.
Diffstat (limited to 'modules/comment')
-rw-r--r--modules/comment/comment.module22
-rw-r--r--modules/comment/comment.test114
2 files changed, 117 insertions, 19 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 3ec441075..2793ea3b5 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -2294,24 +2294,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/modules/comment/comment.test b/modules/comment/comment.test
index cc4687dc0..366429bdd 100644
--- a/modules/comment/comment.test
+++ b/modules/comment/comment.test
@@ -281,8 +281,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();
@@ -369,11 +367,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,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() {
@@ -970,8 +1068,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);