1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for tracker.module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Defines a base class for testing tracker.module.
|
10
|
*/
|
11
|
class TrackerTest extends DrupalWebTestCase {
|
12
|
|
13
|
/**
|
14
|
* The main user for testing.
|
15
|
*
|
16
|
* @var object
|
17
|
*/
|
18
|
protected $user;
|
19
|
|
20
|
/**
|
21
|
* A second user that will 'create' comments and nodes.
|
22
|
*
|
23
|
* @var object
|
24
|
*/
|
25
|
protected $other_user;
|
26
|
|
27
|
public static function getInfo() {
|
28
|
return array(
|
29
|
'name' => 'Tracker',
|
30
|
'description' => 'Create and delete nodes and check for their display in the tracker listings.',
|
31
|
'group' => 'Tracker'
|
32
|
);
|
33
|
}
|
34
|
|
35
|
function setUp() {
|
36
|
parent::setUp('comment', 'tracker');
|
37
|
|
38
|
$permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval');
|
39
|
$this->user = $this->drupalCreateUser($permissions);
|
40
|
$this->other_user = $this->drupalCreateUser($permissions);
|
41
|
|
42
|
// Make node preview optional.
|
43
|
variable_set('comment_preview_page', 0);
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Tests for the presence of nodes on the global tracker listing.
|
48
|
*/
|
49
|
function testTrackerAll() {
|
50
|
$this->drupalLogin($this->user);
|
51
|
|
52
|
$unpublished = $this->drupalCreateNode(array(
|
53
|
'title' => $this->randomName(8),
|
54
|
'status' => 0,
|
55
|
));
|
56
|
$published = $this->drupalCreateNode(array(
|
57
|
'title' => $this->randomName(8),
|
58
|
'status' => 1,
|
59
|
));
|
60
|
|
61
|
$this->drupalGet('tracker');
|
62
|
$this->assertNoText($unpublished->title, 'Unpublished node do not show up in the tracker listing.');
|
63
|
$this->assertText($published->title, 'Published node show up in the tracker listing.');
|
64
|
$this->assertLink(t('My recent content'), 0, 'User tab shows up on the global tracker page.');
|
65
|
|
66
|
// Delete a node and ensure it no longer appears on the tracker.
|
67
|
node_delete($published->nid);
|
68
|
$this->drupalGet('tracker');
|
69
|
$this->assertNoText($published->title, 'Deleted node do not show up in the tracker listing.');
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Tests for the presence of nodes on a user's tracker listing.
|
74
|
*/
|
75
|
function testTrackerUser() {
|
76
|
$this->drupalLogin($this->user);
|
77
|
|
78
|
$unpublished = $this->drupalCreateNode(array(
|
79
|
'title' => $this->randomName(8),
|
80
|
'uid' => $this->user->uid,
|
81
|
'status' => 0,
|
82
|
));
|
83
|
$my_published = $this->drupalCreateNode(array(
|
84
|
'title' => $this->randomName(8),
|
85
|
'uid' => $this->user->uid,
|
86
|
'status' => 1,
|
87
|
));
|
88
|
$other_published_no_comment = $this->drupalCreateNode(array(
|
89
|
'title' => $this->randomName(8),
|
90
|
'uid' => $this->other_user->uid,
|
91
|
'status' => 1,
|
92
|
));
|
93
|
$other_published_my_comment = $this->drupalCreateNode(array(
|
94
|
'title' => $this->randomName(8),
|
95
|
'uid' => $this->other_user->uid,
|
96
|
'status' => 1,
|
97
|
));
|
98
|
$comment = array(
|
99
|
'subject' => $this->randomName(),
|
100
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
101
|
);
|
102
|
$this->drupalPost('comment/reply/' . $other_published_my_comment->nid, $comment, t('Save'));
|
103
|
|
104
|
$this->drupalGet('user/' . $this->user->uid . '/track');
|
105
|
$this->assertNoText($unpublished->title, "Unpublished nodes do not show up in the users's tracker listing.");
|
106
|
$this->assertText($my_published->title, "Published nodes show up in the user's tracker listing.");
|
107
|
$this->assertNoText($other_published_no_comment->title, "Other user's nodes do not show up in the user's tracker listing.");
|
108
|
$this->assertText($other_published_my_comment->title, "Nodes that the user has commented on appear in the user's tracker listing.");
|
109
|
|
110
|
// Verify that unpublished comments are removed from the tracker.
|
111
|
$admin_user = $this->drupalCreateUser(array('administer comments', 'access user profiles'));
|
112
|
$this->drupalLogin($admin_user);
|
113
|
$this->drupalPost('comment/1/edit', array('status' => COMMENT_NOT_PUBLISHED), t('Save'));
|
114
|
$this->drupalGet('user/' . $this->user->uid . '/track');
|
115
|
$this->assertNoText($other_published_my_comment->title, 'Unpublished comments are not counted on the tracker listing.');
|
116
|
}
|
117
|
|
118
|
/**
|
119
|
* Tests for the presence of the "new" flag for nodes.
|
120
|
*/
|
121
|
function testTrackerNewNodes() {
|
122
|
$this->drupalLogin($this->user);
|
123
|
|
124
|
$edit = array(
|
125
|
'title' => $this->randomName(8),
|
126
|
);
|
127
|
|
128
|
$node = $this->drupalCreateNode($edit);
|
129
|
$title = $edit['title'];
|
130
|
$this->drupalGet('tracker');
|
131
|
$this->assertPattern('/' . $title . '.*new/', 'New nodes are flagged as such in the tracker listing.');
|
132
|
|
133
|
$this->drupalGet('node/' . $node->nid);
|
134
|
$this->drupalGet('tracker');
|
135
|
$this->assertNoPattern('/' . $title . '.*new/', 'Visited nodes are not flagged as new.');
|
136
|
|
137
|
$this->drupalLogin($this->other_user);
|
138
|
$this->drupalGet('tracker');
|
139
|
$this->assertPattern('/' . $title . '.*new/', 'For another user, new nodes are flagged as such in the tracker listing.');
|
140
|
|
141
|
$this->drupalGet('node/' . $node->nid);
|
142
|
$this->drupalGet('tracker');
|
143
|
$this->assertNoPattern('/' . $title . '.*new/', 'For another user, visited nodes are not flagged as new.');
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* Tests for comment counters on the tracker listing.
|
148
|
*/
|
149
|
function testTrackerNewComments() {
|
150
|
$this->drupalLogin($this->user);
|
151
|
|
152
|
$node = $this->drupalCreateNode(array(
|
153
|
'comment' => 2,
|
154
|
'title' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
|
155
|
));
|
156
|
|
157
|
// Add a comment to the page.
|
158
|
$comment = array(
|
159
|
'subject' => $this->randomName(),
|
160
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
161
|
);
|
162
|
// The new comment is automatically viewed by the current user.
|
163
|
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
|
164
|
|
165
|
$this->drupalLogin($this->other_user);
|
166
|
$this->drupalGet('tracker');
|
167
|
$this->assertText('1 new', 'New comments are counted on the tracker listing pages.');
|
168
|
$this->drupalGet('node/' . $node->nid);
|
169
|
|
170
|
// Add another comment as other_user.
|
171
|
$comment = array(
|
172
|
'subject' => $this->randomName(),
|
173
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
174
|
);
|
175
|
// If the comment is posted in the same second as the last one then Drupal
|
176
|
// can't tell the difference, so we wait one second here.
|
177
|
sleep(1);
|
178
|
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
|
179
|
|
180
|
$this->drupalLogin($this->user);
|
181
|
$this->drupalGet('tracker');
|
182
|
$this->assertText('1 new', 'New comments are counted on the tracker listing pages.');
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Tests for ordering on a users tracker listing when comments are posted.
|
187
|
*/
|
188
|
function testTrackerOrderingNewComments() {
|
189
|
$this->drupalLogin($this->user);
|
190
|
|
191
|
$node_one = $this->drupalCreateNode(array(
|
192
|
'title' => $this->randomName(8),
|
193
|
));
|
194
|
|
195
|
$node_two = $this->drupalCreateNode(array(
|
196
|
'title' => $this->randomName(8),
|
197
|
));
|
198
|
|
199
|
// Now get other_user to track these pieces of content.
|
200
|
$this->drupalLogin($this->other_user);
|
201
|
|
202
|
// Add a comment to the first page.
|
203
|
$comment = array(
|
204
|
'subject' => $this->randomName(),
|
205
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
206
|
);
|
207
|
$this->drupalPost('comment/reply/' . $node_one->nid, $comment, t('Save'));
|
208
|
|
209
|
// If the comment is posted in the same second as the last one then Drupal
|
210
|
// can't tell the difference, so we wait one second here.
|
211
|
sleep(1);
|
212
|
|
213
|
// Add a comment to the second page.
|
214
|
$comment = array(
|
215
|
'subject' => $this->randomName(),
|
216
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
217
|
);
|
218
|
$this->drupalPost('comment/reply/' . $node_two->nid, $comment, t('Save'));
|
219
|
|
220
|
// We should at this point have in our tracker for other_user:
|
221
|
// 1. node_two
|
222
|
// 2. node_one
|
223
|
// Because that's the reverse order of the posted comments.
|
224
|
|
225
|
// Now we're going to post a comment to node_one which should jump it to the
|
226
|
// top of the list.
|
227
|
|
228
|
$this->drupalLogin($this->user);
|
229
|
// If the comment is posted in the same second as the last one then Drupal
|
230
|
// can't tell the difference, so we wait one second here.
|
231
|
sleep(1);
|
232
|
|
233
|
// Add a comment to the second page.
|
234
|
$comment = array(
|
235
|
'subject' => $this->randomName(),
|
236
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
237
|
);
|
238
|
$this->drupalPost('comment/reply/' . $node_one->nid, $comment, t('Save'));
|
239
|
|
240
|
// Switch back to the other_user and assert that the order has swapped.
|
241
|
$this->drupalLogin($this->other_user);
|
242
|
$this->drupalGet('user/' . $this->other_user->uid . '/track');
|
243
|
// This is a cheeky way of asserting that the nodes are in the right order
|
244
|
// on the tracker page.
|
245
|
// It's almost certainly too brittle.
|
246
|
$pattern = '/' . preg_quote($node_one->title) . '.+' . preg_quote($node_two->title) . '/s';
|
247
|
$this->verbose($pattern);
|
248
|
$this->assertPattern($pattern, 'Most recently commented on node appears at the top of tracker');
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* Tests that existing nodes are indexed by cron.
|
253
|
*/
|
254
|
function testTrackerCronIndexing() {
|
255
|
$this->drupalLogin($this->user);
|
256
|
|
257
|
// Create 3 nodes.
|
258
|
$edits = array();
|
259
|
$nodes = array();
|
260
|
for ($i = 1; $i <= 3; $i++) {
|
261
|
$edits[$i] = array(
|
262
|
'comment' => 2,
|
263
|
'title' => $this->randomName(),
|
264
|
);
|
265
|
$nodes[$i] = $this->drupalCreateNode($edits[$i]);
|
266
|
}
|
267
|
|
268
|
// Add a comment to the last node as other user.
|
269
|
$this->drupalLogin($this->other_user);
|
270
|
$comment = array(
|
271
|
'subject' => $this->randomName(),
|
272
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
|
273
|
);
|
274
|
$this->drupalPost('comment/reply/' . $nodes[3]->nid, $comment, t('Save'));
|
275
|
|
276
|
// Start indexing backwards from node 3.
|
277
|
variable_set('tracker_index_nid', 3);
|
278
|
|
279
|
// Clear the current tracker tables and rebuild them.
|
280
|
db_delete('tracker_node')
|
281
|
->execute();
|
282
|
db_delete('tracker_user')
|
283
|
->execute();
|
284
|
tracker_cron();
|
285
|
|
286
|
$this->drupalLogin($this->user);
|
287
|
|
288
|
// Fetch the user's tracker.
|
289
|
$this->drupalGet('tracker/' . $this->user->uid);
|
290
|
|
291
|
// Assert that all node titles are displayed.
|
292
|
foreach ($nodes as $i => $node) {
|
293
|
$this->assertText($node->title, format_string('Node @i is displayed on the tracker listing pages.', array('@i' => $i)));
|
294
|
}
|
295
|
$this->assertText('1 new', 'New comment is counted on the tracker listing pages.');
|
296
|
$this->assertText('updated', 'Node is listed as updated');
|
297
|
|
298
|
// Fetch the site-wide tracker.
|
299
|
$this->drupalGet('tracker');
|
300
|
|
301
|
// Assert that all node titles are displayed.
|
302
|
foreach ($nodes as $i => $node) {
|
303
|
$this->assertText($node->title, format_string('Node @i is displayed on the tracker listing pages.', array('@i' => $i)));
|
304
|
}
|
305
|
$this->assertText('1 new', 'New comment is counted on the tracker listing pages.');
|
306
|
}
|
307
|
|
308
|
/**
|
309
|
* Tests that publish/unpublish works at admin/content/node.
|
310
|
*/
|
311
|
function testTrackerAdminUnpublish() {
|
312
|
$admin_user = $this->drupalCreateUser(array('access content overview', 'administer nodes', 'bypass node access'));
|
313
|
$this->drupalLogin($admin_user);
|
314
|
|
315
|
$node = $this->drupalCreateNode(array(
|
316
|
'comment' => 2,
|
317
|
'title' => $this->randomName(),
|
318
|
));
|
319
|
|
320
|
// Assert that the node is displayed.
|
321
|
$this->drupalGet('tracker');
|
322
|
$this->assertText($node->title, 'Node is displayed on the tracker listing pages.');
|
323
|
|
324
|
// Unpublish the node and ensure that it's no longer displayed.
|
325
|
$edit = array(
|
326
|
'operation' => 'unpublish',
|
327
|
'nodes[' . $node->nid . ']' => $node->nid,
|
328
|
);
|
329
|
$this->drupalPost('admin/content', $edit, t('Update'));
|
330
|
|
331
|
$this->drupalGet('tracker');
|
332
|
$this->assertText(t('No content available.'), 'Node is displayed on the tracker listing pages.');
|
333
|
}
|
334
|
}
|