1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains tests for the privatemsg_filter module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Test filters, tags and inbox/sent handling.
|
10 |
|
|
*/
|
11 |
|
|
class PrivatemsgFilterTestCase extends PrivatemsgBaseTestCase {
|
12 |
|
|
/**
|
13 |
|
|
* Implements getInfo().
|
14 |
|
|
*/
|
15 |
|
|
public static function getInfo() {
|
16 |
|
|
return array(
|
17 |
|
|
'name' => t('Privatemsg Filter functionality.'),
|
18 |
|
|
'description' => t('Test filters, tags and inbox/sent handling'),
|
19 |
|
|
'group' => t('Privatemsg'),
|
20 |
|
|
);
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Implements setUp().
|
25 |
|
|
*/
|
26 |
|
|
function setUp() {
|
27 |
|
|
parent::setUp('privatemsg', 'privatemsg_filter');
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* Test correct handling of read all permissions.
|
32 |
|
|
*/
|
33 |
|
|
function testInboxSentHandling() {
|
34 |
|
|
$author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg'));
|
35 |
|
|
$recipient = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
36 |
|
|
|
37 |
|
|
// Create new message.
|
38 |
|
|
$edit = array(
|
39 |
|
|
'recipient' => $recipient->name,
|
40 |
|
|
'subject' => $this->randomName(20),
|
41 |
|
|
'body[value]' => $this->randomName(100),
|
42 |
|
|
);
|
43 |
|
|
$this->drupalLogin($author);
|
44 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
45 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), t('Message sent confirmation displayed'));
|
46 |
|
|
|
47 |
|
|
// Validate that the message is not displayed in the inbox of the author
|
48 |
|
|
// but in the sent list.
|
49 |
|
|
$this->drupalGet('messages');
|
50 |
|
|
$this->assertNoText($edit['subject'], t('Thread not displayed in inbox for author.'));
|
51 |
|
|
$this->drupalGet('messages/sent');
|
52 |
|
|
$this->assertText($edit['subject'], t('Thread displayed in "Sent messages" for author.'));
|
53 |
|
|
$this->drupalGet('messages/list');
|
54 |
|
|
$this->assertText($edit['subject'], t('Thread displayed in "All messages" for author.'));
|
55 |
|
|
|
56 |
|
|
// Write a reply as recipient.
|
57 |
|
|
$this->drupalLogin($recipient);
|
58 |
|
|
$this->drupalGet('messages');
|
59 |
|
|
$this->assertText($edit['subject'], t('Thread displayed in inbox for recipient.'));
|
60 |
|
|
$this->drupalGet('messages/sent');
|
61 |
|
|
$this->assertNoText($edit['subject'], t('Thread not displayed in "Sent messages" for recipient.'));
|
62 |
|
|
$this->drupalGet('messages/list');
|
63 |
|
|
$this->assertText($edit['subject'], t('Thread displayed in "All messages." for recipient.'));
|
64 |
|
|
|
65 |
|
|
// Navigate to the new message.
|
66 |
|
|
$this->clickLink($edit['subject']);
|
67 |
|
|
$response = array(
|
68 |
|
|
'body[value]' => $this->randomName(100),
|
69 |
|
|
);
|
70 |
|
|
$this->drupalPost(NULL, $response, t('Send message'));
|
71 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $author->name)), t('Message sent confirmation displayed'));
|
72 |
|
|
|
73 |
|
|
$this->drupalGet('messages/sent');
|
74 |
|
|
$this->assertText($edit['subject'], t('Thread displayed in "Sent messages" for recipient.'));
|
75 |
|
|
|
76 |
|
|
$this->drupalLogin($author);
|
77 |
|
|
$this->drupalGet('messages');
|
78 |
|
|
$this->assertText($edit['subject'], t('Thread displayed in inbox for author.'));
|
79 |
|
|
|
80 |
|
|
// Test for bug http://drupal.org/node/617648
|
81 |
|
|
// Delete all messages for author.
|
82 |
|
|
$delete = array(
|
83 |
|
|
'list[1]' => 1,
|
84 |
|
|
);
|
85 |
|
|
$this->drupalPost(NULL, $delete, t('Delete'));
|
86 |
|
|
$this->assertNoText($edit['subject'], t('Thread has been deleted for author.'));
|
87 |
|
|
|
88 |
|
|
// Write a reply as recipient.
|
89 |
|
|
$this->drupalLogin($recipient);
|
90 |
|
|
$this->drupalGet('messages');
|
91 |
|
|
|
92 |
|
|
// Navigate to the new message.
|
93 |
|
|
$this->clickLink($edit['subject']);
|
94 |
|
|
$response = array(
|
95 |
|
|
'body[value]' => $this->randomName(100),
|
96 |
|
|
);
|
97 |
|
|
$this->drupalPost(NULL, $response, t('Send message'));
|
98 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $author->name)), t('Message sent confirmation displayed'));
|
99 |
|
|
|
100 |
|
|
// Check if thread is visible again for author.
|
101 |
|
|
$this->drupalLogin($author);
|
102 |
|
|
$this->drupalGet('messages');
|
103 |
|
|
$this->assertText($edit['subject'], t('Thread displayed again in inbox for author.'));
|
104 |
|
|
|
105 |
|
|
// Test archiving of messages.
|
106 |
|
|
// Delete all messages for author.
|
107 |
|
|
$archive = array(
|
108 |
|
|
'list[1]' => 1,
|
109 |
|
|
'operation' => 'archive',
|
110 |
|
|
);
|
111 |
|
|
$this->drupalPost(NULL, $archive, t('Execute'));
|
112 |
|
|
$this->assertText(t('The messages have been archived.'), t('Confirmation message displayed'));
|
113 |
|
|
$this->assertNoText($edit['subject'], t('Thread has been removed from inbox.'));
|
114 |
|
|
|
115 |
|
|
$this->drupalGet('messages/list');
|
116 |
|
|
$this->assertText($edit['subject'], t('Thread still displayed in "All messages" list.'));
|
117 |
|
|
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
/**
|
122 |
|
|
* Test filters, tags and inbox/sent handling.
|
123 |
|
|
*/
|
124 |
|
|
class PrivatemsgTagsTestCase extends PrivatemsgBaseTestCase {
|
125 |
|
|
/**
|
126 |
|
|
* Implements getInfo().
|
127 |
|
|
*/
|
128 |
|
|
public static function getInfo() {
|
129 |
|
|
return array(
|
130 |
|
|
'name' => t('Privatemsg Tags functionality.'),
|
131 |
|
|
'description' => t('Test Privatemsg tags use and administration functionality.'),
|
132 |
|
|
'group' => t('Privatemsg'),
|
133 |
|
|
);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
/**
|
137 |
|
|
* Implements setUp().
|
138 |
|
|
*/
|
139 |
|
|
function setUp() {
|
140 |
|
|
parent::setUp('privatemsg', 'privatemsg_filter');
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
/**
|
144 |
|
|
* Create and update tags on a single thread.
|
145 |
|
|
*/
|
146 |
|
|
function testFilterFormSingleThread() {
|
147 |
|
|
$webuser = $this->drupalCreateuser(array('read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags'));
|
148 |
|
|
|
149 |
|
|
// Create a new thread through the api.
|
150 |
|
|
$response = privatemsg_new_thread(array($webuser), $this->randomName(10), $this->randomName(20), array('author' => $webuser));
|
151 |
|
|
$thread_id = $response['message']->thread_id;
|
152 |
|
|
|
153 |
|
|
$tags = array($this->randomName(), $this->randomName(), $this->randomName(), $this->randomName());
|
154 |
|
|
$edit = array(
|
155 |
|
|
'tags' => $tags[0] . ', ' . $tags[1],
|
156 |
|
|
);
|
157 |
|
|
$this->drupalLogin($webuser);
|
158 |
|
|
$this->drupalGet('messages/view/' . $thread_id);
|
159 |
|
|
$this->clickLink(t('Tag this conversation'));
|
160 |
|
|
$this->drupalPost(NULL, $edit, t('Tag this conversation'));
|
161 |
|
|
$this->assertText($tags[0], t('Found message tag'));
|
162 |
|
|
$this->assertText($tags[1], t('Found message tag'));
|
163 |
|
|
|
164 |
|
|
// Create a another thread through the api.
|
165 |
|
|
$response = privatemsg_new_thread(array($webuser), $this->randomName(10), $this->randomName(20), array('author' => $webuser));
|
166 |
|
|
$thread_id = $response['message']->thread_id;
|
167 |
|
|
|
168 |
|
|
$edit = array(
|
169 |
|
|
'tags' => $tags[1] . ', ' . $tags[2],
|
170 |
|
|
);
|
171 |
|
|
$this->drupalGet('messages/view/' . $thread_id);
|
172 |
|
|
$this->clickLink(t('Tag this conversation'));
|
173 |
|
|
$this->drupalPost(NULL, $edit, t('Tag this conversation'));
|
174 |
|
|
$this->assertText($tags[1], t('Found message tag'));
|
175 |
|
|
$this->assertText($tags[2], t('Found message tag'));
|
176 |
|
|
|
177 |
|
|
// Change tags.
|
178 |
|
|
$edit = array(
|
179 |
|
|
'tags' => $tags[0],
|
180 |
|
|
);
|
181 |
|
|
$this->drupalGet('messages/view/' . $thread_id);
|
182 |
|
|
$this->clickLink(t('(modify tags)'));
|
183 |
|
|
$this->drupalPost(NULL, $edit, t('Tag this conversation'));
|
184 |
|
|
$this->assertText($tags[0], t('Found message tag'));
|
185 |
|
|
$this->assertNoText($tags[1], t('Tag has been removed.'));
|
186 |
|
|
$this->assertNoText($tags[2], t('Tag has been removed.'));
|
187 |
|
|
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
function testTagsAdministration() {
|
191 |
|
|
// Create users.
|
192 |
|
|
$admin = $this->drupalCreateuser(array('administer privatemsg settings', 'read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags'));
|
193 |
|
|
$webuser = $this->drupalCreateuser(array('read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags'));
|
194 |
|
|
|
195 |
|
|
// Prepare data.
|
196 |
|
|
$private = array(
|
197 |
|
|
'tag' => $this->randomName(10),
|
198 |
|
|
'public' => FALSE,
|
199 |
|
|
);
|
200 |
|
|
$public = array(
|
201 |
|
|
'tag' => $this->randomName(10),
|
202 |
|
|
'public' => 1,
|
203 |
|
|
);
|
204 |
|
|
$to_edit = array(
|
205 |
|
|
'tag' => $this->randomName(10),
|
206 |
|
|
'public' => 1,
|
207 |
|
|
);
|
208 |
|
|
$edited_tag = array(
|
209 |
|
|
'tag' => $this->randomName(10),
|
210 |
|
|
'public' => FALSE,
|
211 |
|
|
);
|
212 |
|
|
$duplicate = $private;
|
213 |
|
|
|
214 |
|
|
$this->drupalLogin($admin);
|
215 |
|
|
|
216 |
|
|
// Check that the empty message is displayed.
|
217 |
|
|
$this->drupalGet('admin/config/messaging/privatemsg/tags/list');
|
218 |
|
|
$this->assertText(t('No tags available.'), t('No tags exist yet.'));
|
219 |
|
|
|
220 |
|
|
// Create tags.
|
221 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/tags/add', $private, t('Create tag'));
|
222 |
|
|
$this->assertText(t('Tag created.'));
|
223 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/tags/add', $public, t('Create tag'));
|
224 |
|
|
$this->assertText(t('Tag created.'));
|
225 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/tags/add', $to_edit, t('Create tag'));
|
226 |
|
|
$this->assertText(t('Tag created.'));
|
227 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/tags/add', $duplicate, t('Create tag'));
|
228 |
|
|
$this->assertText(t('Tag already exists, choose a different name.'));
|
229 |
|
|
|
230 |
|
|
// Verify that all tags are displayed.
|
231 |
|
|
$this->drupalGet('admin/config/messaging/privatemsg/tags/list');
|
232 |
|
|
foreach (array($private, $public, $to_edit) as $tag) {
|
233 |
|
|
$this->assertText($tag['tag'], t('Tag %tag displayed', array('%tag' => $tag['tag'])));
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
// Verfiy private/public flag.
|
237 |
|
|
$rows = $this->xpath('//table/tbody/tr');
|
238 |
|
|
foreach ($rows as $row) {
|
239 |
|
|
// Index 0 is tag name.
|
240 |
|
|
if ((string)$row->td[0] == $private['tag']) {
|
241 |
|
|
// Index 2 is Yes/- flag indicator.
|
242 |
|
|
$this->assertEqual((string)$row->td[2], '-', t('Private tag does not have public flag.'));
|
243 |
|
|
}
|
244 |
|
|
else {
|
245 |
|
|
$this->assertEqual((string)$row->td[2], t('Yes'), t('Public tag does have public flag.'));
|
246 |
|
|
}
|
247 |
|
|
// Extract edit/delete url. Only the part starting with admin/ is needed.
|
248 |
|
|
if ((string)$row->td[0] == $to_edit['tag']) {
|
249 |
|
|
$edit_url = substr($row->td[3]->a[0]['href'], strpos($row->td[3]->a[0]['href'], 'admin/'));
|
250 |
|
|
}
|
251 |
|
|
if ((string)$row->td[0] == $public['tag']) {
|
252 |
|
|
$delete_url = drupal_substr($row->td[3]->a[1]['href'], strpos($row->td[3]->a[1]['href'], 'admin/'));
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
// Edit Tag.
|
257 |
|
|
$this->drupalGet($edit_url);
|
258 |
|
|
$this->assertTitle(t('Edit @tag | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'), '@tag' => $to_edit['tag'])), t('Correct title for @tag is set.', array('@tag' => $to_edit['tag'])));
|
259 |
|
|
|
260 |
|
|
// With duplicate data.
|
261 |
|
|
$this->drupalPost(NULL, $duplicate, t('Save tag'));
|
262 |
|
|
$this->assertText(t('Tag already exists, choose a different name.'));
|
263 |
|
|
|
264 |
|
|
// With valid data.
|
265 |
|
|
$this->drupalPost(NULL, $edited_tag, t('Save tag'));
|
266 |
|
|
$this->assertText(t('Tag updated.'), t('Tag has been updated'));
|
267 |
|
|
|
268 |
|
|
// Verify edited tag.
|
269 |
|
|
$this->assertNoText($to_edit['tag'], t('Old tag name not found anymore.'));
|
270 |
|
|
$this->assertText($edited_tag['tag'], t('Tag has been renamed.'));
|
271 |
|
|
$rows = $this->xpath('//table/tbody/tr');
|
272 |
|
|
foreach ($rows as $row) {
|
273 |
|
|
// The new tag name should exist and the public flag should be set to false.
|
274 |
|
|
if ((string)$row->td[0] == $edited_tag['tag']) {
|
275 |
|
|
$this->assertEqual((string)$row->td[2], '-', t('Edited tag does not have public flag.'));
|
276 |
|
|
}
|
277 |
|
|
}
|
278 |
|
|
|
279 |
|
|
// Delete tag.
|
280 |
|
|
$this->drupalPost($delete_url, array(), t('Delete'));
|
281 |
|
|
$this->assertText(t('Tag has been deleted'), t('Tag has been deleted'));
|
282 |
|
|
$this->assertNoText($public['tag'], t('Deleted tag is not displayed anymore.'));
|
283 |
|
|
}
|
284 |
|
|
|
285 |
|
|
/**
|
286 |
|
|
* Tests if the tagging feature works when a user doesn't have the filter
|
287 |
|
|
* permission.
|
288 |
|
|
*/
|
289 |
|
|
function testOnlyTaggingPermission() {
|
290 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
291 |
|
|
$webuser = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'tag private messages', 'create private message tags'));
|
292 |
|
|
|
293 |
|
|
// Display tag column in thread list.
|
294 |
|
|
$this->drupalLogin($admin);
|
295 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg', array('privatemsg_display_fields[tags]' => 'tags'), t('Save configuration'));
|
296 |
|
|
|
297 |
|
|
// Create two threads through the API.
|
298 |
|
|
$response = privatemsg_new_thread(array($webuser), $subject1 = $this->randomName(10), $this->randomName(20), array('author' => $admin));
|
299 |
|
|
$thread_id1 = $response['message']->thread_id;
|
300 |
|
|
|
301 |
|
|
$response = privatemsg_new_thread(array($webuser), $subject2 = $this->randomName(10), $this->randomName(20), array('author' => $admin));
|
302 |
|
|
$thread_id2 = $response['message']->thread_id;
|
303 |
|
|
|
304 |
|
|
// Log in and check that both messages are visible.
|
305 |
|
|
$this->drupalLogin($webuser);
|
306 |
|
|
$this->drupalGet('messages');
|
307 |
|
|
$this->assertText($subject1, t('Message is displayed.'));
|
308 |
|
|
$this->assertText($subject2, t('Message is displayed.'));
|
309 |
|
|
|
310 |
|
|
// Tag first thread.
|
311 |
|
|
$tag = array(
|
312 |
|
|
'tag-add' => $this->randomName(5),
|
313 |
|
|
'list[' . $thread_id1 . ']' => $thread_id1,
|
314 |
|
|
);
|
315 |
|
|
$this->drupalPost(NULL, $tag, t('Apply Tag'));
|
316 |
|
|
|
317 |
|
|
// Filter by tag, verify that only the first thread is displayed, an
|
318 |
|
|
// informal message and no filter form.
|
319 |
|
|
$this->clickLink($tag['tag-add']);
|
320 |
|
|
$this->assertText(t('Messages tagged with @tags are currently displayed. Click here to remove this filter.', array('@tags' => $tag['tag-add'])), t('Tag filter message displayed.'));
|
321 |
|
|
$this->assertNoText(t('Filter messages'));
|
322 |
|
|
$this->assertText($subject1, t('First thread displayed.'));
|
323 |
|
|
$this->assertNoText($subject2, t('Second thread not displayed.'));
|
324 |
|
|
|
325 |
|
|
// Check paging, set threads per page to 1.
|
326 |
|
|
variable_set('privatemsg_per_page', 1);
|
327 |
|
|
|
328 |
|
|
// Go the second page, only the second thread should be visible there.
|
329 |
|
|
$this->drupalGet('messages');
|
330 |
|
|
$this->clickLink('2');
|
331 |
|
|
$this->assertNoText($subject1, t('First thread not displayed.'));
|
332 |
|
|
$this->assertText($subject2, t('Second thread displayed.'));
|
333 |
|
|
|
334 |
|
|
// Only the first thread should be visible on the
|
335 |
|
|
// first page.
|
336 |
|
|
$this->clickLink('1');
|
337 |
|
|
$this->assertText($subject1, t('First thread displayed.'));
|
338 |
|
|
$this->assertNoText($subject2, t('Second thread not displayed.'));
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
// Now, filter by tag (which should be visible on this page) and verify
|
342 |
|
|
// that there is no pager shown.
|
343 |
|
|
$this->clickLink($tag['tag-add']);
|
344 |
|
|
$this->assertText(t('Messages tagged with @tags are currently displayed. Click here to remove this filter.', array('@tags' => $tag['tag-add'])), t('Tag filter message displayed.'));
|
345 |
|
|
$this->assertNoText(t('Filter messages'));
|
346 |
|
|
$this->assertText($subject1, t('First thread displayed.'));
|
347 |
|
|
$this->assertNoText($subject2, t('Second thread not displayed.'));
|
348 |
|
|
$this->assertNoLink('2');
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
function testInboxTagging() {
|
352 |
|
|
$webuser = $this->drupalCreateuser(array('read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags'));
|
353 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings'));
|
354 |
|
|
|
355 |
|
|
// Display tag column in thread list.
|
356 |
|
|
$this->drupalLogin($admin);
|
357 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg', array('privatemsg_display_fields[tags]' => 'tags'), t('Save configuration'));
|
358 |
|
|
|
359 |
|
|
// Create a new thread through the api.
|
360 |
|
|
$response = privatemsg_new_thread(array($webuser), $subject1 = $this->randomName(10), $this->randomName(20), array('author' => $webuser));
|
361 |
|
|
$thread_id = $response['message']->thread_id;
|
362 |
|
|
|
363 |
|
|
$tag1 = $this->randomName();
|
364 |
|
|
$tag2 = $this->randomName();
|
365 |
|
|
$edit = array(
|
366 |
|
|
'tags' => $tag1 . ', ' . $tag2,
|
367 |
|
|
);
|
368 |
|
|
$this->drupalLogin($webuser);
|
369 |
|
|
$this->drupalGet('messages/view/' . $thread_id);
|
370 |
|
|
$this->clickLink(t('Tag this conversation'));
|
371 |
|
|
$this->drupalPost(NULL, $edit, t('Tag this conversation'));
|
372 |
|
|
$this->assertText($tag1, t('Found message tag'));
|
373 |
|
|
$this->assertText($tag2, t('Found message tag'));
|
374 |
|
|
|
375 |
|
|
// Create another thread.
|
376 |
|
|
$response = privatemsg_new_thread(array($webuser), $subject2 = $this->randomName(10), $this->randomName(20), array('author' => $webuser));
|
377 |
|
|
$thread_id2 = $response['message']->thread_id;
|
378 |
|
|
|
379 |
|
|
$this->drupalGet('messages');
|
380 |
|
|
$rows = $this->xpath('//tbody/tr');
|
381 |
|
|
foreach ($rows as $row) {
|
382 |
|
|
if ($row->td[2]->a == $subject1) {
|
383 |
|
|
// The first thread should have both tags. Try both ways as the order
|
384 |
|
|
// might change.
|
385 |
|
|
$verify = (($tag1 == $row->td[1]->a[0] && $tag2 == $row->td[1]->a[1]) || ($tag1 == $row->td[1]->a[1] && $tag2 == $row->td[1]->a[0]));
|
386 |
|
|
$this->assertTrue($verify, t('First thread is correctly tagged.'));
|
387 |
|
|
}
|
388 |
|
|
if ($row->td[2]->a == $subject2) {
|
389 |
|
|
// The second thread should have no tags.
|
390 |
|
|
$this->assertEqual('', $row->td[1], t('Second thread is not tagged.'));
|
391 |
|
|
}
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
$add_tag = array(
|
395 |
|
|
'list[' . $thread_id2 . ']' => 1,
|
396 |
|
|
'tag-add' => $tag2,
|
397 |
|
|
);
|
398 |
|
|
$this->drupalPost(NULL, $add_tag, t('Apply Tag'));
|
399 |
|
|
$rows = $this->xpath('//tbody/tr');
|
400 |
|
|
foreach ($rows as $row) {
|
401 |
|
|
if ($row->td[2]->a == $subject1) {
|
402 |
|
|
// The first thread should have both tags. Try both ways as the order
|
403 |
|
|
// might change.
|
404 |
|
|
$verify = (($tag1 == $row->td[1]->a[0] && $tag2 == $row->td[1]->a[1]) || ($tag1 == $row->td[1]->a[1] && $tag2 == $row->td[1]->a[0]));
|
405 |
|
|
$this->assertTrue($verify, t('First thread is correctly tagged.'));
|
406 |
|
|
}
|
407 |
|
|
if ($row->td[2]->a == $subject2) {
|
408 |
|
|
// The second thread should have one tag.
|
409 |
|
|
$this->assertEqual($tag2, $row->td[1]->a, t('Second thread is correctly tagged.'));
|
410 |
|
|
}
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
$remove_tag = array(
|
414 |
|
|
'list[' . $thread_id . ']' => 1,
|
415 |
|
|
'list[' . $thread_id2 . ']' => 1,
|
416 |
|
|
'tag-remove' => 3,
|
417 |
|
|
);
|
418 |
|
|
$this->drupalPost(NULL, $remove_tag, t('Remove Tag'));
|
419 |
|
|
$rows = $this->xpath('//tbody/tr');
|
420 |
|
|
foreach ($rows as $row) {
|
421 |
|
|
if ($row->td[2]->a == $subject1) {
|
422 |
|
|
// The first thread should have only one tag now.
|
423 |
|
|
$this->assertEqual($tag1, $row->td[1]->a, t('First thread is correctly tagged.'));
|
424 |
|
|
}
|
425 |
|
|
if ($row->td[2]->a == $subject2) {
|
426 |
|
|
// The second thread should have no tags.
|
427 |
|
|
$this->assertEqual('', $row->td[1], t('Second thread is not tagged.'));
|
428 |
|
|
}
|
429 |
|
|
}
|
430 |
|
|
$this->assertNoText($tag2, t('Second tag is not displayed anymore.'));
|
431 |
|
|
}
|
432 |
|
|
}
|
433 |
|
|
|
434 |
|
|
/**
|
435 |
|
|
* Test filters, tags and inbox/sent handling.
|
436 |
|
|
*/
|
437 |
|
|
class PrivatemsgFilterWidgetTestCase extends PrivatemsgBaseTestCase {
|
438 |
|
|
/**
|
439 |
|
|
* Implements getInfo().
|
440 |
|
|
*/
|
441 |
|
|
public static function getInfo() {
|
442 |
|
|
return array(
|
443 |
|
|
'name' => t('Privatemsg filter widget'),
|
444 |
|
|
'description' => t('Tests the Privatemsg filter widget displayed on message listings'),
|
445 |
|
|
'group' => t('Privatemsg'),
|
446 |
|
|
);
|
447 |
|
|
}
|
448 |
|
|
|
449 |
|
|
/**
|
450 |
|
|
* Implements setUp().
|
451 |
|
|
*/
|
452 |
|
|
function setUp() {
|
453 |
|
|
parent::setUp('privatemsg', 'privatemsg_filter');
|
454 |
|
|
}
|
455 |
|
|
|
456 |
|
|
/**
|
457 |
|
|
* Generic filter widget tests.
|
458 |
|
|
*/
|
459 |
|
|
function testAuthorSearch() {
|
460 |
|
|
$user1 = $this->drupalCreateuser(array('read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags', 'filter private messages'));
|
461 |
|
|
$user2 = $this->drupalCreateuser(array('read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags', 'filter private messages'));
|
462 |
|
|
$user3 = $this->drupalCreateuser(array('read privatemsg', 'write privatemsg', 'tag private messages', 'create private message tags', 'filter private messages'));
|
463 |
|
|
|
464 |
|
|
$this->drupalLogin($user2);
|
465 |
|
|
$this->drupalGet('messages');
|
466 |
|
|
|
467 |
|
|
// Make sure the widget is not displayed when there are no messages.
|
468 |
|
|
$this->assertNoFieldById('edit-author');
|
469 |
|
|
|
470 |
|
|
// Create a new thread from user 1 through the api.
|
471 |
|
|
$response = privatemsg_new_thread(array($user2), $subject = $this->randomName(10), $body = $this->randomName(20), array('author' => $user1));
|
472 |
|
|
$thread_id = $response['message']->thread_id;
|
473 |
|
|
|
474 |
|
|
$this->drupalGet('messages');
|
475 |
|
|
|
476 |
|
|
// Make sure the widget is now displayed and the message is too.
|
477 |
|
|
$this->assertText($subject);
|
478 |
|
|
$this->assertFieldById('edit-author');
|
479 |
|
|
|
480 |
|
|
// Search for user 3 which will find no results but the widget should still be displayed.
|
481 |
|
|
$this->drupalPost(NULL, array('author' => $user3->name), t('Filter'));
|
482 |
|
|
$this->assertNoText($subject);
|
483 |
|
|
$this->assertFieldById('edit-author', $user3->name . ', ');
|
484 |
|
|
|
485 |
|
|
// Reset filter widget.
|
486 |
|
|
$this->drupalPost(NULL, array(), t('Reset'));
|
487 |
|
|
$this->assertFieldById('edit-author');
|
488 |
|
|
$this->assertText($subject);
|
489 |
|
|
|
490 |
|
|
// Create a new thread through the api.
|
491 |
|
|
$response = privatemsg_new_thread(array($user2), $subject2 = $this->randomName(10), $body2 = $this->randomName(20), array('author' => $user3));
|
492 |
|
|
$thread_id = $response['message']->thread_id;
|
493 |
|
|
|
494 |
|
|
// Make sure that the new message is displayed.
|
495 |
|
|
$this->drupalGet('messages');
|
496 |
|
|
$this->assertText($subject2);
|
497 |
|
|
|
498 |
|
|
// Search for user 1 which should only display his message.
|
499 |
|
|
$this->drupalPost(NULL, array('author' => $user1->name), t('Filter'));
|
500 |
|
|
$this->assertText($subject);
|
501 |
|
|
$this->assertNoText($subject2);
|
502 |
|
|
|
503 |
|
|
// Save the filter and access /messages again - The filter should still be
|
504 |
|
|
// active.
|
505 |
|
|
$this->drupalPost(NULL, array(), t('Save filter'));
|
506 |
|
|
$this->drupalGet('messages');
|
507 |
|
|
$this->assertFieldById('edit-author', $user1->name . ', ');
|
508 |
|
|
$this->assertText($subject);
|
509 |
|
|
$this->assertNoText($subject2);
|
510 |
|
|
|
511 |
|
|
// Reset filter widget.
|
512 |
|
|
$this->drupalPost(NULL, array(), t('Reset'));
|
513 |
|
|
$this->assertFieldById('edit-author');
|
514 |
|
|
$this->assertText($subject);
|
515 |
|
|
$this->assertText($subject2);
|
516 |
|
|
}
|
517 |
|
|
} |