danielebarchiesi@0
|
1 <?php
|
danielebarchiesi@0
|
2
|
danielebarchiesi@0
|
3 /**
|
danielebarchiesi@0
|
4 * @file
|
danielebarchiesi@0
|
5 * Tests for comment.module.
|
danielebarchiesi@0
|
6 */
|
danielebarchiesi@0
|
7
|
danielebarchiesi@0
|
8 class CommentHelperCase extends DrupalWebTestCase {
|
danielebarchiesi@0
|
9 protected $admin_user;
|
danielebarchiesi@0
|
10 protected $web_user;
|
danielebarchiesi@0
|
11 protected $node;
|
danielebarchiesi@0
|
12
|
danielebarchiesi@0
|
13 function setUp() {
|
danielebarchiesi@0
|
14 parent::setUp('comment', 'search');
|
danielebarchiesi@0
|
15 // Create users and test node.
|
danielebarchiesi@0
|
16 $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
|
danielebarchiesi@0
|
17 $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
|
danielebarchiesi@0
|
18 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
|
danielebarchiesi@0
|
19 }
|
danielebarchiesi@0
|
20
|
danielebarchiesi@0
|
21 /**
|
danielebarchiesi@0
|
22 * Post comment.
|
danielebarchiesi@0
|
23 *
|
danielebarchiesi@0
|
24 * @param $node
|
danielebarchiesi@0
|
25 * Node to post comment on.
|
danielebarchiesi@0
|
26 * @param $comment
|
danielebarchiesi@0
|
27 * Comment body.
|
danielebarchiesi@0
|
28 * @param $subject
|
danielebarchiesi@0
|
29 * Comment subject.
|
danielebarchiesi@0
|
30 * @param $contact
|
danielebarchiesi@0
|
31 * Set to NULL for no contact info, TRUE to ignore success checking, and
|
danielebarchiesi@0
|
32 * array of values to set contact info.
|
danielebarchiesi@0
|
33 */
|
danielebarchiesi@0
|
34 function postComment($node, $comment, $subject = '', $contact = NULL) {
|
danielebarchiesi@0
|
35 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
36 $edit = array();
|
danielebarchiesi@0
|
37 $edit['comment_body[' . $langcode . '][0][value]'] = $comment;
|
danielebarchiesi@0
|
38
|
danielebarchiesi@0
|
39 $preview_mode = variable_get('comment_preview_article', DRUPAL_OPTIONAL);
|
danielebarchiesi@0
|
40 $subject_mode = variable_get('comment_subject_field_article', 1);
|
danielebarchiesi@0
|
41
|
danielebarchiesi@0
|
42 // Must get the page before we test for fields.
|
danielebarchiesi@0
|
43 if ($node !== NULL) {
|
danielebarchiesi@0
|
44 $this->drupalGet('comment/reply/' . $node->nid);
|
danielebarchiesi@0
|
45 }
|
danielebarchiesi@0
|
46
|
danielebarchiesi@0
|
47 if ($subject_mode == TRUE) {
|
danielebarchiesi@0
|
48 $edit['subject'] = $subject;
|
danielebarchiesi@0
|
49 }
|
danielebarchiesi@0
|
50 else {
|
danielebarchiesi@0
|
51 $this->assertNoFieldByName('subject', '', 'Subject field not found.');
|
danielebarchiesi@0
|
52 }
|
danielebarchiesi@0
|
53
|
danielebarchiesi@0
|
54 if ($contact !== NULL && is_array($contact)) {
|
danielebarchiesi@0
|
55 $edit += $contact;
|
danielebarchiesi@0
|
56 }
|
danielebarchiesi@0
|
57 switch ($preview_mode) {
|
danielebarchiesi@0
|
58 case DRUPAL_REQUIRED:
|
danielebarchiesi@0
|
59 // Preview required so no save button should be found.
|
danielebarchiesi@0
|
60 $this->assertNoFieldByName('op', t('Save'), 'Save button not found.');
|
danielebarchiesi@0
|
61 $this->drupalPost(NULL, $edit, t('Preview'));
|
danielebarchiesi@0
|
62 // Don't break here so that we can test post-preview field presence and
|
danielebarchiesi@0
|
63 // function below.
|
danielebarchiesi@0
|
64 case DRUPAL_OPTIONAL:
|
danielebarchiesi@0
|
65 $this->assertFieldByName('op', t('Preview'), 'Preview button found.');
|
danielebarchiesi@0
|
66 $this->assertFieldByName('op', t('Save'), 'Save button found.');
|
danielebarchiesi@0
|
67 $this->drupalPost(NULL, $edit, t('Save'));
|
danielebarchiesi@0
|
68 break;
|
danielebarchiesi@0
|
69
|
danielebarchiesi@0
|
70 case DRUPAL_DISABLED:
|
danielebarchiesi@0
|
71 $this->assertNoFieldByName('op', t('Preview'), 'Preview button not found.');
|
danielebarchiesi@0
|
72 $this->assertFieldByName('op', t('Save'), 'Save button found.');
|
danielebarchiesi@0
|
73 $this->drupalPost(NULL, $edit, t('Save'));
|
danielebarchiesi@0
|
74 break;
|
danielebarchiesi@0
|
75 }
|
danielebarchiesi@0
|
76 $match = array();
|
danielebarchiesi@0
|
77 // Get comment ID
|
danielebarchiesi@0
|
78 preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
|
danielebarchiesi@0
|
79
|
danielebarchiesi@0
|
80 // Get comment.
|
danielebarchiesi@0
|
81 if ($contact !== TRUE) { // If true then attempting to find error message.
|
danielebarchiesi@0
|
82 if ($subject) {
|
danielebarchiesi@0
|
83 $this->assertText($subject, 'Comment subject posted.');
|
danielebarchiesi@0
|
84 }
|
danielebarchiesi@0
|
85 $this->assertText($comment, 'Comment body posted.');
|
danielebarchiesi@0
|
86 $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.');
|
danielebarchiesi@0
|
87 }
|
danielebarchiesi@0
|
88
|
danielebarchiesi@0
|
89 if (isset($match[1])) {
|
danielebarchiesi@0
|
90 return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment);
|
danielebarchiesi@0
|
91 }
|
danielebarchiesi@0
|
92 }
|
danielebarchiesi@0
|
93
|
danielebarchiesi@0
|
94 /**
|
danielebarchiesi@0
|
95 * Checks current page for specified comment.
|
danielebarchiesi@0
|
96 *
|
danielebarchiesi@0
|
97 * @param object $comment Comment object.
|
danielebarchiesi@0
|
98 * @param boolean $reply The comment is a reply to another comment.
|
danielebarchiesi@0
|
99 * @return boolean Comment found.
|
danielebarchiesi@0
|
100 */
|
danielebarchiesi@0
|
101 function commentExists($comment, $reply = FALSE) {
|
danielebarchiesi@0
|
102 if ($comment && is_object($comment)) {
|
danielebarchiesi@0
|
103 $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
|
danielebarchiesi@0
|
104 $regex .= '<a id="comment-' . $comment->id . '"(.*?)'; // Comment anchor.
|
danielebarchiesi@0
|
105 $regex .= '<div(.*?)'; // Begin in comment div.
|
danielebarchiesi@0
|
106 $regex .= $comment->subject . '(.*?)'; // Match subject.
|
danielebarchiesi@0
|
107 $regex .= $comment->comment . '(.*?)'; // Match comment.
|
danielebarchiesi@0
|
108 $regex .= '/s';
|
danielebarchiesi@0
|
109
|
danielebarchiesi@0
|
110 return (boolean)preg_match($regex, $this->drupalGetContent());
|
danielebarchiesi@0
|
111 }
|
danielebarchiesi@0
|
112 else {
|
danielebarchiesi@0
|
113 return FALSE;
|
danielebarchiesi@0
|
114 }
|
danielebarchiesi@0
|
115 }
|
danielebarchiesi@0
|
116
|
danielebarchiesi@0
|
117 /**
|
danielebarchiesi@0
|
118 * Delete comment.
|
danielebarchiesi@0
|
119 *
|
danielebarchiesi@0
|
120 * @param object $comment
|
danielebarchiesi@0
|
121 * Comment to delete.
|
danielebarchiesi@0
|
122 */
|
danielebarchiesi@0
|
123 function deleteComment($comment) {
|
danielebarchiesi@0
|
124 $this->drupalPost('comment/' . $comment->id . '/delete', array(), t('Delete'));
|
danielebarchiesi@0
|
125 $this->assertText(t('The comment and all its replies have been deleted.'), 'Comment deleted.');
|
danielebarchiesi@0
|
126 }
|
danielebarchiesi@0
|
127
|
danielebarchiesi@0
|
128 /**
|
danielebarchiesi@0
|
129 * Set comment subject setting.
|
danielebarchiesi@0
|
130 *
|
danielebarchiesi@0
|
131 * @param boolean $enabled
|
danielebarchiesi@0
|
132 * Subject value.
|
danielebarchiesi@0
|
133 */
|
danielebarchiesi@0
|
134 function setCommentSubject($enabled) {
|
danielebarchiesi@0
|
135 $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.');
|
danielebarchiesi@0
|
136 }
|
danielebarchiesi@0
|
137
|
danielebarchiesi@0
|
138 /**
|
danielebarchiesi@0
|
139 * Set comment preview setting.
|
danielebarchiesi@0
|
140 *
|
danielebarchiesi@0
|
141 * @param int $mode
|
danielebarchiesi@0
|
142 * Preview value.
|
danielebarchiesi@0
|
143 */
|
danielebarchiesi@0
|
144 function setCommentPreview($mode) {
|
danielebarchiesi@0
|
145 switch ($mode) {
|
danielebarchiesi@0
|
146 case DRUPAL_DISABLED:
|
danielebarchiesi@0
|
147 $mode_text = 'disabled';
|
danielebarchiesi@0
|
148 break;
|
danielebarchiesi@0
|
149
|
danielebarchiesi@0
|
150 case DRUPAL_OPTIONAL:
|
danielebarchiesi@0
|
151 $mode_text = 'optional';
|
danielebarchiesi@0
|
152 break;
|
danielebarchiesi@0
|
153
|
danielebarchiesi@0
|
154 case DRUPAL_REQUIRED:
|
danielebarchiesi@0
|
155 $mode_text = 'required';
|
danielebarchiesi@0
|
156 break;
|
danielebarchiesi@0
|
157 }
|
danielebarchiesi@0
|
158 $this->setCommentSettings('comment_preview', $mode, 'Comment preview ' . $mode_text . '.');
|
danielebarchiesi@0
|
159 }
|
danielebarchiesi@0
|
160
|
danielebarchiesi@0
|
161 /**
|
danielebarchiesi@0
|
162 * Set comment form location setting.
|
danielebarchiesi@0
|
163 *
|
danielebarchiesi@0
|
164 * @param boolean $enabled
|
danielebarchiesi@0
|
165 * Form value.
|
danielebarchiesi@0
|
166 */
|
danielebarchiesi@0
|
167 function setCommentForm($enabled) {
|
danielebarchiesi@0
|
168 $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
|
danielebarchiesi@0
|
169 }
|
danielebarchiesi@0
|
170
|
danielebarchiesi@0
|
171 /**
|
danielebarchiesi@0
|
172 * Set comment anonymous level setting.
|
danielebarchiesi@0
|
173 *
|
danielebarchiesi@0
|
174 * @param integer $level
|
danielebarchiesi@0
|
175 * Anonymous level.
|
danielebarchiesi@0
|
176 */
|
danielebarchiesi@0
|
177 function setCommentAnonymous($level) {
|
danielebarchiesi@0
|
178 $this->setCommentSettings('comment_anonymous', $level, 'Anonymous commenting set to level ' . $level . '.');
|
danielebarchiesi@0
|
179 }
|
danielebarchiesi@0
|
180
|
danielebarchiesi@0
|
181 /**
|
danielebarchiesi@0
|
182 * Set the default number of comments per page.
|
danielebarchiesi@0
|
183 *
|
danielebarchiesi@0
|
184 * @param integer $comments
|
danielebarchiesi@0
|
185 * Comments per page value.
|
danielebarchiesi@0
|
186 */
|
danielebarchiesi@0
|
187 function setCommentsPerPage($number) {
|
danielebarchiesi@0
|
188 $this->setCommentSettings('comment_default_per_page', $number, 'Number of comments per page set to ' . $number . '.');
|
danielebarchiesi@0
|
189 }
|
danielebarchiesi@0
|
190
|
danielebarchiesi@0
|
191 /**
|
danielebarchiesi@0
|
192 * Set comment setting for article content type.
|
danielebarchiesi@0
|
193 *
|
danielebarchiesi@0
|
194 * @param string $name
|
danielebarchiesi@0
|
195 * Name of variable.
|
danielebarchiesi@0
|
196 * @param string $value
|
danielebarchiesi@0
|
197 * Value of variable.
|
danielebarchiesi@0
|
198 * @param string $message
|
danielebarchiesi@0
|
199 * Status message to display.
|
danielebarchiesi@0
|
200 */
|
danielebarchiesi@0
|
201 function setCommentSettings($name, $value, $message) {
|
danielebarchiesi@0
|
202 variable_set($name . '_article', $value);
|
danielebarchiesi@0
|
203 // Display status message.
|
danielebarchiesi@0
|
204 $this->assertTrue(TRUE, $message);
|
danielebarchiesi@0
|
205 }
|
danielebarchiesi@0
|
206
|
danielebarchiesi@0
|
207 /**
|
danielebarchiesi@0
|
208 * Check for contact info.
|
danielebarchiesi@0
|
209 *
|
danielebarchiesi@0
|
210 * @return boolean Contact info is available.
|
danielebarchiesi@0
|
211 */
|
danielebarchiesi@0
|
212 function commentContactInfoAvailable() {
|
danielebarchiesi@0
|
213 return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent());
|
danielebarchiesi@0
|
214 }
|
danielebarchiesi@0
|
215
|
danielebarchiesi@0
|
216 /**
|
danielebarchiesi@0
|
217 * Perform the specified operation on the specified comment.
|
danielebarchiesi@0
|
218 *
|
danielebarchiesi@0
|
219 * @param object $comment
|
danielebarchiesi@0
|
220 * Comment to perform operation on.
|
danielebarchiesi@0
|
221 * @param string $operation
|
danielebarchiesi@0
|
222 * Operation to perform.
|
danielebarchiesi@0
|
223 * @param boolean $aproval
|
danielebarchiesi@0
|
224 * Operation is found on approval page.
|
danielebarchiesi@0
|
225 */
|
danielebarchiesi@0
|
226 function performCommentOperation($comment, $operation, $approval = FALSE) {
|
danielebarchiesi@0
|
227 $edit = array();
|
danielebarchiesi@0
|
228 $edit['operation'] = $operation;
|
danielebarchiesi@0
|
229 $edit['comments[' . $comment->id . ']'] = TRUE;
|
danielebarchiesi@0
|
230 $this->drupalPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update'));
|
danielebarchiesi@0
|
231
|
danielebarchiesi@0
|
232 if ($operation == 'delete') {
|
danielebarchiesi@0
|
233 $this->drupalPost(NULL, array(), t('Delete comments'));
|
danielebarchiesi@0
|
234 $this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation @operation was performed on comment.', array('@operation' => $operation)));
|
danielebarchiesi@0
|
235 }
|
danielebarchiesi@0
|
236 else {
|
danielebarchiesi@0
|
237 $this->assertText(t('The update has been performed.'), format_string('Operation @operation was performed on comment.', array('@operation' => $operation)));
|
danielebarchiesi@0
|
238 }
|
danielebarchiesi@0
|
239 }
|
danielebarchiesi@0
|
240
|
danielebarchiesi@0
|
241 /**
|
danielebarchiesi@0
|
242 * Get the comment ID for an unapproved comment.
|
danielebarchiesi@0
|
243 *
|
danielebarchiesi@0
|
244 * @param string $subject
|
danielebarchiesi@0
|
245 * Comment subject to find.
|
danielebarchiesi@0
|
246 * @return integer
|
danielebarchiesi@0
|
247 * Comment id.
|
danielebarchiesi@0
|
248 */
|
danielebarchiesi@0
|
249 function getUnapprovedComment($subject) {
|
danielebarchiesi@0
|
250 $this->drupalGet('admin/content/comment/approval');
|
danielebarchiesi@0
|
251 preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->drupalGetContent(), $match);
|
danielebarchiesi@0
|
252
|
danielebarchiesi@0
|
253 return $match[2];
|
danielebarchiesi@0
|
254 }
|
danielebarchiesi@0
|
255 }
|
danielebarchiesi@0
|
256
|
danielebarchiesi@0
|
257 class CommentInterfaceTest extends CommentHelperCase {
|
danielebarchiesi@0
|
258 public static function getInfo() {
|
danielebarchiesi@0
|
259 return array(
|
danielebarchiesi@0
|
260 'name' => 'Comment interface',
|
danielebarchiesi@0
|
261 'description' => 'Test comment user interfaces.',
|
danielebarchiesi@0
|
262 'group' => 'Comment',
|
danielebarchiesi@0
|
263 );
|
danielebarchiesi@0
|
264 }
|
danielebarchiesi@0
|
265
|
danielebarchiesi@0
|
266 /**
|
danielebarchiesi@0
|
267 * Test comment interface.
|
danielebarchiesi@0
|
268 */
|
danielebarchiesi@0
|
269 function testCommentInterface() {
|
danielebarchiesi@0
|
270 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
271 // Set comments to have subject and preview disabled.
|
danielebarchiesi@0
|
272 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
273 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
274 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
275 $this->setCommentSubject(FALSE);
|
danielebarchiesi@0
|
276 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
277 $this->drupalLogout();
|
danielebarchiesi@0
|
278
|
danielebarchiesi@0
|
279 // Post comment #1 without subject or preview.
|
danielebarchiesi@0
|
280 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
281 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
282 $comment = $this->postComment($this->node, $comment_text);
|
danielebarchiesi@0
|
283 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
284 $this->assertTrue($this->commentExists($comment), 'Comment found.');
|
danielebarchiesi@0
|
285
|
danielebarchiesi@0
|
286 // Set comments to have subject and preview to required.
|
danielebarchiesi@0
|
287 $this->drupalLogout();
|
danielebarchiesi@0
|
288 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
289 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
290 $this->setCommentPreview(DRUPAL_REQUIRED);
|
danielebarchiesi@0
|
291 $this->drupalLogout();
|
danielebarchiesi@0
|
292
|
danielebarchiesi@0
|
293 // Create comment #2 that allows subject and requires preview.
|
danielebarchiesi@0
|
294 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
295 $subject_text = $this->randomName();
|
danielebarchiesi@0
|
296 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
297 $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
|
danielebarchiesi@0
|
298 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
299 $this->assertTrue($this->commentExists($comment), 'Comment found.');
|
danielebarchiesi@0
|
300
|
danielebarchiesi@0
|
301 // Check comment display.
|
danielebarchiesi@0
|
302 $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
303 $this->assertText($subject_text, 'Individual comment subject found.');
|
danielebarchiesi@0
|
304 $this->assertText($comment_text, 'Individual comment body found.');
|
danielebarchiesi@0
|
305
|
danielebarchiesi@0
|
306 // Set comments to have subject and preview to optional.
|
danielebarchiesi@0
|
307 $this->drupalLogout();
|
danielebarchiesi@0
|
308 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
309 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
310 $this->setCommentPreview(DRUPAL_OPTIONAL);
|
danielebarchiesi@0
|
311
|
danielebarchiesi@0
|
312 // Test changing the comment author to "Anonymous".
|
danielebarchiesi@0
|
313 $this->drupalGet('comment/' . $comment->id . '/edit');
|
danielebarchiesi@0
|
314 $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => ''));
|
danielebarchiesi@0
|
315 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
316 $this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, 'Comment author successfully changed to anonymous.');
|
danielebarchiesi@0
|
317
|
danielebarchiesi@0
|
318 // Test changing the comment author to an unverified user.
|
danielebarchiesi@0
|
319 $random_name = $this->randomName();
|
danielebarchiesi@0
|
320 $this->drupalGet('comment/' . $comment->id . '/edit');
|
danielebarchiesi@0
|
321 $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $random_name));
|
danielebarchiesi@0
|
322 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
323 $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.');
|
danielebarchiesi@0
|
324
|
danielebarchiesi@0
|
325 // Test changing the comment author to a verified user.
|
danielebarchiesi@0
|
326 $this->drupalGet('comment/' . $comment->id . '/edit');
|
danielebarchiesi@0
|
327 $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name));
|
danielebarchiesi@0
|
328 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
329 $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
|
danielebarchiesi@0
|
330
|
danielebarchiesi@0
|
331 $this->drupalLogout();
|
danielebarchiesi@0
|
332
|
danielebarchiesi@0
|
333 // Reply to comment #2 creating comment #3 with optional preview and no
|
danielebarchiesi@0
|
334 // subject though field enabled.
|
danielebarchiesi@0
|
335 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
336 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
337 $this->assertText($subject_text, 'Individual comment-reply subject found.');
|
danielebarchiesi@0
|
338 $this->assertText($comment_text, 'Individual comment-reply body found.');
|
danielebarchiesi@0
|
339 $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
|
danielebarchiesi@0
|
340 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
341 $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
|
danielebarchiesi@0
|
342 $this->assertEqual($comment->id, $reply_loaded->pid, 'Pid of a reply to a comment is set correctly.');
|
danielebarchiesi@0
|
343 $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.00/', $reply_loaded->thread, 'Thread of reply grows correctly.');
|
danielebarchiesi@0
|
344
|
danielebarchiesi@0
|
345 // Second reply to comment #3 creating comment #4.
|
danielebarchiesi@0
|
346 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
347 $this->assertText($subject_text, 'Individual comment-reply subject found.');
|
danielebarchiesi@0
|
348 $this->assertText($comment_text, 'Individual comment-reply body found.');
|
danielebarchiesi@0
|
349 $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
350 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
351 $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.');
|
danielebarchiesi@0
|
352 $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.01/', $reply_loaded->thread, 'Thread of second reply grows correctly.');
|
danielebarchiesi@0
|
353
|
danielebarchiesi@0
|
354 // Edit reply.
|
danielebarchiesi@0
|
355 $this->drupalGet('comment/' . $reply->id . '/edit');
|
danielebarchiesi@0
|
356 $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
357 $this->assertTrue($this->commentExists($reply, TRUE), 'Modified reply found.');
|
danielebarchiesi@0
|
358
|
danielebarchiesi@0
|
359 // Correct link count
|
danielebarchiesi@0
|
360 $this->drupalGet('node');
|
danielebarchiesi@0
|
361 $this->assertRaw('4 comments', 'Link to the 4 comments exist.');
|
danielebarchiesi@0
|
362
|
danielebarchiesi@0
|
363 // Confirm a new comment is posted to the correct page.
|
danielebarchiesi@0
|
364 $this->setCommentsPerPage(2);
|
danielebarchiesi@0
|
365 $comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
366 $this->assertTrue($this->commentExists($comment_new_page), 'Page one exists. %s');
|
danielebarchiesi@0
|
367 $this->drupalGet('node/' . $this->node->nid, array('query' => array('page' => 1)));
|
danielebarchiesi@0
|
368 $this->assertTrue($this->commentExists($reply, TRUE), 'Page two exists. %s');
|
danielebarchiesi@0
|
369 $this->setCommentsPerPage(50);
|
danielebarchiesi@0
|
370
|
danielebarchiesi@0
|
371 // Attempt to post to node with comments disabled.
|
danielebarchiesi@0
|
372 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_HIDDEN));
|
danielebarchiesi@0
|
373 $this->assertTrue($this->node, 'Article node created.');
|
danielebarchiesi@0
|
374 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
375 $this->assertText('This discussion is closed', 'Posting to node with comments disabled');
|
danielebarchiesi@0
|
376 $this->assertNoField('edit-comment', 'Comment body field found.');
|
danielebarchiesi@0
|
377
|
danielebarchiesi@0
|
378 // Attempt to post to node with read-only comments.
|
danielebarchiesi@0
|
379 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_CLOSED));
|
danielebarchiesi@0
|
380 $this->assertTrue($this->node, 'Article node created.');
|
danielebarchiesi@0
|
381 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
382 $this->assertText('This discussion is closed', 'Posting to node with comments read-only');
|
danielebarchiesi@0
|
383 $this->assertNoField('edit-comment', 'Comment body field found.');
|
danielebarchiesi@0
|
384
|
danielebarchiesi@0
|
385 // Attempt to post to node with comments enabled (check field names etc).
|
danielebarchiesi@0
|
386 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
|
danielebarchiesi@0
|
387 $this->assertTrue($this->node, 'Article node created.');
|
danielebarchiesi@0
|
388 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
389 $this->assertNoText('This discussion is closed', 'Posting to node with comments enabled');
|
danielebarchiesi@0
|
390 $this->assertField('edit-comment-body-' . $langcode . '-0-value', 'Comment body field found.');
|
danielebarchiesi@0
|
391
|
danielebarchiesi@0
|
392 // Delete comment and make sure that reply is also removed.
|
danielebarchiesi@0
|
393 $this->drupalLogout();
|
danielebarchiesi@0
|
394 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
395 $this->deleteComment($comment);
|
danielebarchiesi@0
|
396 $this->deleteComment($comment_new_page);
|
danielebarchiesi@0
|
397
|
danielebarchiesi@0
|
398 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
399 $this->assertFalse($this->commentExists($comment), 'Comment not found.');
|
danielebarchiesi@0
|
400 $this->assertFalse($this->commentExists($reply, TRUE), 'Reply not found.');
|
danielebarchiesi@0
|
401
|
danielebarchiesi@0
|
402 // Enabled comment form on node page.
|
danielebarchiesi@0
|
403 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
404 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
405 $this->drupalLogout();
|
danielebarchiesi@0
|
406
|
danielebarchiesi@0
|
407 // Submit comment through node form.
|
danielebarchiesi@0
|
408 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
409 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
410 $form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
411 $this->assertTrue($this->commentExists($form_comment), 'Form comment found.');
|
danielebarchiesi@0
|
412
|
danielebarchiesi@0
|
413 // Disable comment form on node page.
|
danielebarchiesi@0
|
414 $this->drupalLogout();
|
danielebarchiesi@0
|
415 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
416 $this->setCommentForm(FALSE);
|
danielebarchiesi@0
|
417 }
|
danielebarchiesi@0
|
418
|
danielebarchiesi@0
|
419 /**
|
danielebarchiesi@0
|
420 * Tests new comment marker.
|
danielebarchiesi@0
|
421 */
|
danielebarchiesi@0
|
422 public function testCommentNewCommentsIndicator() {
|
danielebarchiesi@0
|
423 // Test if the right links are displayed when no comment is present for the
|
danielebarchiesi@0
|
424 // node.
|
danielebarchiesi@0
|
425 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
426 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
|
danielebarchiesi@0
|
427 $this->drupalGet('node');
|
danielebarchiesi@0
|
428 $this->assertNoLink(t('@count comments', array('@count' => 0)));
|
danielebarchiesi@0
|
429 $this->assertNoLink(t('@count new comments', array('@count' => 0)));
|
danielebarchiesi@0
|
430 $this->assertLink(t('Read more'));
|
danielebarchiesi@0
|
431 $count = $this->xpath('//div[@id=:id]/div[@class=:class]/ul/li', array(':id' => 'node-' . $this->node->nid, ':class' => 'link-wrapper'));
|
danielebarchiesi@0
|
432 $this->assertTrue(count($count) == 1, 'One child found');
|
danielebarchiesi@0
|
433
|
danielebarchiesi@0
|
434 // Create a new comment. This helper function may be run with different
|
danielebarchiesi@0
|
435 // comment settings so use comment_save() to avoid complex setup.
|
danielebarchiesi@0
|
436 $comment = (object) array(
|
danielebarchiesi@0
|
437 'cid' => NULL,
|
danielebarchiesi@0
|
438 'nid' => $this->node->nid,
|
danielebarchiesi@0
|
439 'node_type' => $this->node->type,
|
danielebarchiesi@0
|
440 'pid' => 0,
|
danielebarchiesi@0
|
441 'uid' => $this->loggedInUser->uid,
|
danielebarchiesi@0
|
442 'status' => COMMENT_PUBLISHED,
|
danielebarchiesi@0
|
443 'subject' => $this->randomName(),
|
danielebarchiesi@0
|
444 'hostname' => ip_address(),
|
danielebarchiesi@0
|
445 'language' => LANGUAGE_NONE,
|
danielebarchiesi@0
|
446 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
|
danielebarchiesi@0
|
447 );
|
danielebarchiesi@0
|
448 comment_save($comment);
|
danielebarchiesi@0
|
449 $this->drupalLogout();
|
danielebarchiesi@0
|
450
|
danielebarchiesi@0
|
451 // Log in with 'web user' and check comment links.
|
danielebarchiesi@0
|
452 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
453 $this->drupalGet('node');
|
danielebarchiesi@0
|
454 $this->assertLink(t('1 new comment'));
|
danielebarchiesi@0
|
455 $this->clickLink(t('1 new comment'));
|
danielebarchiesi@0
|
456 $this->assertRaw('<a id="new"></a>', 'Found "new" marker.');
|
danielebarchiesi@0
|
457 $this->assertTrue($this->xpath('//a[@id=:new]/following-sibling::a[1][@id=:comment_id]', array(':new' => 'new', ':comment_id' => 'comment-1')), 'The "new" anchor is positioned at the right comment.');
|
danielebarchiesi@0
|
458
|
danielebarchiesi@0
|
459 // Test if "new comment" link is correctly removed.
|
danielebarchiesi@0
|
460 $this->drupalGet('node');
|
danielebarchiesi@0
|
461 $this->assertLink(t('1 comment'));
|
danielebarchiesi@0
|
462 $this->assertLink(t('Read more'));
|
danielebarchiesi@0
|
463 $this->assertNoLink(t('1 new comment'));
|
danielebarchiesi@0
|
464 $this->assertNoLink(t('@count new comments', array('@count' => 0)));
|
danielebarchiesi@0
|
465 $count = $this->xpath('//div[@id=:id]/div[@class=:class]/ul/li', array(':id' => 'node-' . $this->node->nid, ':class' => 'link-wrapper'));
|
danielebarchiesi@0
|
466 $this->assertTrue(count($count) == 2, print_r($count, TRUE));
|
danielebarchiesi@0
|
467 }
|
danielebarchiesi@0
|
468
|
danielebarchiesi@0
|
469 /**
|
danielebarchiesi@0
|
470 * Tests CSS classes on comments.
|
danielebarchiesi@0
|
471 */
|
danielebarchiesi@0
|
472 function testCommentClasses() {
|
danielebarchiesi@0
|
473 // Create all permutations for comments, users, and nodes.
|
danielebarchiesi@0
|
474 $parameters = array(
|
danielebarchiesi@0
|
475 'node_uid' => array(0, $this->web_user->uid),
|
danielebarchiesi@0
|
476 'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
|
danielebarchiesi@0
|
477 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
|
danielebarchiesi@0
|
478 'user' => array('anonymous', 'authenticated', 'admin'),
|
danielebarchiesi@0
|
479 );
|
danielebarchiesi@0
|
480 $permutations = $this->generatePermutations($parameters);
|
danielebarchiesi@0
|
481
|
danielebarchiesi@0
|
482 foreach ($permutations as $case) {
|
danielebarchiesi@0
|
483 // Create a new node.
|
danielebarchiesi@0
|
484 $node = $this->drupalCreateNode(array('type' => 'article', 'uid' => $case['node_uid']));
|
danielebarchiesi@0
|
485
|
danielebarchiesi@0
|
486 // Add a comment.
|
danielebarchiesi@0
|
487 $comment = (object) array(
|
danielebarchiesi@0
|
488 'cid' => NULL,
|
danielebarchiesi@0
|
489 'nid' => $node->nid,
|
danielebarchiesi@0
|
490 'pid' => 0,
|
danielebarchiesi@0
|
491 'uid' => $case['comment_uid'],
|
danielebarchiesi@0
|
492 'status' => $case['comment_status'],
|
danielebarchiesi@0
|
493 'subject' => $this->randomName(),
|
danielebarchiesi@0
|
494 'language' => LANGUAGE_NONE,
|
danielebarchiesi@0
|
495 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
|
danielebarchiesi@0
|
496 );
|
danielebarchiesi@0
|
497 comment_save($comment);
|
danielebarchiesi@0
|
498
|
danielebarchiesi@0
|
499 // Adjust the current/viewing user.
|
danielebarchiesi@0
|
500 switch ($case['user']) {
|
danielebarchiesi@0
|
501 case 'anonymous':
|
danielebarchiesi@0
|
502 $this->drupalLogout();
|
danielebarchiesi@0
|
503 $case['user_uid'] = 0;
|
danielebarchiesi@0
|
504 break;
|
danielebarchiesi@0
|
505
|
danielebarchiesi@0
|
506 case 'authenticated':
|
danielebarchiesi@0
|
507 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
508 $case['user_uid'] = $this->web_user->uid;
|
danielebarchiesi@0
|
509 break;
|
danielebarchiesi@0
|
510
|
danielebarchiesi@0
|
511 case 'admin':
|
danielebarchiesi@0
|
512 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
513 $case['user_uid'] = $this->admin_user->uid;
|
danielebarchiesi@0
|
514 break;
|
danielebarchiesi@0
|
515 }
|
danielebarchiesi@0
|
516 // Request the node with the comment.
|
danielebarchiesi@0
|
517 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
518
|
danielebarchiesi@0
|
519 // Verify classes if the comment is visible for the current user.
|
danielebarchiesi@0
|
520 if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
|
danielebarchiesi@0
|
521 // Verify the comment-by-anonymous class.
|
danielebarchiesi@0
|
522 $comments = $this->xpath('//*[contains(@class, "comment-by-anonymous")]');
|
danielebarchiesi@0
|
523 if ($case['comment_uid'] == 0) {
|
danielebarchiesi@0
|
524 $this->assertTrue(count($comments) == 1, 'comment-by-anonymous class found.');
|
danielebarchiesi@0
|
525 }
|
danielebarchiesi@0
|
526 else {
|
danielebarchiesi@0
|
527 $this->assertFalse(count($comments), 'comment-by-anonymous class not found.');
|
danielebarchiesi@0
|
528 }
|
danielebarchiesi@0
|
529
|
danielebarchiesi@0
|
530 // Verify the comment-by-node-author class.
|
danielebarchiesi@0
|
531 $comments = $this->xpath('//*[contains(@class, "comment-by-node-author")]');
|
danielebarchiesi@0
|
532 if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
|
danielebarchiesi@0
|
533 $this->assertTrue(count($comments) == 1, 'comment-by-node-author class found.');
|
danielebarchiesi@0
|
534 }
|
danielebarchiesi@0
|
535 else {
|
danielebarchiesi@0
|
536 $this->assertFalse(count($comments), 'comment-by-node-author class not found.');
|
danielebarchiesi@0
|
537 }
|
danielebarchiesi@0
|
538
|
danielebarchiesi@0
|
539 // Verify the comment-by-viewer class.
|
danielebarchiesi@0
|
540 $comments = $this->xpath('//*[contains(@class, "comment-by-viewer")]');
|
danielebarchiesi@0
|
541 if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user_uid']) {
|
danielebarchiesi@0
|
542 $this->assertTrue(count($comments) == 1, 'comment-by-viewer class found.');
|
danielebarchiesi@0
|
543 }
|
danielebarchiesi@0
|
544 else {
|
danielebarchiesi@0
|
545 $this->assertFalse(count($comments), 'comment-by-viewer class not found.');
|
danielebarchiesi@0
|
546 }
|
danielebarchiesi@0
|
547 }
|
danielebarchiesi@0
|
548
|
danielebarchiesi@0
|
549 // Verify the comment-unpublished class.
|
danielebarchiesi@0
|
550 $comments = $this->xpath('//*[contains(@class, "comment-unpublished")]');
|
danielebarchiesi@0
|
551 if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') {
|
danielebarchiesi@0
|
552 $this->assertTrue(count($comments) == 1, 'comment-unpublished class found.');
|
danielebarchiesi@0
|
553 }
|
danielebarchiesi@0
|
554 else {
|
danielebarchiesi@0
|
555 $this->assertFalse(count($comments), 'comment-unpublished class not found.');
|
danielebarchiesi@0
|
556 }
|
danielebarchiesi@0
|
557
|
danielebarchiesi@0
|
558 // Verify the comment-new class.
|
danielebarchiesi@0
|
559 if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
|
danielebarchiesi@0
|
560 $comments = $this->xpath('//*[contains(@class, "comment-new")]');
|
danielebarchiesi@0
|
561 if ($case['user'] != 'anonymous') {
|
danielebarchiesi@0
|
562 $this->assertTrue(count($comments) == 1, 'comment-new class found.');
|
danielebarchiesi@0
|
563
|
danielebarchiesi@0
|
564 // Request the node again. The comment-new class should disappear.
|
danielebarchiesi@0
|
565 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
566 $comments = $this->xpath('//*[contains(@class, "comment-new")]');
|
danielebarchiesi@0
|
567 $this->assertFalse(count($comments), 'comment-new class not found.');
|
danielebarchiesi@0
|
568 }
|
danielebarchiesi@0
|
569 else {
|
danielebarchiesi@0
|
570 $this->assertFalse(count($comments), 'comment-new class not found.');
|
danielebarchiesi@0
|
571 }
|
danielebarchiesi@0
|
572 }
|
danielebarchiesi@0
|
573 }
|
danielebarchiesi@0
|
574 }
|
danielebarchiesi@0
|
575
|
danielebarchiesi@0
|
576 /**
|
danielebarchiesi@0
|
577 * Tests the node comment statistics.
|
danielebarchiesi@0
|
578 */
|
danielebarchiesi@0
|
579 function testCommentNodeCommentStatistics() {
|
danielebarchiesi@0
|
580 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
581 // Set comments to have subject and preview disabled.
|
danielebarchiesi@0
|
582 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
583 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
584 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
585 $this->setCommentSubject(FALSE);
|
danielebarchiesi@0
|
586 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
587 $this->drupalLogout();
|
danielebarchiesi@0
|
588
|
danielebarchiesi@0
|
589 // Creates a second user to post comments.
|
danielebarchiesi@0
|
590 $this->web_user2 = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
|
danielebarchiesi@0
|
591
|
danielebarchiesi@0
|
592 // Checks the initial values of node comment statistics with no comment.
|
danielebarchiesi@0
|
593 $node = node_load($this->node->nid);
|
danielebarchiesi@0
|
594 $this->assertEqual($node->last_comment_timestamp, $this->node->created, 'The initial value of node last_comment_timestamp is the node created date.');
|
danielebarchiesi@0
|
595 $this->assertEqual($node->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
|
danielebarchiesi@0
|
596 $this->assertEqual($node->last_comment_uid, $this->web_user->uid, 'The initial value of node last_comment_uid is the node uid.');
|
danielebarchiesi@0
|
597 $this->assertEqual($node->comment_count, 0, 'The initial value of node comment_count is zero.');
|
danielebarchiesi@0
|
598
|
danielebarchiesi@0
|
599 // Post comment #1 as web_user2.
|
danielebarchiesi@0
|
600 $this->drupalLogin($this->web_user2);
|
danielebarchiesi@0
|
601 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
602 $comment = $this->postComment($this->node, $comment_text);
|
danielebarchiesi@0
|
603 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
604
|
danielebarchiesi@0
|
605 // Checks the new values of node comment statistics with comment #1.
|
danielebarchiesi@0
|
606 // The node needs to be reloaded with a node_load_multiple cache reset.
|
danielebarchiesi@0
|
607 $node = node_load($this->node->nid, NULL, TRUE);
|
danielebarchiesi@0
|
608 $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is NULL.');
|
danielebarchiesi@0
|
609 $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is the comment #1 uid.');
|
danielebarchiesi@0
|
610 $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is 1.');
|
danielebarchiesi@0
|
611
|
danielebarchiesi@0
|
612 // Prepare for anonymous comment submission (comment approval enabled).
|
danielebarchiesi@0
|
613 variable_set('user_register', USER_REGISTER_VISITORS);
|
danielebarchiesi@0
|
614 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
615 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
616 'access comments' => TRUE,
|
danielebarchiesi@0
|
617 'post comments' => TRUE,
|
danielebarchiesi@0
|
618 'skip comment approval' => FALSE,
|
danielebarchiesi@0
|
619 ));
|
danielebarchiesi@0
|
620 // Ensure that the poster can leave some contact info.
|
danielebarchiesi@0
|
621 $this->setCommentAnonymous('1');
|
danielebarchiesi@0
|
622 $this->drupalLogout();
|
danielebarchiesi@0
|
623
|
danielebarchiesi@0
|
624 // Post comment #2 as anonymous (comment approval enabled).
|
danielebarchiesi@0
|
625 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
626 $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', TRUE);
|
danielebarchiesi@0
|
627 $comment_unpublished_loaded = comment_load($anonymous_comment->id);
|
danielebarchiesi@0
|
628
|
danielebarchiesi@0
|
629 // Checks the new values of node comment statistics with comment #2 and
|
danielebarchiesi@0
|
630 // ensure they haven't changed since the comment has not been moderated.
|
danielebarchiesi@0
|
631 // The node needs to be reloaded with a node_load_multiple cache reset.
|
danielebarchiesi@0
|
632 $node = node_load($this->node->nid, NULL, TRUE);
|
danielebarchiesi@0
|
633 $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.');
|
danielebarchiesi@0
|
634 $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is still the comment #1 uid.');
|
danielebarchiesi@0
|
635 $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is still 1.');
|
danielebarchiesi@0
|
636
|
danielebarchiesi@0
|
637 // Prepare for anonymous comment submission (no approval required).
|
danielebarchiesi@0
|
638 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
639 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
640 'access comments' => TRUE,
|
danielebarchiesi@0
|
641 'post comments' => TRUE,
|
danielebarchiesi@0
|
642 'skip comment approval' => TRUE,
|
danielebarchiesi@0
|
643 ));
|
danielebarchiesi@0
|
644 $this->drupalLogout();
|
danielebarchiesi@0
|
645
|
danielebarchiesi@0
|
646 // Post comment #3 as anonymous.
|
danielebarchiesi@0
|
647 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
648 $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', array('name' => $this->randomName()));
|
danielebarchiesi@0
|
649 $comment_loaded = comment_load($anonymous_comment->id);
|
danielebarchiesi@0
|
650
|
danielebarchiesi@0
|
651 // Checks the new values of node comment statistics with comment #3.
|
danielebarchiesi@0
|
652 // The node needs to be reloaded with a node_load_multiple cache reset.
|
danielebarchiesi@0
|
653 $node = node_load($this->node->nid, NULL, TRUE);
|
danielebarchiesi@0
|
654 $this->assertEqual($node->last_comment_name, $comment_loaded->name, 'The value of node last_comment_name is the name of the anonymous user.');
|
danielebarchiesi@0
|
655 $this->assertEqual($node->last_comment_uid, 0, 'The value of node last_comment_uid is zero.');
|
danielebarchiesi@0
|
656 $this->assertEqual($node->comment_count, 2, 'The value of node comment_count is 2.');
|
danielebarchiesi@0
|
657 }
|
danielebarchiesi@0
|
658
|
danielebarchiesi@0
|
659 /**
|
danielebarchiesi@0
|
660 * Tests comment links.
|
danielebarchiesi@0
|
661 *
|
danielebarchiesi@0
|
662 * The output of comment links depends on various environment conditions:
|
danielebarchiesi@0
|
663 * - Various Comment module configuration settings, user registration
|
danielebarchiesi@0
|
664 * settings, and user access permissions.
|
danielebarchiesi@0
|
665 * - Whether the user is authenticated or not, and whether any comments exist.
|
danielebarchiesi@0
|
666 *
|
danielebarchiesi@0
|
667 * To account for all possible cases, this test creates permutations of all
|
danielebarchiesi@0
|
668 * possible conditions and tests the expected appearance of comment links in
|
danielebarchiesi@0
|
669 * each environment.
|
danielebarchiesi@0
|
670 */
|
danielebarchiesi@0
|
671 function testCommentLinks() {
|
danielebarchiesi@0
|
672 // Bartik theme alters comment links, so use a different theme.
|
danielebarchiesi@0
|
673 theme_enable(array('garland'));
|
danielebarchiesi@0
|
674 variable_set('theme_default', 'garland');
|
danielebarchiesi@0
|
675
|
danielebarchiesi@0
|
676 // Remove additional user permissions from $this->web_user added by setUp(),
|
danielebarchiesi@0
|
677 // since this test is limited to anonymous and authenticated roles only.
|
danielebarchiesi@0
|
678 user_role_delete(key($this->web_user->roles));
|
danielebarchiesi@0
|
679
|
danielebarchiesi@0
|
680 // Matrix of possible environmental conditions and configuration settings.
|
danielebarchiesi@0
|
681 // See setEnvironment() for details.
|
danielebarchiesi@0
|
682 $conditions = array(
|
danielebarchiesi@0
|
683 'authenticated' => array(FALSE, TRUE),
|
danielebarchiesi@0
|
684 'comment count' => array(FALSE, TRUE),
|
danielebarchiesi@0
|
685 'access comments' => array(0, 1),
|
danielebarchiesi@0
|
686 'post comments' => array(0, 1),
|
danielebarchiesi@0
|
687 'form' => array(COMMENT_FORM_BELOW, COMMENT_FORM_SEPARATE_PAGE),
|
danielebarchiesi@0
|
688 // USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL is irrelevant for this
|
danielebarchiesi@0
|
689 // test; there is only a difference between open and closed registration.
|
danielebarchiesi@0
|
690 'user_register' => array(USER_REGISTER_VISITORS, USER_REGISTER_ADMINISTRATORS_ONLY),
|
danielebarchiesi@0
|
691 // @todo Complete test coverage for:
|
danielebarchiesi@0
|
692 //'comments' => array(COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, COMMENT_NODE_HIDDEN),
|
danielebarchiesi@0
|
693 //// COMMENT_ANONYMOUS_MUST_CONTACT is irrelevant for this test.
|
danielebarchiesi@0
|
694 //'contact ' => array(COMMENT_ANONYMOUS_MAY_CONTACT, COMMENT_ANONYMOUS_MAYNOT_CONTACT),
|
danielebarchiesi@0
|
695 );
|
danielebarchiesi@0
|
696
|
danielebarchiesi@0
|
697 $environments = $this->generatePermutations($conditions);
|
danielebarchiesi@0
|
698 foreach ($environments as $info) {
|
danielebarchiesi@0
|
699 $this->assertCommentLinks($info);
|
danielebarchiesi@0
|
700 }
|
danielebarchiesi@0
|
701 }
|
danielebarchiesi@0
|
702
|
danielebarchiesi@0
|
703 /**
|
danielebarchiesi@0
|
704 * Re-configures the environment, module settings, and user permissions.
|
danielebarchiesi@0
|
705 *
|
danielebarchiesi@0
|
706 * @param $info
|
danielebarchiesi@0
|
707 * An associative array describing the environment to setup:
|
danielebarchiesi@0
|
708 * - Environment conditions:
|
danielebarchiesi@0
|
709 * - authenticated: Boolean whether to test with $this->web_user or
|
danielebarchiesi@0
|
710 * anonymous.
|
danielebarchiesi@0
|
711 * - comment count: Boolean whether to test with a new/unread comment on
|
danielebarchiesi@0
|
712 * $this->node or no comments.
|
danielebarchiesi@0
|
713 * - Configuration settings:
|
danielebarchiesi@0
|
714 * - form: COMMENT_FORM_BELOW or COMMENT_FORM_SEPARATE_PAGE.
|
danielebarchiesi@0
|
715 * - user_register: USER_REGISTER_ADMINISTRATORS_ONLY or
|
danielebarchiesi@0
|
716 * USER_REGISTER_VISITORS.
|
danielebarchiesi@0
|
717 * - contact: COMMENT_ANONYMOUS_MAY_CONTACT or
|
danielebarchiesi@0
|
718 * COMMENT_ANONYMOUS_MAYNOT_CONTACT.
|
danielebarchiesi@0
|
719 * - comments: COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, or
|
danielebarchiesi@0
|
720 * COMMENT_NODE_HIDDEN.
|
danielebarchiesi@0
|
721 * - User permissions:
|
danielebarchiesi@0
|
722 * These are granted or revoked for the user, according to the
|
danielebarchiesi@0
|
723 * 'authenticated' flag above. Pass 0 or 1 as parameter values. See
|
danielebarchiesi@0
|
724 * user_role_change_permissions().
|
danielebarchiesi@0
|
725 * - access comments
|
danielebarchiesi@0
|
726 * - post comments
|
danielebarchiesi@0
|
727 * - skip comment approval
|
danielebarchiesi@0
|
728 * - edit own comments
|
danielebarchiesi@0
|
729 */
|
danielebarchiesi@0
|
730 function setEnvironment(array $info) {
|
danielebarchiesi@0
|
731 static $current;
|
danielebarchiesi@0
|
732
|
danielebarchiesi@0
|
733 // Apply defaults to initial environment.
|
danielebarchiesi@0
|
734 if (!isset($current)) {
|
danielebarchiesi@0
|
735 $current = array(
|
danielebarchiesi@0
|
736 'authenticated' => FALSE,
|
danielebarchiesi@0
|
737 'comment count' => FALSE,
|
danielebarchiesi@0
|
738 'form' => COMMENT_FORM_BELOW,
|
danielebarchiesi@0
|
739 'user_register' => USER_REGISTER_VISITORS,
|
danielebarchiesi@0
|
740 'contact' => COMMENT_ANONYMOUS_MAY_CONTACT,
|
danielebarchiesi@0
|
741 'comments' => COMMENT_NODE_OPEN,
|
danielebarchiesi@0
|
742 'access comments' => 0,
|
danielebarchiesi@0
|
743 'post comments' => 0,
|
danielebarchiesi@0
|
744 // Enabled by default, because it's irrelevant for this test.
|
danielebarchiesi@0
|
745 'skip comment approval' => 1,
|
danielebarchiesi@0
|
746 'edit own comments' => 0,
|
danielebarchiesi@0
|
747 );
|
danielebarchiesi@0
|
748 }
|
danielebarchiesi@0
|
749 // Complete new environment with current environment.
|
danielebarchiesi@0
|
750 $info = array_merge($current, $info);
|
danielebarchiesi@0
|
751
|
danielebarchiesi@0
|
752 // Change environment conditions.
|
danielebarchiesi@0
|
753 if ($current['authenticated'] != $info['authenticated']) {
|
danielebarchiesi@0
|
754 if ($this->loggedInUser) {
|
danielebarchiesi@0
|
755 $this->drupalLogout();
|
danielebarchiesi@0
|
756 }
|
danielebarchiesi@0
|
757 else {
|
danielebarchiesi@0
|
758 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
759 }
|
danielebarchiesi@0
|
760 }
|
danielebarchiesi@0
|
761 if ($current['comment count'] != $info['comment count']) {
|
danielebarchiesi@0
|
762 if ($info['comment count']) {
|
danielebarchiesi@0
|
763 // Create a comment via CRUD API functionality, since
|
danielebarchiesi@0
|
764 // $this->postComment() relies on actual user permissions.
|
danielebarchiesi@0
|
765 $comment = (object) array(
|
danielebarchiesi@0
|
766 'cid' => NULL,
|
danielebarchiesi@0
|
767 'nid' => $this->node->nid,
|
danielebarchiesi@0
|
768 'node_type' => $this->node->type,
|
danielebarchiesi@0
|
769 'pid' => 0,
|
danielebarchiesi@0
|
770 'uid' => 0,
|
danielebarchiesi@0
|
771 'status' => COMMENT_PUBLISHED,
|
danielebarchiesi@0
|
772 'subject' => $this->randomName(),
|
danielebarchiesi@0
|
773 'hostname' => ip_address(),
|
danielebarchiesi@0
|
774 'language' => LANGUAGE_NONE,
|
danielebarchiesi@0
|
775 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
|
danielebarchiesi@0
|
776 );
|
danielebarchiesi@0
|
777 comment_save($comment);
|
danielebarchiesi@0
|
778 $this->comment = $comment;
|
danielebarchiesi@0
|
779
|
danielebarchiesi@0
|
780 // comment_num_new() relies on node_last_viewed(), so ensure that no one
|
danielebarchiesi@0
|
781 // has seen the node of this comment.
|
danielebarchiesi@0
|
782 db_delete('history')->condition('nid', $this->node->nid)->execute();
|
danielebarchiesi@0
|
783 }
|
danielebarchiesi@0
|
784 else {
|
danielebarchiesi@0
|
785 $cids = db_query("SELECT cid FROM {comment}")->fetchCol();
|
danielebarchiesi@0
|
786 comment_delete_multiple($cids);
|
danielebarchiesi@0
|
787 unset($this->comment);
|
danielebarchiesi@0
|
788 }
|
danielebarchiesi@0
|
789 }
|
danielebarchiesi@0
|
790
|
danielebarchiesi@0
|
791 // Change comment settings.
|
danielebarchiesi@0
|
792 variable_set('comment_form_location_' . $this->node->type, $info['form']);
|
danielebarchiesi@0
|
793 variable_set('comment_anonymous_' . $this->node->type, $info['contact']);
|
danielebarchiesi@0
|
794 if ($this->node->comment != $info['comments']) {
|
danielebarchiesi@0
|
795 $this->node->comment = $info['comments'];
|
danielebarchiesi@0
|
796 node_save($this->node);
|
danielebarchiesi@0
|
797 }
|
danielebarchiesi@0
|
798
|
danielebarchiesi@0
|
799 // Change user settings.
|
danielebarchiesi@0
|
800 variable_set('user_register', $info['user_register']);
|
danielebarchiesi@0
|
801
|
danielebarchiesi@0
|
802 // Change user permissions.
|
danielebarchiesi@0
|
803 $rid = ($this->loggedInUser ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID);
|
danielebarchiesi@0
|
804 $perms = array_intersect_key($info, array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1));
|
danielebarchiesi@0
|
805 user_role_change_permissions($rid, $perms);
|
danielebarchiesi@0
|
806
|
danielebarchiesi@0
|
807 // Output verbose debugging information.
|
danielebarchiesi@0
|
808 // @see DrupalTestCase::error()
|
danielebarchiesi@0
|
809 $t_form = array(
|
danielebarchiesi@0
|
810 COMMENT_FORM_BELOW => 'below',
|
danielebarchiesi@0
|
811 COMMENT_FORM_SEPARATE_PAGE => 'separate page',
|
danielebarchiesi@0
|
812 );
|
danielebarchiesi@0
|
813 $t_contact = array(
|
danielebarchiesi@0
|
814 COMMENT_ANONYMOUS_MAY_CONTACT => 'optional',
|
danielebarchiesi@0
|
815 COMMENT_ANONYMOUS_MAYNOT_CONTACT => 'disabled',
|
danielebarchiesi@0
|
816 COMMENT_ANONYMOUS_MUST_CONTACT => 'required',
|
danielebarchiesi@0
|
817 );
|
danielebarchiesi@0
|
818 $t_comments = array(
|
danielebarchiesi@0
|
819 COMMENT_NODE_OPEN => 'open',
|
danielebarchiesi@0
|
820 COMMENT_NODE_CLOSED => 'closed',
|
danielebarchiesi@0
|
821 COMMENT_NODE_HIDDEN => 'hidden',
|
danielebarchiesi@0
|
822 );
|
danielebarchiesi@0
|
823 $verbose = $info;
|
danielebarchiesi@0
|
824 $verbose['form'] = $t_form[$info['form']];
|
danielebarchiesi@0
|
825 $verbose['contact'] = $t_contact[$info['contact']];
|
danielebarchiesi@0
|
826 $verbose['comments'] = $t_comments[$info['comments']];
|
danielebarchiesi@0
|
827 $message = t('Changed environment:<pre>@verbose</pre>', array(
|
danielebarchiesi@0
|
828 '@verbose' => var_export($verbose, TRUE),
|
danielebarchiesi@0
|
829 ));
|
danielebarchiesi@0
|
830 $this->assert('debug', $message, 'Debug');
|
danielebarchiesi@0
|
831
|
danielebarchiesi@0
|
832 // Update current environment.
|
danielebarchiesi@0
|
833 $current = $info;
|
danielebarchiesi@0
|
834
|
danielebarchiesi@0
|
835 return $info;
|
danielebarchiesi@0
|
836 }
|
danielebarchiesi@0
|
837
|
danielebarchiesi@0
|
838 /**
|
danielebarchiesi@0
|
839 * Asserts that comment links appear according to the passed environment setup.
|
danielebarchiesi@0
|
840 *
|
danielebarchiesi@0
|
841 * @param $info
|
danielebarchiesi@0
|
842 * An associative array describing the environment to pass to
|
danielebarchiesi@0
|
843 * setEnvironment().
|
danielebarchiesi@0
|
844 */
|
danielebarchiesi@0
|
845 function assertCommentLinks(array $info) {
|
danielebarchiesi@0
|
846 $info = $this->setEnvironment($info);
|
danielebarchiesi@0
|
847
|
danielebarchiesi@0
|
848 $nid = $this->node->nid;
|
danielebarchiesi@0
|
849
|
danielebarchiesi@0
|
850 foreach (array('', "node/$nid") as $path) {
|
danielebarchiesi@0
|
851 $this->drupalGet($path);
|
danielebarchiesi@0
|
852
|
danielebarchiesi@0
|
853 // User is allowed to view comments.
|
danielebarchiesi@0
|
854 if ($info['access comments']) {
|
danielebarchiesi@0
|
855 if ($path == '') {
|
danielebarchiesi@0
|
856 // In teaser view, a link containing the comment count is always
|
danielebarchiesi@0
|
857 // expected.
|
danielebarchiesi@0
|
858 if ($info['comment count']) {
|
danielebarchiesi@0
|
859 $this->assertLink(t('1 comment'));
|
danielebarchiesi@0
|
860
|
danielebarchiesi@0
|
861 // For logged in users, a link containing the amount of new/unread
|
danielebarchiesi@0
|
862 // comments is expected.
|
danielebarchiesi@0
|
863 // See important note about comment_num_new() below.
|
danielebarchiesi@0
|
864 if ($this->loggedInUser && isset($this->comment) && !isset($this->comment->seen)) {
|
danielebarchiesi@0
|
865 $this->assertLink(t('1 new comment'));
|
danielebarchiesi@0
|
866 $this->comment->seen = TRUE;
|
danielebarchiesi@0
|
867 }
|
danielebarchiesi@0
|
868 }
|
danielebarchiesi@0
|
869 }
|
danielebarchiesi@0
|
870 }
|
danielebarchiesi@0
|
871 else {
|
danielebarchiesi@0
|
872 $this->assertNoLink(t('1 comment'));
|
danielebarchiesi@0
|
873 $this->assertNoLink(t('1 new comment'));
|
danielebarchiesi@0
|
874 }
|
danielebarchiesi@0
|
875 // comment_num_new() is based on node views, so comments are marked as
|
danielebarchiesi@0
|
876 // read when a node is viewed, regardless of whether we have access to
|
danielebarchiesi@0
|
877 // comments.
|
danielebarchiesi@0
|
878 if ($path == "node/$nid" && $this->loggedInUser && isset($this->comment)) {
|
danielebarchiesi@0
|
879 $this->comment->seen = TRUE;
|
danielebarchiesi@0
|
880 }
|
danielebarchiesi@0
|
881
|
danielebarchiesi@0
|
882 // User is not allowed to post comments.
|
danielebarchiesi@0
|
883 if (!$info['post comments']) {
|
danielebarchiesi@0
|
884 $this->assertNoLink('Add new comment');
|
danielebarchiesi@0
|
885
|
danielebarchiesi@0
|
886 // Anonymous users should see a note to log in or register in case
|
danielebarchiesi@0
|
887 // authenticated users are allowed to post comments.
|
danielebarchiesi@0
|
888 // @see theme_comment_post_forbidden()
|
danielebarchiesi@0
|
889 if (!$this->loggedInUser) {
|
danielebarchiesi@0
|
890 if (user_access('post comments', $this->web_user)) {
|
danielebarchiesi@0
|
891 // The note depends on whether users are actually able to register.
|
danielebarchiesi@0
|
892 if ($info['user_register']) {
|
danielebarchiesi@0
|
893 $this->assertText('Log in or register to post comments');
|
danielebarchiesi@0
|
894 }
|
danielebarchiesi@0
|
895 else {
|
danielebarchiesi@0
|
896 $this->assertText('Log in to post comments');
|
danielebarchiesi@0
|
897 }
|
danielebarchiesi@0
|
898 }
|
danielebarchiesi@0
|
899 else {
|
danielebarchiesi@0
|
900 $this->assertNoText('Log in or register to post comments');
|
danielebarchiesi@0
|
901 $this->assertNoText('Log in to post comments');
|
danielebarchiesi@0
|
902 }
|
danielebarchiesi@0
|
903 }
|
danielebarchiesi@0
|
904 }
|
danielebarchiesi@0
|
905 // User is allowed to post comments.
|
danielebarchiesi@0
|
906 else {
|
danielebarchiesi@0
|
907 $this->assertNoText('Log in or register to post comments');
|
danielebarchiesi@0
|
908
|
danielebarchiesi@0
|
909 // "Add new comment" is always expected, except when there are no
|
danielebarchiesi@0
|
910 // comments or if the user cannot see them.
|
danielebarchiesi@0
|
911 if ($path == "node/$nid" && $info['form'] == COMMENT_FORM_BELOW && (!$info['comment count'] || !$info['access comments'])) {
|
danielebarchiesi@0
|
912 $this->assertNoLink('Add new comment');
|
danielebarchiesi@0
|
913 }
|
danielebarchiesi@0
|
914 else {
|
danielebarchiesi@0
|
915 $this->assertLink('Add new comment');
|
danielebarchiesi@0
|
916 }
|
danielebarchiesi@0
|
917
|
danielebarchiesi@0
|
918 // Also verify that the comment form appears according to the configured
|
danielebarchiesi@0
|
919 // location.
|
danielebarchiesi@0
|
920 if ($path == "node/$nid") {
|
danielebarchiesi@0
|
921 $elements = $this->xpath('//form[@id=:id]', array(':id' => 'comment-form'));
|
danielebarchiesi@0
|
922 if ($info['form'] == COMMENT_FORM_BELOW) {
|
danielebarchiesi@0
|
923 $this->assertTrue(count($elements), 'Comment form found below.');
|
danielebarchiesi@0
|
924 }
|
danielebarchiesi@0
|
925 else {
|
danielebarchiesi@0
|
926 $this->assertFalse(count($elements), 'Comment form not found below.');
|
danielebarchiesi@0
|
927 }
|
danielebarchiesi@0
|
928 }
|
danielebarchiesi@0
|
929 }
|
danielebarchiesi@0
|
930 }
|
danielebarchiesi@0
|
931 }
|
danielebarchiesi@0
|
932 }
|
danielebarchiesi@0
|
933
|
danielebarchiesi@0
|
934 /**
|
danielebarchiesi@0
|
935 * Test previewing comments.
|
danielebarchiesi@0
|
936 */
|
danielebarchiesi@0
|
937 class CommentPreviewTest extends CommentHelperCase {
|
danielebarchiesi@0
|
938 public static function getInfo() {
|
danielebarchiesi@0
|
939 return array(
|
danielebarchiesi@0
|
940 'name' => 'Comment preview',
|
danielebarchiesi@0
|
941 'description' => 'Test comment preview.',
|
danielebarchiesi@0
|
942 'group' => 'Comment',
|
danielebarchiesi@0
|
943 );
|
danielebarchiesi@0
|
944 }
|
danielebarchiesi@0
|
945
|
danielebarchiesi@0
|
946 /**
|
danielebarchiesi@0
|
947 * Test comment preview.
|
danielebarchiesi@0
|
948 */
|
danielebarchiesi@0
|
949 function testCommentPreview() {
|
danielebarchiesi@0
|
950 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
951
|
danielebarchiesi@0
|
952 // As admin user, configure comment settings.
|
danielebarchiesi@0
|
953 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
954 $this->setCommentPreview(DRUPAL_OPTIONAL);
|
danielebarchiesi@0
|
955 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
956 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
957 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
958 $this->drupalLogout();
|
danielebarchiesi@0
|
959
|
danielebarchiesi@0
|
960 // Login as web user and add a signature and a user picture.
|
danielebarchiesi@0
|
961 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
962 variable_set('user_signatures', 1);
|
danielebarchiesi@0
|
963 variable_set('user_pictures', 1);
|
danielebarchiesi@0
|
964 $test_signature = $this->randomName();
|
danielebarchiesi@0
|
965 $edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>';
|
danielebarchiesi@0
|
966 $edit['signature[format]'] = 'filtered_html';
|
danielebarchiesi@0
|
967 $image = current($this->drupalGetTestFiles('image'));
|
danielebarchiesi@0
|
968 $edit['files[picture_upload]'] = drupal_realpath($image->uri);
|
danielebarchiesi@0
|
969 $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
|
danielebarchiesi@0
|
970
|
danielebarchiesi@0
|
971 // As the web user, fill in the comment form and preview the comment.
|
danielebarchiesi@0
|
972 $edit = array();
|
danielebarchiesi@0
|
973 $edit['subject'] = $this->randomName(8);
|
danielebarchiesi@0
|
974 $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
|
danielebarchiesi@0
|
975 $this->drupalPost('node/' . $this->node->nid, $edit, t('Preview'));
|
danielebarchiesi@0
|
976
|
danielebarchiesi@0
|
977 // Check that the preview is displaying the title and body.
|
danielebarchiesi@0
|
978 $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
|
danielebarchiesi@0
|
979 $this->assertText($edit['subject'], 'Subject displayed.');
|
danielebarchiesi@0
|
980 $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');
|
danielebarchiesi@0
|
981
|
danielebarchiesi@0
|
982 // Check that the title and body fields are displayed with the correct values.
|
danielebarchiesi@0
|
983 $this->assertFieldByName('subject', $edit['subject'], 'Subject field displayed.');
|
danielebarchiesi@0
|
984 $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
|
danielebarchiesi@0
|
985
|
danielebarchiesi@0
|
986 // Check that the signature is displaying with the correct text format.
|
danielebarchiesi@0
|
987 $this->assertLink($test_signature);
|
danielebarchiesi@0
|
988
|
danielebarchiesi@0
|
989 // Check that the user picture is displayed.
|
danielebarchiesi@0
|
990 $this->assertFieldByXPath("//div[contains(@class, 'comment-preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
|
danielebarchiesi@0
|
991 }
|
danielebarchiesi@0
|
992
|
danielebarchiesi@0
|
993 /**
|
danielebarchiesi@0
|
994 * Test comment edit, preview, and save.
|
danielebarchiesi@0
|
995 */
|
danielebarchiesi@0
|
996 function testCommentEditPreviewSave() {
|
danielebarchiesi@0
|
997 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
998 $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval'));
|
danielebarchiesi@0
|
999 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1000 $this->setCommentPreview(DRUPAL_OPTIONAL);
|
danielebarchiesi@0
|
1001 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
1002 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1003 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
1004
|
danielebarchiesi@0
|
1005 $edit = array();
|
danielebarchiesi@0
|
1006 $edit['subject'] = $this->randomName(8);
|
danielebarchiesi@0
|
1007 $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
|
danielebarchiesi@0
|
1008 $edit['name'] = $web_user->name;
|
danielebarchiesi@0
|
1009 $edit['date'] = '2008-03-02 17:23 +0300';
|
danielebarchiesi@0
|
1010 $raw_date = strtotime($edit['date']);
|
danielebarchiesi@0
|
1011 $expected_text_date = format_date($raw_date);
|
danielebarchiesi@0
|
1012 $expected_form_date = format_date($raw_date, 'custom', 'Y-m-d H:i O');
|
danielebarchiesi@0
|
1013 $comment = $this->postComment($this->node, $edit['subject'], $edit['comment_body[' . $langcode . '][0][value]'], TRUE);
|
danielebarchiesi@0
|
1014 $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Preview'));
|
danielebarchiesi@0
|
1015
|
danielebarchiesi@0
|
1016 // Check that the preview is displaying the subject, comment, author and date correctly.
|
danielebarchiesi@0
|
1017 $this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
|
danielebarchiesi@0
|
1018 $this->assertText($edit['subject'], 'Subject displayed.');
|
danielebarchiesi@0
|
1019 $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');
|
danielebarchiesi@0
|
1020 $this->assertText($edit['name'], 'Author displayed.');
|
danielebarchiesi@0
|
1021 $this->assertText($expected_text_date, 'Date displayed.');
|
danielebarchiesi@0
|
1022
|
danielebarchiesi@0
|
1023 // Check that the subject, comment, author and date fields are displayed with the correct values.
|
danielebarchiesi@0
|
1024 $this->assertFieldByName('subject', $edit['subject'], 'Subject field displayed.');
|
danielebarchiesi@0
|
1025 $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
|
danielebarchiesi@0
|
1026 $this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
|
danielebarchiesi@0
|
1027 $this->assertFieldByName('date', $edit['date'], 'Date field displayed.');
|
danielebarchiesi@0
|
1028
|
danielebarchiesi@0
|
1029 // Check that saving a comment produces a success message.
|
danielebarchiesi@0
|
1030 $this->drupalPost('comment/' . $comment->id . '/edit', $edit, t('Save'));
|
danielebarchiesi@0
|
1031 $this->assertText(t('Your comment has been posted.'), 'Comment posted.');
|
danielebarchiesi@0
|
1032
|
danielebarchiesi@0
|
1033 // Check that the comment fields are correct after loading the saved comment.
|
danielebarchiesi@0
|
1034 $this->drupalGet('comment/' . $comment->id . '/edit');
|
danielebarchiesi@0
|
1035 $this->assertFieldByName('subject', $edit['subject'], 'Subject field displayed.');
|
danielebarchiesi@0
|
1036 $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
|
danielebarchiesi@0
|
1037 $this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
|
danielebarchiesi@0
|
1038 $this->assertFieldByName('date', $expected_form_date, 'Date field displayed.');
|
danielebarchiesi@0
|
1039
|
danielebarchiesi@0
|
1040 // Submit the form using the displayed values.
|
danielebarchiesi@0
|
1041 $displayed = array();
|
danielebarchiesi@0
|
1042 $displayed['subject'] = (string) current($this->xpath("//input[@id='edit-subject']/@value"));
|
danielebarchiesi@0
|
1043 $displayed['comment_body[' . $langcode . '][0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-" . $langcode . "-0-value']"));
|
danielebarchiesi@0
|
1044 $displayed['name'] = (string) current($this->xpath("//input[@id='edit-name']/@value"));
|
danielebarchiesi@0
|
1045 $displayed['date'] = (string) current($this->xpath("//input[@id='edit-date']/@value"));
|
danielebarchiesi@0
|
1046 $this->drupalPost('comment/' . $comment->id . '/edit', $displayed, t('Save'));
|
danielebarchiesi@0
|
1047
|
danielebarchiesi@0
|
1048 // Check that the saved comment is still correct.
|
danielebarchiesi@0
|
1049 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
1050 $this->assertEqual($comment_loaded->subject, $edit['subject'], 'Subject loaded.');
|
danielebarchiesi@0
|
1051 $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], 'Comment body loaded.');
|
danielebarchiesi@0
|
1052 $this->assertEqual($comment_loaded->name, $edit['name'], 'Name loaded.');
|
danielebarchiesi@0
|
1053 $this->assertEqual($comment_loaded->created, $raw_date, 'Date loaded.');
|
danielebarchiesi@0
|
1054
|
danielebarchiesi@0
|
1055 }
|
danielebarchiesi@0
|
1056
|
danielebarchiesi@0
|
1057 }
|
danielebarchiesi@0
|
1058
|
danielebarchiesi@0
|
1059 class CommentAnonymous extends CommentHelperCase {
|
danielebarchiesi@0
|
1060 public static function getInfo() {
|
danielebarchiesi@0
|
1061 return array(
|
danielebarchiesi@0
|
1062 'name' => 'Anonymous comments',
|
danielebarchiesi@0
|
1063 'description' => 'Test anonymous comments.',
|
danielebarchiesi@0
|
1064 'group' => 'Comment',
|
danielebarchiesi@0
|
1065 );
|
danielebarchiesi@0
|
1066 }
|
danielebarchiesi@0
|
1067
|
danielebarchiesi@0
|
1068 function setUp() {
|
danielebarchiesi@0
|
1069 parent::setUp();
|
danielebarchiesi@0
|
1070 variable_set('user_register', USER_REGISTER_VISITORS);
|
danielebarchiesi@0
|
1071 }
|
danielebarchiesi@0
|
1072
|
danielebarchiesi@0
|
1073 /**
|
danielebarchiesi@0
|
1074 * Test anonymous comment functionality.
|
danielebarchiesi@0
|
1075 */
|
danielebarchiesi@0
|
1076 function testAnonymous() {
|
danielebarchiesi@0
|
1077 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1078 // Enabled anonymous user comments.
|
danielebarchiesi@0
|
1079 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
1080 'access comments' => TRUE,
|
danielebarchiesi@0
|
1081 'post comments' => TRUE,
|
danielebarchiesi@0
|
1082 'skip comment approval' => TRUE,
|
danielebarchiesi@0
|
1083 ));
|
danielebarchiesi@0
|
1084 $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
|
danielebarchiesi@0
|
1085 $this->drupalLogout();
|
danielebarchiesi@0
|
1086
|
danielebarchiesi@0
|
1087 // Post anonymous comment without contact info.
|
danielebarchiesi@0
|
1088 $anonymous_comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1089 $this->assertTrue($this->commentExists($anonymous_comment1), 'Anonymous comment without contact info found.');
|
danielebarchiesi@0
|
1090
|
danielebarchiesi@0
|
1091 // Allow contact info.
|
danielebarchiesi@0
|
1092 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1093 $this->setCommentAnonymous('1');
|
danielebarchiesi@0
|
1094
|
danielebarchiesi@0
|
1095 // Attempt to edit anonymous comment.
|
danielebarchiesi@0
|
1096 $this->drupalGet('comment/' . $anonymous_comment1->id . '/edit');
|
danielebarchiesi@0
|
1097 $edited_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1098 $this->assertTrue($this->commentExists($edited_comment, FALSE), 'Modified reply found.');
|
danielebarchiesi@0
|
1099 $this->drupalLogout();
|
danielebarchiesi@0
|
1100
|
danielebarchiesi@0
|
1101 // Post anonymous comment with contact info (optional).
|
danielebarchiesi@0
|
1102 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
1103 $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
|
danielebarchiesi@0
|
1104
|
danielebarchiesi@0
|
1105 $anonymous_comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1106 $this->assertTrue($this->commentExists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.');
|
danielebarchiesi@0
|
1107
|
danielebarchiesi@0
|
1108 // Ensure anonymous users cannot post in the name of registered users.
|
danielebarchiesi@0
|
1109 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
1110 $edit = array(
|
danielebarchiesi@0
|
1111 'name' => $this->admin_user->name,
|
danielebarchiesi@0
|
1112 'mail' => $this->randomName() . '@example.com',
|
danielebarchiesi@0
|
1113 'subject' => $this->randomName(),
|
danielebarchiesi@0
|
1114 "comment_body[$langcode][0][value]" => $this->randomName(),
|
danielebarchiesi@0
|
1115 );
|
danielebarchiesi@0
|
1116 $this->drupalPost('comment/reply/' . $this->node->nid, $edit, t('Save'));
|
danielebarchiesi@0
|
1117 $this->assertText(t('The name you used belongs to a registered user.'));
|
danielebarchiesi@0
|
1118
|
danielebarchiesi@0
|
1119 // Require contact info.
|
danielebarchiesi@0
|
1120 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1121 $this->setCommentAnonymous('2');
|
danielebarchiesi@0
|
1122 $this->drupalLogout();
|
danielebarchiesi@0
|
1123
|
danielebarchiesi@0
|
1124 // Try to post comment with contact info (required).
|
danielebarchiesi@0
|
1125 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
1126 $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
|
danielebarchiesi@0
|
1127
|
danielebarchiesi@0
|
1128 $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1129 // Name should have 'Anonymous' for value by default.
|
danielebarchiesi@0
|
1130 $this->assertText(t('E-mail field is required.'), 'E-mail required.');
|
danielebarchiesi@0
|
1131 $this->assertFalse($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) not found.');
|
danielebarchiesi@0
|
1132
|
danielebarchiesi@0
|
1133 // Post comment with contact info (required).
|
danielebarchiesi@0
|
1134 $author_name = $this->randomName();
|
danielebarchiesi@0
|
1135 $author_mail = $this->randomName() . '@example.com';
|
danielebarchiesi@0
|
1136 $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), array('name' => $author_name, 'mail' => $author_mail));
|
danielebarchiesi@0
|
1137 $this->assertTrue($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) found.');
|
danielebarchiesi@0
|
1138
|
danielebarchiesi@0
|
1139 // Make sure the user data appears correctly when editing the comment.
|
danielebarchiesi@0
|
1140 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1141 $this->drupalGet('comment/' . $anonymous_comment3->id . '/edit');
|
danielebarchiesi@0
|
1142 $this->assertRaw($author_name, "The anonymous user's name is correct when editing the comment.");
|
danielebarchiesi@0
|
1143 $this->assertRaw($author_mail, "The anonymous user's e-mail address is correct when editing the comment.");
|
danielebarchiesi@0
|
1144
|
danielebarchiesi@0
|
1145 // Unpublish comment.
|
danielebarchiesi@0
|
1146 $this->performCommentOperation($anonymous_comment3, 'unpublish');
|
danielebarchiesi@0
|
1147
|
danielebarchiesi@0
|
1148 $this->drupalGet('admin/content/comment/approval');
|
danielebarchiesi@0
|
1149 $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was unpublished.');
|
danielebarchiesi@0
|
1150
|
danielebarchiesi@0
|
1151 // Publish comment.
|
danielebarchiesi@0
|
1152 $this->performCommentOperation($anonymous_comment3, 'publish', TRUE);
|
danielebarchiesi@0
|
1153
|
danielebarchiesi@0
|
1154 $this->drupalGet('admin/content/comment');
|
danielebarchiesi@0
|
1155 $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was published.');
|
danielebarchiesi@0
|
1156
|
danielebarchiesi@0
|
1157 // Delete comment.
|
danielebarchiesi@0
|
1158 $this->performCommentOperation($anonymous_comment3, 'delete');
|
danielebarchiesi@0
|
1159
|
danielebarchiesi@0
|
1160 $this->drupalGet('admin/content/comment');
|
danielebarchiesi@0
|
1161 $this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was deleted.');
|
danielebarchiesi@0
|
1162 $this->drupalLogout();
|
danielebarchiesi@0
|
1163
|
danielebarchiesi@0
|
1164 // Reset.
|
danielebarchiesi@0
|
1165 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
1166 'access comments' => FALSE,
|
danielebarchiesi@0
|
1167 'post comments' => FALSE,
|
danielebarchiesi@0
|
1168 'skip comment approval' => FALSE,
|
danielebarchiesi@0
|
1169 ));
|
danielebarchiesi@0
|
1170
|
danielebarchiesi@0
|
1171 // Attempt to view comments while disallowed.
|
danielebarchiesi@0
|
1172 // NOTE: if authenticated user has permission to post comments, then a
|
danielebarchiesi@0
|
1173 // "Login or register to post comments" type link may be shown.
|
danielebarchiesi@0
|
1174 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1175 $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
|
danielebarchiesi@0
|
1176 $this->assertNoLink('Add new comment', 'Link to add comment was found.');
|
danielebarchiesi@0
|
1177
|
danielebarchiesi@0
|
1178 // Attempt to view node-comment form while disallowed.
|
danielebarchiesi@0
|
1179 $this->drupalGet('comment/reply/' . $this->node->nid);
|
danielebarchiesi@0
|
1180 $this->assertText('You are not authorized to post comments', 'Error attempting to post comment.');
|
danielebarchiesi@0
|
1181 $this->assertNoFieldByName('subject', '', 'Subject field not found.');
|
danielebarchiesi@0
|
1182 $this->assertNoFieldByName("comment_body[$langcode][0][value]", '', 'Comment field not found.');
|
danielebarchiesi@0
|
1183
|
danielebarchiesi@0
|
1184 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
1185 'access comments' => TRUE,
|
danielebarchiesi@0
|
1186 'post comments' => FALSE,
|
danielebarchiesi@0
|
1187 'skip comment approval' => FALSE,
|
danielebarchiesi@0
|
1188 ));
|
danielebarchiesi@0
|
1189 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1190 $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
|
danielebarchiesi@0
|
1191 $this->assertLink('Log in', 1, 'Link to log in was found.');
|
danielebarchiesi@0
|
1192 $this->assertLink('register', 1, 'Link to register was found.');
|
danielebarchiesi@0
|
1193
|
danielebarchiesi@0
|
1194 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
1195 'access comments' => FALSE,
|
danielebarchiesi@0
|
1196 'post comments' => TRUE,
|
danielebarchiesi@0
|
1197 'skip comment approval' => TRUE,
|
danielebarchiesi@0
|
1198 ));
|
danielebarchiesi@0
|
1199 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1200 $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
|
danielebarchiesi@0
|
1201 $this->assertFieldByName('subject', '', 'Subject field found.');
|
danielebarchiesi@0
|
1202 $this->assertFieldByName("comment_body[$langcode][0][value]", '', 'Comment field found.');
|
danielebarchiesi@0
|
1203
|
danielebarchiesi@0
|
1204 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $anonymous_comment3->id);
|
danielebarchiesi@0
|
1205 $this->assertText('You are not authorized to view comments', 'Error attempting to post reply.');
|
danielebarchiesi@0
|
1206 $this->assertNoText($author_name, 'Comment not displayed.');
|
danielebarchiesi@0
|
1207 }
|
danielebarchiesi@0
|
1208 }
|
danielebarchiesi@0
|
1209
|
danielebarchiesi@0
|
1210 /**
|
danielebarchiesi@0
|
1211 * Verify pagination of comments.
|
danielebarchiesi@0
|
1212 */
|
danielebarchiesi@0
|
1213 class CommentPagerTest extends CommentHelperCase {
|
danielebarchiesi@0
|
1214
|
danielebarchiesi@0
|
1215 public static function getInfo() {
|
danielebarchiesi@0
|
1216 return array(
|
danielebarchiesi@0
|
1217 'name' => 'Comment paging settings',
|
danielebarchiesi@0
|
1218 'description' => 'Test paging of comments and their settings.',
|
danielebarchiesi@0
|
1219 'group' => 'Comment',
|
danielebarchiesi@0
|
1220 );
|
danielebarchiesi@0
|
1221 }
|
danielebarchiesi@0
|
1222
|
danielebarchiesi@0
|
1223 /**
|
danielebarchiesi@0
|
1224 * Confirm comment paging works correctly with flat and threaded comments.
|
danielebarchiesi@0
|
1225 */
|
danielebarchiesi@0
|
1226 function testCommentPaging() {
|
danielebarchiesi@0
|
1227 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1228
|
danielebarchiesi@0
|
1229 // Set comment variables.
|
danielebarchiesi@0
|
1230 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
1231 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1232 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
1233
|
danielebarchiesi@0
|
1234 // Create a node and three comments.
|
danielebarchiesi@0
|
1235 $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
1236 $comments = array();
|
danielebarchiesi@0
|
1237 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1238 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1239 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1240
|
danielebarchiesi@0
|
1241 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
|
danielebarchiesi@0
|
1242
|
danielebarchiesi@0
|
1243 // Set comments to one per page so that we are able to test paging without
|
danielebarchiesi@0
|
1244 // needing to insert large numbers of comments.
|
danielebarchiesi@0
|
1245 $this->setCommentsPerPage(1);
|
danielebarchiesi@0
|
1246
|
danielebarchiesi@0
|
1247 // Check the first page of the node, and confirm the correct comments are
|
danielebarchiesi@0
|
1248 // shown.
|
danielebarchiesi@0
|
1249 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
1250 $this->assertRaw(t('next'), 'Paging links found.');
|
danielebarchiesi@0
|
1251 $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page 1.');
|
danielebarchiesi@0
|
1252 $this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 1.');
|
danielebarchiesi@0
|
1253 $this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 1.');
|
danielebarchiesi@0
|
1254
|
danielebarchiesi@0
|
1255 // Check the second page.
|
danielebarchiesi@0
|
1256 $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 1)));
|
danielebarchiesi@0
|
1257 $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page 2.');
|
danielebarchiesi@0
|
1258 $this->assertFalse($this->commentExists($comments[0]), 'Comment 1 does not appear on page 2.');
|
danielebarchiesi@0
|
1259 $this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 2.');
|
danielebarchiesi@0
|
1260
|
danielebarchiesi@0
|
1261 // Check the third page.
|
danielebarchiesi@0
|
1262 $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 2)));
|
danielebarchiesi@0
|
1263 $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page 3.');
|
danielebarchiesi@0
|
1264 $this->assertFalse($this->commentExists($comments[0]), 'Comment 1 does not appear on page 3.');
|
danielebarchiesi@0
|
1265 $this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 3.');
|
danielebarchiesi@0
|
1266
|
danielebarchiesi@0
|
1267 // Post a reply to the oldest comment and test again.
|
danielebarchiesi@0
|
1268 $replies = array();
|
danielebarchiesi@0
|
1269 $oldest_comment = reset($comments);
|
danielebarchiesi@0
|
1270 $this->drupalGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
|
danielebarchiesi@0
|
1271 $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1272
|
danielebarchiesi@0
|
1273 $this->setCommentsPerPage(2);
|
danielebarchiesi@0
|
1274 // We are still in flat view - the replies should not be on the first page,
|
danielebarchiesi@0
|
1275 // even though they are replies to the oldest comment.
|
danielebarchiesi@0
|
1276 $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
|
danielebarchiesi@0
|
1277 $this->assertFalse($this->commentExists($reply, TRUE), 'In flat mode, reply does not appear on page 1.');
|
danielebarchiesi@0
|
1278
|
danielebarchiesi@0
|
1279 // If we switch to threaded mode, the replies on the oldest comment
|
danielebarchiesi@0
|
1280 // should be bumped to the first page and comment 6 should be bumped
|
danielebarchiesi@0
|
1281 // to the second page.
|
danielebarchiesi@0
|
1282 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
|
danielebarchiesi@0
|
1283 $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
|
danielebarchiesi@0
|
1284 $this->assertTrue($this->commentExists($reply, TRUE), 'In threaded mode, reply appears on page 1.');
|
danielebarchiesi@0
|
1285 $this->assertFalse($this->commentExists($comments[1]), 'In threaded mode, comment 2 has been bumped off of page 1.');
|
danielebarchiesi@0
|
1286
|
danielebarchiesi@0
|
1287 // If (# replies > # comments per page) in threaded expanded view,
|
danielebarchiesi@0
|
1288 // the overage should be bumped.
|
danielebarchiesi@0
|
1289 $reply2 = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1290 $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0)));
|
danielebarchiesi@0
|
1291 $this->assertFalse($this->commentExists($reply2, TRUE), 'In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.');
|
danielebarchiesi@0
|
1292
|
danielebarchiesi@0
|
1293 $this->drupalLogout();
|
danielebarchiesi@0
|
1294 }
|
danielebarchiesi@0
|
1295
|
danielebarchiesi@0
|
1296 /**
|
danielebarchiesi@0
|
1297 * Test comment ordering and threading.
|
danielebarchiesi@0
|
1298 */
|
danielebarchiesi@0
|
1299 function testCommentOrderingThreading() {
|
danielebarchiesi@0
|
1300 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1301
|
danielebarchiesi@0
|
1302 // Set comment variables.
|
danielebarchiesi@0
|
1303 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
1304 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1305 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
1306
|
danielebarchiesi@0
|
1307 // Display all the comments on the same page.
|
danielebarchiesi@0
|
1308 $this->setCommentsPerPage(1000);
|
danielebarchiesi@0
|
1309
|
danielebarchiesi@0
|
1310 // Create a node and three comments.
|
danielebarchiesi@0
|
1311 $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
1312 $comments = array();
|
danielebarchiesi@0
|
1313 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1314 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1315 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1316
|
danielebarchiesi@0
|
1317 // Post a reply to the second comment.
|
danielebarchiesi@0
|
1318 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
|
danielebarchiesi@0
|
1319 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1320
|
danielebarchiesi@0
|
1321 // Post a reply to the first comment.
|
danielebarchiesi@0
|
1322 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
|
danielebarchiesi@0
|
1323 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1324
|
danielebarchiesi@0
|
1325 // Post a reply to the last comment.
|
danielebarchiesi@0
|
1326 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
|
danielebarchiesi@0
|
1327 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1328
|
danielebarchiesi@0
|
1329 // Post a reply to the second comment.
|
danielebarchiesi@0
|
1330 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[3]->id);
|
danielebarchiesi@0
|
1331 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1332
|
danielebarchiesi@0
|
1333 // At this point, the comment tree is:
|
danielebarchiesi@0
|
1334 // - 0
|
danielebarchiesi@0
|
1335 // - 4
|
danielebarchiesi@0
|
1336 // - 1
|
danielebarchiesi@0
|
1337 // - 3
|
danielebarchiesi@0
|
1338 // - 6
|
danielebarchiesi@0
|
1339 // - 2
|
danielebarchiesi@0
|
1340 // - 5
|
danielebarchiesi@0
|
1341
|
danielebarchiesi@0
|
1342 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
|
danielebarchiesi@0
|
1343
|
danielebarchiesi@0
|
1344 $expected_order = array(
|
danielebarchiesi@0
|
1345 0,
|
danielebarchiesi@0
|
1346 1,
|
danielebarchiesi@0
|
1347 2,
|
danielebarchiesi@0
|
1348 3,
|
danielebarchiesi@0
|
1349 4,
|
danielebarchiesi@0
|
1350 5,
|
danielebarchiesi@0
|
1351 6,
|
danielebarchiesi@0
|
1352 );
|
danielebarchiesi@0
|
1353 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
1354 $this->assertCommentOrder($comments, $expected_order);
|
danielebarchiesi@0
|
1355
|
danielebarchiesi@0
|
1356 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
|
danielebarchiesi@0
|
1357
|
danielebarchiesi@0
|
1358 $expected_order = array(
|
danielebarchiesi@0
|
1359 0,
|
danielebarchiesi@0
|
1360 4,
|
danielebarchiesi@0
|
1361 1,
|
danielebarchiesi@0
|
1362 3,
|
danielebarchiesi@0
|
1363 6,
|
danielebarchiesi@0
|
1364 2,
|
danielebarchiesi@0
|
1365 5,
|
danielebarchiesi@0
|
1366 );
|
danielebarchiesi@0
|
1367 $this->drupalGet('node/' . $node->nid);
|
danielebarchiesi@0
|
1368 $this->assertCommentOrder($comments, $expected_order);
|
danielebarchiesi@0
|
1369 }
|
danielebarchiesi@0
|
1370
|
danielebarchiesi@0
|
1371 /**
|
danielebarchiesi@0
|
1372 * Helper function: assert that the comments are displayed in the correct order.
|
danielebarchiesi@0
|
1373 *
|
danielebarchiesi@0
|
1374 * @param $comments
|
danielebarchiesi@0
|
1375 * And array of comments.
|
danielebarchiesi@0
|
1376 * @param $expected_order
|
danielebarchiesi@0
|
1377 * An array of keys from $comments describing the expected order.
|
danielebarchiesi@0
|
1378 */
|
danielebarchiesi@0
|
1379 function assertCommentOrder(array $comments, array $expected_order) {
|
danielebarchiesi@0
|
1380 $expected_cids = array();
|
danielebarchiesi@0
|
1381
|
danielebarchiesi@0
|
1382 // First, rekey the expected order by cid.
|
danielebarchiesi@0
|
1383 foreach ($expected_order as $key) {
|
danielebarchiesi@0
|
1384 $expected_cids[] = $comments[$key]->id;
|
danielebarchiesi@0
|
1385 }
|
danielebarchiesi@0
|
1386
|
danielebarchiesi@0
|
1387 $comment_anchors = $this->xpath('//a[starts-with(@id,"comment-")]');
|
danielebarchiesi@0
|
1388 $result_order = array();
|
danielebarchiesi@0
|
1389 foreach ($comment_anchors as $anchor) {
|
danielebarchiesi@0
|
1390 $result_order[] = substr($anchor['id'], 8);
|
danielebarchiesi@0
|
1391 }
|
danielebarchiesi@0
|
1392
|
danielebarchiesi@0
|
1393 return $this->assertIdentical($expected_cids, $result_order, format_string('Comment order: expected @expected, returned @returned.', array('@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order))));
|
danielebarchiesi@0
|
1394 }
|
danielebarchiesi@0
|
1395
|
danielebarchiesi@0
|
1396 /**
|
danielebarchiesi@0
|
1397 * Test comment_new_page_count().
|
danielebarchiesi@0
|
1398 */
|
danielebarchiesi@0
|
1399 function testCommentNewPageIndicator() {
|
danielebarchiesi@0
|
1400 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1401
|
danielebarchiesi@0
|
1402 // Set comment variables.
|
danielebarchiesi@0
|
1403 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
1404 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1405 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
1406
|
danielebarchiesi@0
|
1407 // Set comments to one per page so that we are able to test paging without
|
danielebarchiesi@0
|
1408 // needing to insert large numbers of comments.
|
danielebarchiesi@0
|
1409 $this->setCommentsPerPage(1);
|
danielebarchiesi@0
|
1410
|
danielebarchiesi@0
|
1411 // Create a node and three comments.
|
danielebarchiesi@0
|
1412 $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
danielebarchiesi@0
|
1413 $comments = array();
|
danielebarchiesi@0
|
1414 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1415 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1416 $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1417
|
danielebarchiesi@0
|
1418 // Post a reply to the second comment.
|
danielebarchiesi@0
|
1419 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
|
danielebarchiesi@0
|
1420 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1421
|
danielebarchiesi@0
|
1422 // Post a reply to the first comment.
|
danielebarchiesi@0
|
1423 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
|
danielebarchiesi@0
|
1424 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1425
|
danielebarchiesi@0
|
1426 // Post a reply to the last comment.
|
danielebarchiesi@0
|
1427 $this->drupalGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
|
danielebarchiesi@0
|
1428 $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1429
|
danielebarchiesi@0
|
1430 // At this point, the comment tree is:
|
danielebarchiesi@0
|
1431 // - 0
|
danielebarchiesi@0
|
1432 // - 4
|
danielebarchiesi@0
|
1433 // - 1
|
danielebarchiesi@0
|
1434 // - 3
|
danielebarchiesi@0
|
1435 // - 2
|
danielebarchiesi@0
|
1436 // - 5
|
danielebarchiesi@0
|
1437
|
danielebarchiesi@0
|
1438 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, t('Comment paging changed.'));
|
danielebarchiesi@0
|
1439
|
danielebarchiesi@0
|
1440 $expected_pages = array(
|
danielebarchiesi@0
|
1441 1 => 5, // Page of comment 5
|
danielebarchiesi@0
|
1442 2 => 4, // Page of comment 4
|
danielebarchiesi@0
|
1443 3 => 3, // Page of comment 3
|
danielebarchiesi@0
|
1444 4 => 2, // Page of comment 2
|
danielebarchiesi@0
|
1445 5 => 1, // Page of comment 1
|
danielebarchiesi@0
|
1446 6 => 0, // Page of comment 0
|
danielebarchiesi@0
|
1447 );
|
danielebarchiesi@0
|
1448
|
danielebarchiesi@0
|
1449 $node = node_load($node->nid);
|
danielebarchiesi@0
|
1450 foreach ($expected_pages as $new_replies => $expected_page) {
|
danielebarchiesi@0
|
1451 $returned = comment_new_page_count($node->comment_count, $new_replies, $node);
|
danielebarchiesi@0
|
1452 $returned_page = is_array($returned) ? $returned['page'] : 0;
|
danielebarchiesi@0
|
1453 $this->assertIdentical($expected_page, $returned_page, format_string('Flat mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
|
danielebarchiesi@0
|
1454 }
|
danielebarchiesi@0
|
1455
|
danielebarchiesi@0
|
1456 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Switched to threaded mode.'));
|
danielebarchiesi@0
|
1457
|
danielebarchiesi@0
|
1458 $expected_pages = array(
|
danielebarchiesi@0
|
1459 1 => 5, // Page of comment 5
|
danielebarchiesi@0
|
1460 2 => 1, // Page of comment 4
|
danielebarchiesi@0
|
1461 3 => 1, // Page of comment 4
|
danielebarchiesi@0
|
1462 4 => 1, // Page of comment 4
|
danielebarchiesi@0
|
1463 5 => 1, // Page of comment 4
|
danielebarchiesi@0
|
1464 6 => 0, // Page of comment 0
|
danielebarchiesi@0
|
1465 );
|
danielebarchiesi@0
|
1466
|
danielebarchiesi@0
|
1467 $node = node_load($node->nid);
|
danielebarchiesi@0
|
1468 foreach ($expected_pages as $new_replies => $expected_page) {
|
danielebarchiesi@0
|
1469 $returned = comment_new_page_count($node->comment_count, $new_replies, $node);
|
danielebarchiesi@0
|
1470 $returned_page = is_array($returned) ? $returned['page'] : 0;
|
danielebarchiesi@0
|
1471 $this->assertEqual($expected_page, $returned_page, format_string('Threaded mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
|
danielebarchiesi@0
|
1472 }
|
danielebarchiesi@0
|
1473 }
|
danielebarchiesi@0
|
1474 }
|
danielebarchiesi@0
|
1475
|
danielebarchiesi@0
|
1476 /**
|
danielebarchiesi@0
|
1477 * Tests comments with node access.
|
danielebarchiesi@0
|
1478 *
|
danielebarchiesi@0
|
1479 * See http://drupal.org/node/886752 -- verify there is no PostgreSQL error when
|
danielebarchiesi@0
|
1480 * viewing a node with threaded comments (a comment and a reply), if a node
|
danielebarchiesi@0
|
1481 * access module is in use.
|
danielebarchiesi@0
|
1482 */
|
danielebarchiesi@0
|
1483 class CommentNodeAccessTest extends CommentHelperCase {
|
danielebarchiesi@0
|
1484 public static function getInfo() {
|
danielebarchiesi@0
|
1485 return array(
|
danielebarchiesi@0
|
1486 'name' => 'Comment node access',
|
danielebarchiesi@0
|
1487 'description' => 'Test comment viewing with node access.',
|
danielebarchiesi@0
|
1488 'group' => 'Comment',
|
danielebarchiesi@0
|
1489 );
|
danielebarchiesi@0
|
1490 }
|
danielebarchiesi@0
|
1491
|
danielebarchiesi@0
|
1492 function setUp() {
|
danielebarchiesi@0
|
1493 DrupalWebTestCase::setUp('comment', 'search', 'node_access_test');
|
danielebarchiesi@0
|
1494 node_access_rebuild();
|
danielebarchiesi@0
|
1495
|
danielebarchiesi@0
|
1496 // Create users and test node.
|
danielebarchiesi@0
|
1497 $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
|
danielebarchiesi@0
|
1498 $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments', 'node test view'));
|
danielebarchiesi@0
|
1499 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
|
danielebarchiesi@0
|
1500 }
|
danielebarchiesi@0
|
1501
|
danielebarchiesi@0
|
1502 /**
|
danielebarchiesi@0
|
1503 * Test that threaded comments can be viewed.
|
danielebarchiesi@0
|
1504 */
|
danielebarchiesi@0
|
1505 function testThreadedCommentView() {
|
danielebarchiesi@0
|
1506 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
1507 // Set comments to have subject required and preview disabled.
|
danielebarchiesi@0
|
1508 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1509 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
1510 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
1511 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1512 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
1513 $this->drupalLogout();
|
danielebarchiesi@0
|
1514
|
danielebarchiesi@0
|
1515 // Post comment.
|
danielebarchiesi@0
|
1516 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
1517 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
1518 $comment_subject = $this->randomName();
|
danielebarchiesi@0
|
1519 $comment = $this->postComment($this->node, $comment_text, $comment_subject);
|
danielebarchiesi@0
|
1520 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
1521 $this->assertTrue($this->commentExists($comment), 'Comment found.');
|
danielebarchiesi@0
|
1522
|
danielebarchiesi@0
|
1523 // Check comment display.
|
danielebarchiesi@0
|
1524 $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
1525 $this->assertText($comment_subject, 'Individual comment subject found.');
|
danielebarchiesi@0
|
1526 $this->assertText($comment_text, 'Individual comment body found.');
|
danielebarchiesi@0
|
1527
|
danielebarchiesi@0
|
1528 // Reply to comment, creating second comment.
|
danielebarchiesi@0
|
1529 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
1530 $reply_text = $this->randomName();
|
danielebarchiesi@0
|
1531 $reply_subject = $this->randomName();
|
danielebarchiesi@0
|
1532 $reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE);
|
danielebarchiesi@0
|
1533 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
1534 $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
|
danielebarchiesi@0
|
1535
|
danielebarchiesi@0
|
1536 // Go to the node page and verify comment and reply are visible.
|
danielebarchiesi@0
|
1537 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1538 $this->assertText($comment_text);
|
danielebarchiesi@0
|
1539 $this->assertText($comment_subject);
|
danielebarchiesi@0
|
1540 $this->assertText($reply_text);
|
danielebarchiesi@0
|
1541 $this->assertText($reply_subject);
|
danielebarchiesi@0
|
1542 }
|
danielebarchiesi@0
|
1543 }
|
danielebarchiesi@0
|
1544
|
danielebarchiesi@0
|
1545 class CommentApprovalTest extends CommentHelperCase {
|
danielebarchiesi@0
|
1546 public static function getInfo() {
|
danielebarchiesi@0
|
1547 return array(
|
danielebarchiesi@0
|
1548 'name' => 'Comment approval',
|
danielebarchiesi@0
|
1549 'description' => 'Test comment approval functionality.',
|
danielebarchiesi@0
|
1550 'group' => 'Comment',
|
danielebarchiesi@0
|
1551 );
|
danielebarchiesi@0
|
1552 }
|
danielebarchiesi@0
|
1553
|
danielebarchiesi@0
|
1554 /**
|
danielebarchiesi@0
|
1555 * Test comment approval functionality through admin/content/comment.
|
danielebarchiesi@0
|
1556 */
|
danielebarchiesi@0
|
1557 function testApprovalAdminInterface() {
|
danielebarchiesi@0
|
1558 // Set anonymous comments to require approval.
|
danielebarchiesi@0
|
1559 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
1560 'access comments' => TRUE,
|
danielebarchiesi@0
|
1561 'post comments' => TRUE,
|
danielebarchiesi@0
|
1562 'skip comment approval' => FALSE,
|
danielebarchiesi@0
|
1563 ));
|
danielebarchiesi@0
|
1564 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1565 $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
|
danielebarchiesi@0
|
1566
|
danielebarchiesi@0
|
1567 // Test that the comments page loads correctly when there are no comments
|
danielebarchiesi@0
|
1568 $this->drupalGet('admin/content/comment');
|
danielebarchiesi@0
|
1569 $this->assertText(t('No comments available.'));
|
danielebarchiesi@0
|
1570
|
danielebarchiesi@0
|
1571 $this->drupalLogout();
|
danielebarchiesi@0
|
1572
|
danielebarchiesi@0
|
1573 // Post anonymous comment without contact info.
|
danielebarchiesi@0
|
1574 $subject = $this->randomName();
|
danielebarchiesi@0
|
1575 $body = $this->randomName();
|
danielebarchiesi@0
|
1576 $this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
|
danielebarchiesi@0
|
1577 $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
|
danielebarchiesi@0
|
1578
|
danielebarchiesi@0
|
1579 // Get unapproved comment id.
|
danielebarchiesi@0
|
1580 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1581 $anonymous_comment4 = $this->getUnapprovedComment($subject);
|
danielebarchiesi@0
|
1582 $anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
|
danielebarchiesi@0
|
1583 $this->drupalLogout();
|
danielebarchiesi@0
|
1584
|
danielebarchiesi@0
|
1585 $this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
|
danielebarchiesi@0
|
1586
|
danielebarchiesi@0
|
1587 // Approve comment.
|
danielebarchiesi@0
|
1588 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1589 $this->performCommentOperation($anonymous_comment4, 'publish', TRUE);
|
danielebarchiesi@0
|
1590 $this->drupalLogout();
|
danielebarchiesi@0
|
1591
|
danielebarchiesi@0
|
1592 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1593 $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
|
danielebarchiesi@0
|
1594
|
danielebarchiesi@0
|
1595 // Post 2 anonymous comments without contact info.
|
danielebarchiesi@0
|
1596 $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1597 $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1598
|
danielebarchiesi@0
|
1599 // Publish multiple comments in one operation.
|
danielebarchiesi@0
|
1600 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1601 $this->drupalGet('admin/content/comment/approval');
|
danielebarchiesi@0
|
1602 $this->assertText(t('Unapproved comments (@count)', array('@count' => 2)), 'Two unapproved comments waiting for approval.');
|
danielebarchiesi@0
|
1603 $edit = array(
|
danielebarchiesi@0
|
1604 "comments[{$comments[0]->id}]" => 1,
|
danielebarchiesi@0
|
1605 "comments[{$comments[1]->id}]" => 1,
|
danielebarchiesi@0
|
1606 );
|
danielebarchiesi@0
|
1607 $this->drupalPost(NULL, $edit, t('Update'));
|
danielebarchiesi@0
|
1608 $this->assertText(t('Unapproved comments (@count)', array('@count' => 0)), 'All comments were approved.');
|
danielebarchiesi@0
|
1609
|
danielebarchiesi@0
|
1610 // Delete multiple comments in one operation.
|
danielebarchiesi@0
|
1611 $edit = array(
|
danielebarchiesi@0
|
1612 'operation' => 'delete',
|
danielebarchiesi@0
|
1613 "comments[{$comments[0]->id}]" => 1,
|
danielebarchiesi@0
|
1614 "comments[{$comments[1]->id}]" => 1,
|
danielebarchiesi@0
|
1615 "comments[{$anonymous_comment4->id}]" => 1,
|
danielebarchiesi@0
|
1616 );
|
danielebarchiesi@0
|
1617 $this->drupalPost(NULL, $edit, t('Update'));
|
danielebarchiesi@0
|
1618 $this->assertText(t('Are you sure you want to delete these comments and all their children?'), 'Confirmation required.');
|
danielebarchiesi@0
|
1619 $this->drupalPost(NULL, $edit, t('Delete comments'));
|
danielebarchiesi@0
|
1620 $this->assertText(t('No comments available.'), 'All comments were deleted.');
|
danielebarchiesi@0
|
1621 }
|
danielebarchiesi@0
|
1622
|
danielebarchiesi@0
|
1623 /**
|
danielebarchiesi@0
|
1624 * Test comment approval functionality through node interface.
|
danielebarchiesi@0
|
1625 */
|
danielebarchiesi@0
|
1626 function testApprovalNodeInterface() {
|
danielebarchiesi@0
|
1627 // Set anonymous comments to require approval.
|
danielebarchiesi@0
|
1628 user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
|
danielebarchiesi@0
|
1629 'access comments' => TRUE,
|
danielebarchiesi@0
|
1630 'post comments' => TRUE,
|
danielebarchiesi@0
|
1631 'skip comment approval' => FALSE,
|
danielebarchiesi@0
|
1632 ));
|
danielebarchiesi@0
|
1633 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1634 $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
|
danielebarchiesi@0
|
1635 $this->drupalLogout();
|
danielebarchiesi@0
|
1636
|
danielebarchiesi@0
|
1637 // Post anonymous comment without contact info.
|
danielebarchiesi@0
|
1638 $subject = $this->randomName();
|
danielebarchiesi@0
|
1639 $body = $this->randomName();
|
danielebarchiesi@0
|
1640 $this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
|
danielebarchiesi@0
|
1641 $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
|
danielebarchiesi@0
|
1642
|
danielebarchiesi@0
|
1643 // Get unapproved comment id.
|
danielebarchiesi@0
|
1644 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1645 $anonymous_comment4 = $this->getUnapprovedComment($subject);
|
danielebarchiesi@0
|
1646 $anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
|
danielebarchiesi@0
|
1647 $this->drupalLogout();
|
danielebarchiesi@0
|
1648
|
danielebarchiesi@0
|
1649 $this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
|
danielebarchiesi@0
|
1650
|
danielebarchiesi@0
|
1651 // Approve comment.
|
danielebarchiesi@0
|
1652 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1653 $this->drupalGet('comment/1/approve');
|
danielebarchiesi@0
|
1654 $this->assertResponse(403, 'Forged comment approval was denied.');
|
danielebarchiesi@0
|
1655 $this->drupalGet('comment/1/approve', array('query' => array('token' => 'forged')));
|
danielebarchiesi@0
|
1656 $this->assertResponse(403, 'Forged comment approval was denied.');
|
danielebarchiesi@0
|
1657 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1658 $this->clickLink(t('approve'));
|
danielebarchiesi@0
|
1659 $this->drupalLogout();
|
danielebarchiesi@0
|
1660
|
danielebarchiesi@0
|
1661 $this->drupalGet('node/' . $this->node->nid);
|
danielebarchiesi@0
|
1662 $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
|
danielebarchiesi@0
|
1663 }
|
danielebarchiesi@0
|
1664 }
|
danielebarchiesi@0
|
1665
|
danielebarchiesi@0
|
1666 /**
|
danielebarchiesi@0
|
1667 * Functional tests for the comment module blocks.
|
danielebarchiesi@0
|
1668 */
|
danielebarchiesi@0
|
1669 class CommentBlockFunctionalTest extends CommentHelperCase {
|
danielebarchiesi@0
|
1670 public static function getInfo() {
|
danielebarchiesi@0
|
1671 return array(
|
danielebarchiesi@0
|
1672 'name' => 'Comment blocks',
|
danielebarchiesi@0
|
1673 'description' => 'Test comment block functionality.',
|
danielebarchiesi@0
|
1674 'group' => 'Comment',
|
danielebarchiesi@0
|
1675 );
|
danielebarchiesi@0
|
1676 }
|
danielebarchiesi@0
|
1677
|
danielebarchiesi@0
|
1678 /**
|
danielebarchiesi@0
|
1679 * Test the recent comments block.
|
danielebarchiesi@0
|
1680 */
|
danielebarchiesi@0
|
1681 function testRecentCommentBlock() {
|
danielebarchiesi@0
|
1682 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1683
|
danielebarchiesi@0
|
1684 // Set the block to a region to confirm block is available.
|
danielebarchiesi@0
|
1685 $edit = array(
|
danielebarchiesi@0
|
1686 'blocks[comment_recent][region]' => 'sidebar_first',
|
danielebarchiesi@0
|
1687 );
|
danielebarchiesi@0
|
1688 $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
danielebarchiesi@0
|
1689 $this->assertText(t('The block settings have been updated.'), 'Block saved to first sidebar region.');
|
danielebarchiesi@0
|
1690
|
danielebarchiesi@0
|
1691 // Set block title and variables.
|
danielebarchiesi@0
|
1692 $block = array(
|
danielebarchiesi@0
|
1693 'title' => $this->randomName(),
|
danielebarchiesi@0
|
1694 'comment_block_count' => 2,
|
danielebarchiesi@0
|
1695 );
|
danielebarchiesi@0
|
1696 $this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block'));
|
danielebarchiesi@0
|
1697 $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
|
danielebarchiesi@0
|
1698
|
danielebarchiesi@0
|
1699 // Add some test comments, one without a subject.
|
danielebarchiesi@0
|
1700 $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1701 $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1702 $comment3 = $this->postComment($this->node, $this->randomName());
|
danielebarchiesi@0
|
1703
|
danielebarchiesi@0
|
1704 // Test that a user without the 'access comments' permission cannot see the
|
danielebarchiesi@0
|
1705 // block.
|
danielebarchiesi@0
|
1706 $this->drupalLogout();
|
danielebarchiesi@0
|
1707 user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
|
danielebarchiesi@0
|
1708 $this->drupalGet('');
|
danielebarchiesi@0
|
1709 $this->assertNoText($block['title'], 'Block was not found.');
|
danielebarchiesi@0
|
1710 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
|
danielebarchiesi@0
|
1711
|
danielebarchiesi@0
|
1712 // Test that a user with the 'access comments' permission can see the
|
danielebarchiesi@0
|
1713 // block.
|
danielebarchiesi@0
|
1714 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
1715 $this->drupalGet('');
|
danielebarchiesi@0
|
1716 $this->assertText($block['title'], 'Block was found.');
|
danielebarchiesi@0
|
1717
|
danielebarchiesi@0
|
1718 // Test the only the 2 latest comments are shown and in the proper order.
|
danielebarchiesi@0
|
1719 $this->assertNoText($comment1->subject, 'Comment not found in block.');
|
danielebarchiesi@0
|
1720 $this->assertText($comment2->subject, 'Comment found in block.');
|
danielebarchiesi@0
|
1721 $this->assertText($comment3->comment, 'Comment found in block.');
|
danielebarchiesi@0
|
1722 $this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment) < strpos($this->drupalGetContent(), $comment2->subject), 'Comments were ordered correctly in block.');
|
danielebarchiesi@0
|
1723
|
danielebarchiesi@0
|
1724 // Set the number of recent comments to show to 10.
|
danielebarchiesi@0
|
1725 $this->drupalLogout();
|
danielebarchiesi@0
|
1726 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1727 $block = array(
|
danielebarchiesi@0
|
1728 'comment_block_count' => 10,
|
danielebarchiesi@0
|
1729 );
|
danielebarchiesi@0
|
1730 $this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block'));
|
danielebarchiesi@0
|
1731 $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
|
danielebarchiesi@0
|
1732
|
danielebarchiesi@0
|
1733 // Post an additional comment.
|
danielebarchiesi@0
|
1734 $comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1735
|
danielebarchiesi@0
|
1736 // Test that all four comments are shown.
|
danielebarchiesi@0
|
1737 $this->assertText($comment1->subject, 'Comment found in block.');
|
danielebarchiesi@0
|
1738 $this->assertText($comment2->subject, 'Comment found in block.');
|
danielebarchiesi@0
|
1739 $this->assertText($comment3->comment, 'Comment found in block.');
|
danielebarchiesi@0
|
1740 $this->assertText($comment4->subject, 'Comment found in block.');
|
danielebarchiesi@0
|
1741
|
danielebarchiesi@0
|
1742 // Test that links to comments work when comments are across pages.
|
danielebarchiesi@0
|
1743 $this->setCommentsPerPage(1);
|
danielebarchiesi@0
|
1744 $this->drupalGet('');
|
danielebarchiesi@0
|
1745 $this->clickLink($comment1->subject);
|
danielebarchiesi@0
|
1746 $this->assertText($comment1->subject, 'Comment link goes to correct page.');
|
danielebarchiesi@0
|
1747 $this->drupalGet('');
|
danielebarchiesi@0
|
1748 $this->clickLink($comment2->subject);
|
danielebarchiesi@0
|
1749 $this->assertText($comment2->subject, 'Comment link goes to correct page.');
|
danielebarchiesi@0
|
1750 $this->clickLink($comment4->subject);
|
danielebarchiesi@0
|
1751 $this->assertText($comment4->subject, 'Comment link goes to correct page.');
|
danielebarchiesi@0
|
1752 // Check that when viewing a comment page from a link to the comment, that
|
danielebarchiesi@0
|
1753 // rel="canonical" is added to the head of the document.
|
danielebarchiesi@0
|
1754 $this->assertRaw('<link rel="canonical"', 'Canonical URL was found in the HTML head');
|
danielebarchiesi@0
|
1755 }
|
danielebarchiesi@0
|
1756 }
|
danielebarchiesi@0
|
1757
|
danielebarchiesi@0
|
1758 /**
|
danielebarchiesi@0
|
1759 * Unit tests for comment module integration with RSS feeds.
|
danielebarchiesi@0
|
1760 */
|
danielebarchiesi@0
|
1761 class CommentRSSUnitTest extends CommentHelperCase {
|
danielebarchiesi@0
|
1762 public static function getInfo() {
|
danielebarchiesi@0
|
1763 return array(
|
danielebarchiesi@0
|
1764 'name' => 'Comment RSS',
|
danielebarchiesi@0
|
1765 'description' => 'Test comments as part of an RSS feed.',
|
danielebarchiesi@0
|
1766 'group' => 'Comment',
|
danielebarchiesi@0
|
1767 );
|
danielebarchiesi@0
|
1768 }
|
danielebarchiesi@0
|
1769
|
danielebarchiesi@0
|
1770 /**
|
danielebarchiesi@0
|
1771 * Test comments as part of an RSS feed.
|
danielebarchiesi@0
|
1772 */
|
danielebarchiesi@0
|
1773 function testCommentRSS() {
|
danielebarchiesi@0
|
1774 // Find comment in RSS feed.
|
danielebarchiesi@0
|
1775 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
1776 $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1777 $this->drupalGet('rss.xml');
|
danielebarchiesi@0
|
1778 $raw = '<comments>' . url('node/' . $this->node->nid, array('fragment' => 'comments', 'absolute' => TRUE)) . '</comments>';
|
danielebarchiesi@0
|
1779 $this->assertRaw($raw, 'Comments as part of RSS feed.');
|
danielebarchiesi@0
|
1780
|
danielebarchiesi@0
|
1781 // Hide comments from RSS feed and check presence.
|
danielebarchiesi@0
|
1782 $this->node->comment = COMMENT_NODE_HIDDEN;
|
danielebarchiesi@0
|
1783 node_save($this->node);
|
danielebarchiesi@0
|
1784 $this->drupalGet('rss.xml');
|
danielebarchiesi@0
|
1785 $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.');
|
danielebarchiesi@0
|
1786 }
|
danielebarchiesi@0
|
1787 }
|
danielebarchiesi@0
|
1788
|
danielebarchiesi@0
|
1789
|
danielebarchiesi@0
|
1790 /**
|
danielebarchiesi@0
|
1791 * Test to make sure comment content is rebuilt.
|
danielebarchiesi@0
|
1792 */
|
danielebarchiesi@0
|
1793 class CommentContentRebuild extends CommentHelperCase {
|
danielebarchiesi@0
|
1794 public static function getInfo() {
|
danielebarchiesi@0
|
1795 return array(
|
danielebarchiesi@0
|
1796 'name' => 'Comment Rebuild',
|
danielebarchiesi@0
|
1797 'description' => 'Test to make sure the comment content is rebuilt.',
|
danielebarchiesi@0
|
1798 'group' => 'Comment',
|
danielebarchiesi@0
|
1799 );
|
danielebarchiesi@0
|
1800 }
|
danielebarchiesi@0
|
1801
|
danielebarchiesi@0
|
1802 /**
|
danielebarchiesi@0
|
1803 * Test to ensure that the comment's content array is rebuilt for every
|
danielebarchiesi@0
|
1804 * call to comment_view().
|
danielebarchiesi@0
|
1805 */
|
danielebarchiesi@0
|
1806 function testCommentRebuild() {
|
danielebarchiesi@0
|
1807 // Update the comment settings so preview isn't required.
|
danielebarchiesi@0
|
1808 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1809 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1810 $this->setCommentPreview(DRUPAL_OPTIONAL);
|
danielebarchiesi@0
|
1811 $this->drupalLogout();
|
danielebarchiesi@0
|
1812
|
danielebarchiesi@0
|
1813 // Log in as the web user and add the comment.
|
danielebarchiesi@0
|
1814 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
1815 $subject_text = $this->randomName();
|
danielebarchiesi@0
|
1816 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
1817 $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
|
danielebarchiesi@0
|
1818 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
1819 $this->assertTrue($this->commentExists($comment), 'Comment found.');
|
danielebarchiesi@0
|
1820
|
danielebarchiesi@0
|
1821 // Add the property to the content array and then see if it still exists on build.
|
danielebarchiesi@0
|
1822 $comment_loaded->content['test_property'] = array('#value' => $this->randomString());
|
danielebarchiesi@0
|
1823 $built_content = comment_view($comment_loaded, $this->node);
|
danielebarchiesi@0
|
1824
|
danielebarchiesi@0
|
1825 // This means that the content was rebuilt as the added test property no longer exists.
|
danielebarchiesi@0
|
1826 $this->assertFalse(isset($built_content['test_property']), 'Comment content was emptied before being built.');
|
danielebarchiesi@0
|
1827 }
|
danielebarchiesi@0
|
1828 }
|
danielebarchiesi@0
|
1829
|
danielebarchiesi@0
|
1830 /**
|
danielebarchiesi@0
|
1831 * Test comment token replacement in strings.
|
danielebarchiesi@0
|
1832 */
|
danielebarchiesi@0
|
1833 class CommentTokenReplaceTestCase extends CommentHelperCase {
|
danielebarchiesi@0
|
1834 public static function getInfo() {
|
danielebarchiesi@0
|
1835 return array(
|
danielebarchiesi@0
|
1836 'name' => 'Comment token replacement',
|
danielebarchiesi@0
|
1837 'description' => 'Generates text using placeholders for dummy content to check comment token replacement.',
|
danielebarchiesi@0
|
1838 'group' => 'Comment',
|
danielebarchiesi@0
|
1839 );
|
danielebarchiesi@0
|
1840 }
|
danielebarchiesi@0
|
1841
|
danielebarchiesi@0
|
1842 /**
|
danielebarchiesi@0
|
1843 * Creates a comment, then tests the tokens generated from it.
|
danielebarchiesi@0
|
1844 */
|
danielebarchiesi@0
|
1845 function testCommentTokenReplacement() {
|
danielebarchiesi@0
|
1846 global $language;
|
danielebarchiesi@0
|
1847 $url_options = array(
|
danielebarchiesi@0
|
1848 'absolute' => TRUE,
|
danielebarchiesi@0
|
1849 'language' => $language,
|
danielebarchiesi@0
|
1850 );
|
danielebarchiesi@0
|
1851
|
danielebarchiesi@0
|
1852 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
1853
|
danielebarchiesi@0
|
1854 // Set comment variables.
|
danielebarchiesi@0
|
1855 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
1856
|
danielebarchiesi@0
|
1857 // Create a node and a comment.
|
danielebarchiesi@0
|
1858 $node = $this->drupalCreateNode(array('type' => 'article'));
|
danielebarchiesi@0
|
1859 $parent_comment = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
1860
|
danielebarchiesi@0
|
1861 // Post a reply to the comment.
|
danielebarchiesi@0
|
1862 $this->drupalGet('comment/reply/' . $node->nid . '/' . $parent_comment->id);
|
danielebarchiesi@0
|
1863 $child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
1864 $comment = comment_load($child_comment->id);
|
danielebarchiesi@0
|
1865 $comment->homepage = 'http://example.org/';
|
danielebarchiesi@0
|
1866
|
danielebarchiesi@0
|
1867 // Add HTML to ensure that sanitation of some fields tested directly.
|
danielebarchiesi@0
|
1868 $comment->subject = '<blink>Blinking Comment</blink>';
|
danielebarchiesi@0
|
1869 $instance = field_info_instance('comment', 'body', 'comment_body');
|
danielebarchiesi@0
|
1870
|
danielebarchiesi@0
|
1871 // Generate and test sanitized tokens.
|
danielebarchiesi@0
|
1872 $tests = array();
|
danielebarchiesi@0
|
1873 $tests['[comment:cid]'] = $comment->cid;
|
danielebarchiesi@0
|
1874 $tests['[comment:hostname]'] = check_plain($comment->hostname);
|
danielebarchiesi@0
|
1875 $tests['[comment:name]'] = filter_xss($comment->name);
|
danielebarchiesi@0
|
1876 $tests['[comment:mail]'] = check_plain($this->admin_user->mail);
|
danielebarchiesi@0
|
1877 $tests['[comment:homepage]'] = check_url($comment->homepage);
|
danielebarchiesi@0
|
1878 $tests['[comment:title]'] = filter_xss($comment->subject);
|
danielebarchiesi@0
|
1879 $tests['[comment:body]'] = _text_sanitize($instance, LANGUAGE_NONE, $comment->comment_body[LANGUAGE_NONE][0], 'value');
|
danielebarchiesi@0
|
1880 $tests['[comment:url]'] = url('comment/' . $comment->cid, $url_options + array('fragment' => 'comment-' . $comment->cid));
|
danielebarchiesi@0
|
1881 $tests['[comment:edit-url]'] = url('comment/' . $comment->cid . '/edit', $url_options);
|
danielebarchiesi@0
|
1882 $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created, 2, $language->language);
|
danielebarchiesi@0
|
1883 $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed, 2, $language->language);
|
danielebarchiesi@0
|
1884 $tests['[comment:parent:cid]'] = $comment->pid;
|
danielebarchiesi@0
|
1885 $tests['[comment:parent:title]'] = check_plain($parent_comment->subject);
|
danielebarchiesi@0
|
1886 $tests['[comment:node:nid]'] = $comment->nid;
|
danielebarchiesi@0
|
1887 $tests['[comment:node:title]'] = check_plain($node->title);
|
danielebarchiesi@0
|
1888 $tests['[comment:author:uid]'] = $comment->uid;
|
danielebarchiesi@0
|
1889 $tests['[comment:author:name]'] = check_plain($this->admin_user->name);
|
danielebarchiesi@0
|
1890
|
danielebarchiesi@0
|
1891 // Test to make sure that we generated something for each token.
|
danielebarchiesi@0
|
1892 $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
danielebarchiesi@0
|
1893
|
danielebarchiesi@0
|
1894 foreach ($tests as $input => $expected) {
|
danielebarchiesi@0
|
1895 $output = token_replace($input, array('comment' => $comment), array('language' => $language));
|
danielebarchiesi@0
|
1896 $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input)));
|
danielebarchiesi@0
|
1897 }
|
danielebarchiesi@0
|
1898
|
danielebarchiesi@0
|
1899 // Generate and test unsanitized tokens.
|
danielebarchiesi@0
|
1900 $tests['[comment:hostname]'] = $comment->hostname;
|
danielebarchiesi@0
|
1901 $tests['[comment:name]'] = $comment->name;
|
danielebarchiesi@0
|
1902 $tests['[comment:mail]'] = $this->admin_user->mail;
|
danielebarchiesi@0
|
1903 $tests['[comment:homepage]'] = $comment->homepage;
|
danielebarchiesi@0
|
1904 $tests['[comment:title]'] = $comment->subject;
|
danielebarchiesi@0
|
1905 $tests['[comment:body]'] = $comment->comment_body[LANGUAGE_NONE][0]['value'];
|
danielebarchiesi@0
|
1906 $tests['[comment:parent:title]'] = $parent_comment->subject;
|
danielebarchiesi@0
|
1907 $tests['[comment:node:title]'] = $node->title;
|
danielebarchiesi@0
|
1908 $tests['[comment:author:name]'] = $this->admin_user->name;
|
danielebarchiesi@0
|
1909
|
danielebarchiesi@0
|
1910 foreach ($tests as $input => $expected) {
|
danielebarchiesi@0
|
1911 $output = token_replace($input, array('comment' => $comment), array('language' => $language, 'sanitize' => FALSE));
|
danielebarchiesi@0
|
1912 $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
|
danielebarchiesi@0
|
1913 }
|
danielebarchiesi@0
|
1914
|
danielebarchiesi@0
|
1915 // Load node so comment_count gets computed.
|
danielebarchiesi@0
|
1916 $node = node_load($node->nid);
|
danielebarchiesi@0
|
1917
|
danielebarchiesi@0
|
1918 // Generate comment tokens for the node (it has 2 comments, both new).
|
danielebarchiesi@0
|
1919 $tests = array();
|
danielebarchiesi@0
|
1920 $tests['[node:comment-count]'] = 2;
|
danielebarchiesi@0
|
1921 $tests['[node:comment-count-new]'] = 2;
|
danielebarchiesi@0
|
1922
|
danielebarchiesi@0
|
1923 foreach ($tests as $input => $expected) {
|
danielebarchiesi@0
|
1924 $output = token_replace($input, array('node' => $node), array('language' => $language));
|
danielebarchiesi@0
|
1925 $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
|
danielebarchiesi@0
|
1926 }
|
danielebarchiesi@0
|
1927 }
|
danielebarchiesi@0
|
1928 }
|
danielebarchiesi@0
|
1929
|
danielebarchiesi@0
|
1930 /**
|
danielebarchiesi@0
|
1931 * Test actions provided by the comment module.
|
danielebarchiesi@0
|
1932 */
|
danielebarchiesi@0
|
1933 class CommentActionsTestCase extends CommentHelperCase {
|
danielebarchiesi@0
|
1934 public static function getInfo() {
|
danielebarchiesi@0
|
1935 return array(
|
danielebarchiesi@0
|
1936 'name' => 'Comment actions',
|
danielebarchiesi@0
|
1937 'description' => 'Test actions provided by the comment module.',
|
danielebarchiesi@0
|
1938 'group' => 'Comment',
|
danielebarchiesi@0
|
1939 );
|
danielebarchiesi@0
|
1940 }
|
danielebarchiesi@0
|
1941
|
danielebarchiesi@0
|
1942 /**
|
danielebarchiesi@0
|
1943 * Test comment publish and unpublish actions.
|
danielebarchiesi@0
|
1944 */
|
danielebarchiesi@0
|
1945 function testCommentPublishUnpublishActions() {
|
danielebarchiesi@0
|
1946 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
1947 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
1948 $subject = $this->randomName();
|
danielebarchiesi@0
|
1949 $comment = $this->postComment($this->node, $comment_text, $subject);
|
danielebarchiesi@0
|
1950 $comment = comment_load($comment->id);
|
danielebarchiesi@0
|
1951
|
danielebarchiesi@0
|
1952 // Unpublish a comment (direct form: doesn't actually save the comment).
|
danielebarchiesi@0
|
1953 comment_unpublish_action($comment);
|
danielebarchiesi@0
|
1954 $this->assertEqual($comment->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished');
|
danielebarchiesi@0
|
1955 $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), 'Found watchdog message');
|
danielebarchiesi@0
|
1956 $this->clearWatchdog();
|
danielebarchiesi@0
|
1957
|
danielebarchiesi@0
|
1958 // Unpublish a comment (indirect form: modify the comment in the database).
|
danielebarchiesi@0
|
1959 comment_unpublish_action(NULL, array('cid' => $comment->cid));
|
danielebarchiesi@0
|
1960 $this->assertEqual(comment_load($comment->cid)->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished');
|
danielebarchiesi@0
|
1961 $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), 'Found watchdog message');
|
danielebarchiesi@0
|
1962
|
danielebarchiesi@0
|
1963 // Publish a comment (direct form: doesn't actually save the comment).
|
danielebarchiesi@0
|
1964 comment_publish_action($comment);
|
danielebarchiesi@0
|
1965 $this->assertEqual($comment->status, COMMENT_PUBLISHED, 'Comment was published');
|
danielebarchiesi@0
|
1966 $this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), 'Found watchdog message');
|
danielebarchiesi@0
|
1967 $this->clearWatchdog();
|
danielebarchiesi@0
|
1968
|
danielebarchiesi@0
|
1969 // Publish a comment (indirect form: modify the comment in the database).
|
danielebarchiesi@0
|
1970 comment_publish_action(NULL, array('cid' => $comment->cid));
|
danielebarchiesi@0
|
1971 $this->assertEqual(comment_load($comment->cid)->status, COMMENT_PUBLISHED, 'Comment was published');
|
danielebarchiesi@0
|
1972 $this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), 'Found watchdog message');
|
danielebarchiesi@0
|
1973 $this->clearWatchdog();
|
danielebarchiesi@0
|
1974 }
|
danielebarchiesi@0
|
1975
|
danielebarchiesi@0
|
1976 /**
|
danielebarchiesi@0
|
1977 * Verify that a watchdog message has been entered.
|
danielebarchiesi@0
|
1978 *
|
danielebarchiesi@0
|
1979 * @param $watchdog_message
|
danielebarchiesi@0
|
1980 * The watchdog message.
|
danielebarchiesi@0
|
1981 * @param $variables
|
danielebarchiesi@0
|
1982 * The array of variables passed to watchdog().
|
danielebarchiesi@0
|
1983 * @param $message
|
danielebarchiesi@0
|
1984 * The assertion message.
|
danielebarchiesi@0
|
1985 */
|
danielebarchiesi@0
|
1986 function assertWatchdogMessage($watchdog_message, $variables, $message) {
|
danielebarchiesi@0
|
1987 $status = (bool) db_query_range("SELECT 1 FROM {watchdog} WHERE message = :message AND variables = :variables", 0, 1, array(':message' => $watchdog_message, ':variables' => serialize($variables)))->fetchField();
|
danielebarchiesi@0
|
1988 return $this->assert($status, format_string('@message', array('@message' => $message)));
|
danielebarchiesi@0
|
1989 }
|
danielebarchiesi@0
|
1990
|
danielebarchiesi@0
|
1991 /**
|
danielebarchiesi@0
|
1992 * Helper function: clear the watchdog.
|
danielebarchiesi@0
|
1993 */
|
danielebarchiesi@0
|
1994 function clearWatchdog() {
|
danielebarchiesi@0
|
1995 db_truncate('watchdog')->execute();
|
danielebarchiesi@0
|
1996 }
|
danielebarchiesi@0
|
1997 }
|
danielebarchiesi@0
|
1998
|
danielebarchiesi@0
|
1999 /**
|
danielebarchiesi@0
|
2000 * Test fields on comments.
|
danielebarchiesi@0
|
2001 */
|
danielebarchiesi@0
|
2002 class CommentFieldsTest extends CommentHelperCase {
|
danielebarchiesi@0
|
2003 public static function getInfo() {
|
danielebarchiesi@0
|
2004 return array(
|
danielebarchiesi@0
|
2005 'name' => 'Comment fields',
|
danielebarchiesi@0
|
2006 'description' => 'Tests fields on comments.',
|
danielebarchiesi@0
|
2007 'group' => 'Comment',
|
danielebarchiesi@0
|
2008 );
|
danielebarchiesi@0
|
2009 }
|
danielebarchiesi@0
|
2010
|
danielebarchiesi@0
|
2011 /**
|
danielebarchiesi@0
|
2012 * Tests that the default 'comment_body' field is correctly added.
|
danielebarchiesi@0
|
2013 */
|
danielebarchiesi@0
|
2014 function testCommentDefaultFields() {
|
danielebarchiesi@0
|
2015 // Do not make assumptions on default node types created by the test
|
danielebarchiesi@0
|
2016 // installation profile, and create our own.
|
danielebarchiesi@0
|
2017 $this->drupalCreateContentType(array('type' => 'test_node_type'));
|
danielebarchiesi@0
|
2018
|
danielebarchiesi@0
|
2019 // Check that the 'comment_body' field is present on all comment bundles.
|
danielebarchiesi@0
|
2020 $instances = field_info_instances('comment');
|
danielebarchiesi@0
|
2021 foreach (node_type_get_types() as $type_name => $info) {
|
danielebarchiesi@0
|
2022 $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
|
danielebarchiesi@0
|
2023
|
danielebarchiesi@0
|
2024 // Delete the instance along the way.
|
danielebarchiesi@0
|
2025 field_delete_instance($instances['comment_node_' . $type_name]['comment_body']);
|
danielebarchiesi@0
|
2026 }
|
danielebarchiesi@0
|
2027
|
danielebarchiesi@0
|
2028 // Check that the 'comment_body' field is deleted.
|
danielebarchiesi@0
|
2029 $field = field_info_field('comment_body');
|
danielebarchiesi@0
|
2030 $this->assertTrue(empty($field), 'The comment_body field was deleted');
|
danielebarchiesi@0
|
2031
|
danielebarchiesi@0
|
2032 // Create a new content type.
|
danielebarchiesi@0
|
2033 $type_name = 'test_node_type_2';
|
danielebarchiesi@0
|
2034 $this->drupalCreateContentType(array('type' => $type_name));
|
danielebarchiesi@0
|
2035
|
danielebarchiesi@0
|
2036 // Check that the 'comment_body' field exists and has an instance on the
|
danielebarchiesi@0
|
2037 // new comment bundle.
|
danielebarchiesi@0
|
2038 $field = field_info_field('comment_body');
|
danielebarchiesi@0
|
2039 $this->assertTrue($field, 'The comment_body field exists');
|
danielebarchiesi@0
|
2040 $instances = field_info_instances('comment');
|
danielebarchiesi@0
|
2041 $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
|
danielebarchiesi@0
|
2042 }
|
danielebarchiesi@0
|
2043
|
danielebarchiesi@0
|
2044 /**
|
danielebarchiesi@0
|
2045 * Test that comment module works when enabled after a content module.
|
danielebarchiesi@0
|
2046 */
|
danielebarchiesi@0
|
2047 function testCommentEnable() {
|
danielebarchiesi@0
|
2048 // Create a user to do module administration.
|
danielebarchiesi@0
|
2049 $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
|
danielebarchiesi@0
|
2050 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
2051
|
danielebarchiesi@0
|
2052 // Disable the comment module.
|
danielebarchiesi@0
|
2053 $edit = array();
|
danielebarchiesi@0
|
2054 $edit['modules[Core][comment][enable]'] = FALSE;
|
danielebarchiesi@0
|
2055 $this->drupalPost('admin/modules', $edit, t('Save configuration'));
|
danielebarchiesi@0
|
2056 $this->resetAll();
|
danielebarchiesi@0
|
2057 $this->assertFalse(module_exists('comment'), 'Comment module disabled.');
|
danielebarchiesi@0
|
2058
|
danielebarchiesi@0
|
2059 // Enable core content type modules (blog, book, and poll).
|
danielebarchiesi@0
|
2060 $edit = array();
|
danielebarchiesi@0
|
2061 $edit['modules[Core][blog][enable]'] = 'blog';
|
danielebarchiesi@0
|
2062 $edit['modules[Core][book][enable]'] = 'book';
|
danielebarchiesi@0
|
2063 $edit['modules[Core][poll][enable]'] = 'poll';
|
danielebarchiesi@0
|
2064 $this->drupalPost('admin/modules', $edit, t('Save configuration'));
|
danielebarchiesi@0
|
2065 $this->resetAll();
|
danielebarchiesi@0
|
2066
|
danielebarchiesi@0
|
2067 // Now enable the comment module.
|
danielebarchiesi@0
|
2068 $edit = array();
|
danielebarchiesi@0
|
2069 $edit['modules[Core][comment][enable]'] = 'comment';
|
danielebarchiesi@0
|
2070 $this->drupalPost('admin/modules', $edit, t('Save configuration'));
|
danielebarchiesi@0
|
2071 $this->resetAll();
|
danielebarchiesi@0
|
2072 $this->assertTrue(module_exists('comment'), 'Comment module enabled.');
|
danielebarchiesi@0
|
2073
|
danielebarchiesi@0
|
2074 // Create nodes of each type.
|
danielebarchiesi@0
|
2075 $blog_node = $this->drupalCreateNode(array('type' => 'blog'));
|
danielebarchiesi@0
|
2076 $book_node = $this->drupalCreateNode(array('type' => 'book'));
|
danielebarchiesi@0
|
2077 $poll_node = $this->drupalCreateNode(array('type' => 'poll', 'active' => 1, 'runtime' => 0, 'choice' => array(array('chtext' => ''))));
|
danielebarchiesi@0
|
2078
|
danielebarchiesi@0
|
2079 $this->drupalLogout();
|
danielebarchiesi@0
|
2080
|
danielebarchiesi@0
|
2081 // Try to post a comment on each node. A failure will be triggered if the
|
danielebarchiesi@0
|
2082 // comment body is missing on one of these forms, due to postComment()
|
danielebarchiesi@0
|
2083 // asserting that the body is actually posted correctly.
|
danielebarchiesi@0
|
2084 $this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'post comments', 'skip comment approval'));
|
danielebarchiesi@0
|
2085 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2086 $this->postComment($blog_node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
2087 $this->postComment($book_node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
2088 $this->postComment($poll_node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
2089 }
|
danielebarchiesi@0
|
2090
|
danielebarchiesi@0
|
2091 /**
|
danielebarchiesi@0
|
2092 * Test that comment module works correctly with plain text format.
|
danielebarchiesi@0
|
2093 */
|
danielebarchiesi@0
|
2094 function testCommentFormat() {
|
danielebarchiesi@0
|
2095 // Disable text processing for comments.
|
danielebarchiesi@0
|
2096 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
2097 $edit = array('instance[settings][text_processing]' => 0);
|
danielebarchiesi@0
|
2098 $this->drupalPost('admin/structure/types/manage/article/comment/fields/comment_body', $edit, t('Save settings'));
|
danielebarchiesi@0
|
2099
|
danielebarchiesi@0
|
2100 // Post a comment without an explicit subject.
|
danielebarchiesi@0
|
2101 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2102 $edit = array('comment_body[und][0][value]' => $this->randomName(8));
|
danielebarchiesi@0
|
2103 $this->drupalPost('node/' . $this->node->nid, $edit, t('Save'));
|
danielebarchiesi@0
|
2104 }
|
danielebarchiesi@0
|
2105 }
|
danielebarchiesi@0
|
2106
|
danielebarchiesi@0
|
2107 /**
|
danielebarchiesi@0
|
2108 * Tests comment threading.
|
danielebarchiesi@0
|
2109 */
|
danielebarchiesi@0
|
2110 class CommentThreadingTestCase extends CommentHelperCase {
|
danielebarchiesi@0
|
2111 public static function getInfo() {
|
danielebarchiesi@0
|
2112 return array(
|
danielebarchiesi@0
|
2113 'name' => 'Comment Threading',
|
danielebarchiesi@0
|
2114 'description' => 'Test to make sure the comment number increments properly.',
|
danielebarchiesi@0
|
2115 'group' => 'Comment',
|
danielebarchiesi@0
|
2116 );
|
danielebarchiesi@0
|
2117 }
|
danielebarchiesi@0
|
2118
|
danielebarchiesi@0
|
2119 /**
|
danielebarchiesi@0
|
2120 * Tests the comment threading.
|
danielebarchiesi@0
|
2121 */
|
danielebarchiesi@0
|
2122 function testCommentThreading() {
|
danielebarchiesi@0
|
2123 $langcode = LANGUAGE_NONE;
|
danielebarchiesi@0
|
2124 // Set comments to have a subject with preview disabled.
|
danielebarchiesi@0
|
2125 $this->drupalLogin($this->admin_user);
|
danielebarchiesi@0
|
2126 $this->setCommentPreview(DRUPAL_DISABLED);
|
danielebarchiesi@0
|
2127 $this->setCommentForm(TRUE);
|
danielebarchiesi@0
|
2128 $this->setCommentSubject(TRUE);
|
danielebarchiesi@0
|
2129 $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
|
danielebarchiesi@0
|
2130 $this->drupalLogout();
|
danielebarchiesi@0
|
2131
|
danielebarchiesi@0
|
2132 // Create a node.
|
danielebarchiesi@0
|
2133 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2134 $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
|
danielebarchiesi@0
|
2135
|
danielebarchiesi@0
|
2136 // Post comment #1.
|
danielebarchiesi@0
|
2137 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2138 $subject_text = $this->randomName();
|
danielebarchiesi@0
|
2139 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
2140 $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
|
danielebarchiesi@0
|
2141 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
2142 $this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.');
|
danielebarchiesi@0
|
2143 $this->assertEqual($comment_loaded->thread, '01/');
|
danielebarchiesi@0
|
2144
|
danielebarchiesi@0
|
2145 // Reply to comment #1 creating comment #2.
|
danielebarchiesi@0
|
2146 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2147 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
2148 $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
|
danielebarchiesi@0
|
2149 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
2150 $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.');
|
danielebarchiesi@0
|
2151 $this->assertEqual($reply_loaded->thread, '01.00/');
|
danielebarchiesi@0
|
2152
|
danielebarchiesi@0
|
2153 // Reply to comment #2 creating comment #3.
|
danielebarchiesi@0
|
2154 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
|
danielebarchiesi@0
|
2155 $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
2156 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
2157 $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.');
|
danielebarchiesi@0
|
2158 $this->assertEqual($reply_loaded->thread, '01.00.00/');
|
danielebarchiesi@0
|
2159
|
danielebarchiesi@0
|
2160 // Reply to comment #1 creating comment #4.
|
danielebarchiesi@0
|
2161 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2162 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
2163 $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
|
danielebarchiesi@0
|
2164 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
2165 $this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.');
|
danielebarchiesi@0
|
2166 $this->assertEqual($reply_loaded->thread, '01.01/');
|
danielebarchiesi@0
|
2167
|
danielebarchiesi@0
|
2168 // Post comment #2 overall comment #5.
|
danielebarchiesi@0
|
2169 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2170 $subject_text = $this->randomName();
|
danielebarchiesi@0
|
2171 $comment_text = $this->randomName();
|
danielebarchiesi@0
|
2172 $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
|
danielebarchiesi@0
|
2173 $comment_loaded = comment_load($comment->id);
|
danielebarchiesi@0
|
2174 $this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.');
|
danielebarchiesi@0
|
2175 $this->assertEqual($comment_loaded->thread, '02/');
|
danielebarchiesi@0
|
2176
|
danielebarchiesi@0
|
2177 // Reply to comment #5 creating comment #6.
|
danielebarchiesi@0
|
2178 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2179 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
2180 $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
|
danielebarchiesi@0
|
2181 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
2182 $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.');
|
danielebarchiesi@0
|
2183 $this->assertEqual($reply_loaded->thread, '02.00/');
|
danielebarchiesi@0
|
2184
|
danielebarchiesi@0
|
2185 // Reply to comment #6 creating comment #7.
|
danielebarchiesi@0
|
2186 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
|
danielebarchiesi@0
|
2187 $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
|
danielebarchiesi@0
|
2188 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
2189 $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.');
|
danielebarchiesi@0
|
2190 $this->assertEqual($reply_loaded->thread, '02.00.00/');
|
danielebarchiesi@0
|
2191
|
danielebarchiesi@0
|
2192 // Reply to comment #5 creating comment #8.
|
danielebarchiesi@0
|
2193 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2194 $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
|
danielebarchiesi@0
|
2195 $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
|
danielebarchiesi@0
|
2196 $reply_loaded = comment_load($reply->id);
|
danielebarchiesi@0
|
2197 $this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.');
|
danielebarchiesi@0
|
2198 $this->assertEqual($reply_loaded->thread, '02.01/');
|
danielebarchiesi@0
|
2199 }
|
danielebarchiesi@0
|
2200 }
|
danielebarchiesi@0
|
2201
|
danielebarchiesi@0
|
2202 /**
|
danielebarchiesi@0
|
2203 * Tests that comments behave correctly when the node is changed.
|
danielebarchiesi@0
|
2204 */
|
danielebarchiesi@0
|
2205 class CommentNodeChangesTestCase extends CommentHelperCase {
|
danielebarchiesi@0
|
2206
|
danielebarchiesi@0
|
2207 public static function getInfo() {
|
danielebarchiesi@0
|
2208 return array(
|
danielebarchiesi@0
|
2209 'name' => 'Comment deletion on node changes',
|
danielebarchiesi@0
|
2210 'description' => 'Tests that comments behave correctly when the node is changed.',
|
danielebarchiesi@0
|
2211 'group' => 'Comment',
|
danielebarchiesi@0
|
2212 );
|
danielebarchiesi@0
|
2213 }
|
danielebarchiesi@0
|
2214
|
danielebarchiesi@0
|
2215 /**
|
danielebarchiesi@0
|
2216 * Tests that comments are deleted with the node.
|
danielebarchiesi@0
|
2217 */
|
danielebarchiesi@0
|
2218 function testNodeDeletion() {
|
danielebarchiesi@0
|
2219 $this->drupalLogin($this->web_user);
|
danielebarchiesi@0
|
2220 $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
|
danielebarchiesi@0
|
2221 $this->assertTrue(comment_load($comment->id), 'The comment could be loaded.');
|
danielebarchiesi@0
|
2222 node_delete($this->node->nid);
|
danielebarchiesi@0
|
2223 $this->assertFalse(comment_load($comment->id), 'The comment could not be loaded after the node was deleted.');
|
danielebarchiesi@0
|
2224 }
|
danielebarchiesi@0
|
2225 }
|