CommentInterfaceTest.php 8.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Definition of Drupal\comment\Tests\CommentInterfaceTest.
 */

namespace Drupal\comment\Tests;

10
11
12
/**
 * Tests the comment module administrative and end-user-facing interfaces.
 */
13
class CommentInterfaceTest extends CommentTestBase {
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  public static function getInfo() {
    return array(
      'name' => 'Comment interface',
      'description' => 'Test comment user interfaces.',
      'group' => 'Comment',
    );
  }

  /**
   * Tests the comment interface.
   */
  function testCommentInterface() {
    $langcode = LANGUAGE_NOT_SPECIFIED;
    // Set comments to have subject and preview disabled.
    $this->drupalLogin($this->admin_user);
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(FALSE);
33
    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
34
35
36
37
38
39
    $this->drupalLogout();

    // Post comment #1 without subject or preview.
    $this->drupalLogin($this->web_user);
    $comment_text = $this->randomName();
    $comment = $this->postComment($this->node, $comment_text);
40
    $this->assertTrue($this->commentExists($comment), 'Comment found.');
41
42
43
44
45
46
47
48
49
50
51
52
53

    // Set comments to have subject and preview to required.
    $this->drupalLogout();
    $this->drupalLogin($this->admin_user);
    $this->setCommentSubject(TRUE);
    $this->setCommentPreview(DRUPAL_REQUIRED);
    $this->drupalLogout();

    // Create comment #2 that allows subject and requires preview.
    $this->drupalLogin($this->web_user);
    $subject_text = $this->randomName();
    $comment_text = $this->randomName();
    $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
54
    $this->assertTrue($this->commentExists($comment), 'Comment found.');
55
56

    // Check comment display.
57
    $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id());
58
59
    $this->assertText($subject_text, 'Individual comment subject found.');
    $this->assertText($comment_text, 'Individual comment body found.');
60
61
62
63
64
65
66
67

    // Set comments to have subject and preview to optional.
    $this->drupalLogout();
    $this->drupalLogin($this->admin_user);
    $this->setCommentSubject(TRUE);
    $this->setCommentPreview(DRUPAL_OPTIONAL);

    // Test changing the comment author to "Anonymous".
68
69
70
    $this->drupalGet('comment/' . $comment->id() . '/edit');
    $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => ''));
    $this->assertTrue(empty($comment->name->value) && $comment->uid->value == 0, 'Comment author successfully changed to anonymous.');
71
72
73

    // Test changing the comment author to an unverified user.
    $random_name = $this->randomName();
74
75
    $this->drupalGet('comment/' . $comment->id() . '/edit');
    $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $random_name));
76
    $this->drupalGet('node/' . $this->node->nid);
77
    $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.');
78
79

    // Test changing the comment author to a verified user.
80
81
82
    $this->drupalGet('comment/' . $comment->id() . '/edit');
    $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $this->web_user->name));
    $this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->value == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
83
84
85
86
87
88

    $this->drupalLogout();

    // Reply to comment #2 creating comment #3 with optional preview and no
    // subject though field enabled.
    $this->drupalLogin($this->web_user);
89
    $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id());
90
91
    $this->assertText($subject_text, 'Individual comment-reply subject found.');
    $this->assertText($comment_text, 'Individual comment-reply body found.');
92
    $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
93
    $reply_loaded = comment_load($reply->id());
94
    $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
95
96
    $this->assertEqual($comment->id(), $reply_loaded->pid->value, 'Pid of a reply to a comment is set correctly.');
    $this->assertEqual(rtrim($comment->thread->value, '/') . '.00/', $reply_loaded->thread->value, 'Thread of reply grows correctly.');
97
98

    // Second reply to comment #3 creating comment #4.
99
    $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id());
100
    $this->assertText($subject_text, 'Individual comment-reply subject found.');
101
    $this->assertText($comment_text, 'Individual comment-reply body found.');
102
    $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
103
    $reply_loaded = comment_load($reply->id());
104
    $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.');
105
    $this->assertEqual(rtrim($comment->thread->value, '/') . '.01/', $reply_loaded->thread->value, 'Thread of second reply grows correctly.');
106
107

    // Edit reply.
108
    $this->drupalGet('comment/' . $reply->id() . '/edit');
109
    $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
110
    $this->assertTrue($this->commentExists($reply, TRUE), 'Modified reply found.');
111
112
113

    // Correct link count
    $this->drupalGet('node');
114
    $this->assertRaw('4 comments', 'Link to the 4 comments exist.');
115
116
117
118

    // Confirm a new comment is posted to the correct page.
    $this->setCommentsPerPage(2);
    $comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
119
    $this->assertTrue($this->commentExists($comment_new_page), 'Page one exists. %s');
120
    $this->drupalGet('node/' . $this->node->nid, array('query' => array('page' => 1)));
121
    $this->assertTrue($this->commentExists($reply, TRUE), 'Page two exists. %s');
122
123
124
    $this->setCommentsPerPage(50);

    // Attempt to reply to an unpublished comment.
125
    $reply_loaded->status->value = COMMENT_NOT_PUBLISHED;
126
    $reply_loaded->save();
127
    $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply_loaded->id());
128
129
130
131
    $this->assertText(t('The comment you are replying to does not exist.'), 'Replying to an unpublished comment');

    // Attempt to post to node with comments disabled.
    $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_HIDDEN));
132
    $this->assertTrue($this->node, 'Article node created.');
133
    $this->drupalGet('comment/reply/' . $this->node->nid);
134
135
    $this->assertText('This discussion is closed', 'Posting to node with comments disabled');
    $this->assertNoField('edit-comment', 'Comment body field found.');
136
137
138

    // Attempt to post to node with read-only comments.
    $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_CLOSED));
139
    $this->assertTrue($this->node, 'Article node created.');
140
    $this->drupalGet('comment/reply/' . $this->node->nid);
141
142
    $this->assertText('This discussion is closed', 'Posting to node with comments read-only');
    $this->assertNoField('edit-comment', 'Comment body field found.');
143
144
145

    // Attempt to post to node with comments enabled (check field names etc).
    $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
146
    $this->assertTrue($this->node, 'Article node created.');
147
    $this->drupalGet('comment/reply/' . $this->node->nid);
148
149
    $this->assertNoText('This discussion is closed', 'Posting to node with comments enabled');
    $this->assertField('edit-comment-body-' . $langcode . '-0-value', 'Comment body field found.');
150
151
152
153
154
155
156
157

    // Delete comment and make sure that reply is also removed.
    $this->drupalLogout();
    $this->drupalLogin($this->admin_user);
    $this->deleteComment($comment);
    $this->deleteComment($comment_new_page);

    $this->drupalGet('node/' . $this->node->nid);
158
159
    $this->assertFalse($this->commentExists($comment), 'Comment not found.');
    $this->assertFalse($this->commentExists($reply, TRUE), 'Reply not found.');
160
161
162
163
164
165
166
167
168
169

    // Enabled comment form on node page.
    $this->drupalLogin($this->admin_user);
    $this->setCommentForm(TRUE);
    $this->drupalLogout();

    // Submit comment through node form.
    $this->drupalLogin($this->web_user);
    $this->drupalGet('node/' . $this->node->nid);
    $form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
170
    $this->assertTrue($this->commentExists($form_comment), 'Form comment found.');
171
172
173
174
175
176
177

    // Disable comment form on node page.
    $this->drupalLogout();
    $this->drupalLogin($this->admin_user);
    $this->setCommentForm(FALSE);
  }
}