1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* This file contains tests for the privatemsg limits module
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Test cases for the privatemsg_limits module.
|
10 |
|
|
*/
|
11 |
|
|
class PrivatemsgLimitsTestCase extends PrivatemsgBaseTestCase {
|
12 |
|
|
public static function getInfo() {
|
13 |
|
|
return array(
|
14 |
|
|
'name' => 'Privatemsg Limits',
|
15 |
|
|
'description' => 'Tests limits on sending and recieving messages.',
|
16 |
|
|
'group' => 'Privatemsg',
|
17 |
|
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Install necessary modules.
|
22 |
|
|
*/
|
23 |
|
|
function setUp() {
|
24 |
|
|
parent::setUp('privatemsg', 'privatemsg_limits', 'privatemsg_filter');
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* Test sending limits with threads as limits object.
|
29 |
|
|
*/
|
30 |
|
|
function testSendLimitsMessages() {
|
31 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
32 |
|
|
$user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
33 |
|
|
|
34 |
|
|
$this->drupalLogin($admin);
|
35 |
|
|
|
36 |
|
|
$settings = array(
|
37 |
|
|
'privatemsg_limits_send_enabled' => TRUE,
|
38 |
|
|
'privatemsg_limits_send_amount' => 3,
|
39 |
|
|
'privatemsg_limits_send_amount_role_3' => 5,
|
40 |
|
|
);
|
41 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
42 |
|
|
|
43 |
|
|
$this->drupalLogin($user);
|
44 |
|
|
for ($i = 0; $i < 3; $i++) {
|
45 |
|
|
// Send three messages.
|
46 |
|
|
$edit = array(
|
47 |
|
|
'recipient' => $user->name,
|
48 |
|
|
'subject' => $this->randomName(20),
|
49 |
|
|
'body[value]' => $this->randomName(100),
|
50 |
|
|
);
|
51 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
52 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user->name)));
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
// Send a fourth message that fails.
|
56 |
|
|
$blocked = array(
|
57 |
|
|
'recipient' => $user->name,
|
58 |
|
|
'subject' => $this->randomName(20),
|
59 |
|
|
'body[value]' => $this->randomName(100),
|
60 |
|
|
);
|
61 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
62 |
|
|
$this->assertText(t('Your message was not sent because you have exceeded your sending limit. You are allowed to send 3 messages every 1 hour.'));
|
63 |
|
|
|
64 |
|
|
// Verify that replies can't be sent either.
|
65 |
|
|
$this->drupalGet('messages');
|
66 |
|
|
$this->clickLink($edit['subject']);
|
67 |
|
|
$reply = array(
|
68 |
|
|
'body[value]' => $this->randomName(100),
|
69 |
|
|
);
|
70 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
71 |
|
|
$this->assertText(t('Your message was not sent because you have exceeded your sending limit. You are allowed to send 3 messages every 1 hour.'));
|
72 |
|
|
|
73 |
|
|
// Now the same with admin, he should be able to send 5 messages.
|
74 |
|
|
$this->drupalLogin($admin);
|
75 |
|
|
for ($i = 0; $i < 5; $i++) {
|
76 |
|
|
// Send three messages.
|
77 |
|
|
$edit = array(
|
78 |
|
|
'recipient' => $admin->name,
|
79 |
|
|
'subject' => $this->randomName(20),
|
80 |
|
|
'body[value]' => $this->randomName(100),
|
81 |
|
|
);
|
82 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
83 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
// Send a sixth message that fails.
|
87 |
|
|
$blocked = array(
|
88 |
|
|
'recipient' => $admin->name,
|
89 |
|
|
'subject' => $this->randomName(20),
|
90 |
|
|
'body[value]' => $this->randomName(100),
|
91 |
|
|
);
|
92 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
93 |
|
|
$this->assertText(t('Your message was not sent because you have exceeded your sending limit. You are allowed to send 5 messages every 1 hour.'));
|
94 |
|
|
|
95 |
|
|
// Verify that replies can't be sent either.
|
96 |
|
|
$this->drupalGet('messages');
|
97 |
|
|
$this->clickLink($edit['subject']);
|
98 |
|
|
$reply = array(
|
99 |
|
|
'body[value]' => $this->randomName(100),
|
100 |
|
|
);
|
101 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
102 |
|
|
$this->assertText(t('Your message was not sent because you have exceeded your sending limit. You are allowed to send 5 messages every 1 hour.'));
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
/**
|
106 |
|
|
* Test sending limits with threads as limits object.
|
107 |
|
|
*/
|
108 |
|
|
function testSendLimitsThreads() {
|
109 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
110 |
|
|
$user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
111 |
|
|
|
112 |
|
|
$this->drupalLogin($admin);
|
113 |
|
|
|
114 |
|
|
$settings = array(
|
115 |
|
|
'privatemsg_limits_send_enabled' => TRUE,
|
116 |
|
|
'privatemsg_limits_send_amount' => 3,
|
117 |
|
|
'privatemsg_limits_send_amount_role_3' => 5,
|
118 |
|
|
'privatemsg_limits_send_object' => 'thread',
|
119 |
|
|
);
|
120 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
121 |
|
|
|
122 |
|
|
$this->drupalLogin($user);
|
123 |
|
|
for ($i = 0; $i < 3; $i++) {
|
124 |
|
|
// Send three messages.
|
125 |
|
|
$edit = array(
|
126 |
|
|
'recipient' => $user->name,
|
127 |
|
|
'subject' => $this->randomName(20),
|
128 |
|
|
'body[value]' => $this->randomName(100),
|
129 |
|
|
);
|
130 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
131 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user->name)));
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
// Send a fourth message that fails.
|
135 |
|
|
$blocked = array(
|
136 |
|
|
'recipient' => $user->name,
|
137 |
|
|
'subject' => $this->randomName(20),
|
138 |
|
|
'body[value]' => $this->randomName(100),
|
139 |
|
|
);
|
140 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
141 |
|
|
$this->assertText(t('Your message was not sent because you have exceeded your sending limit. You are allowed to send 3 messages every 1 hour.'));
|
142 |
|
|
|
143 |
|
|
// Verify that replies can still be sent.
|
144 |
|
|
$this->drupalGet('messages');
|
145 |
|
|
$this->clickLink($edit['subject']);
|
146 |
|
|
$reply = array(
|
147 |
|
|
'body[value]' => $this->randomName(100),
|
148 |
|
|
);
|
149 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
150 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user->name)));
|
151 |
|
|
|
152 |
|
|
// Now the same with admin, he should be able to send 5 messages.
|
153 |
|
|
$this->drupalLogin($admin);
|
154 |
|
|
for ($i = 0; $i < 5; $i++) {
|
155 |
|
|
// Send three messages.
|
156 |
|
|
$edit = array(
|
157 |
|
|
'recipient' => $admin->name,
|
158 |
|
|
'subject' => $this->randomName(20),
|
159 |
|
|
'body[value]' => $this->randomName(100),
|
160 |
|
|
);
|
161 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
162 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
// Send a sixth message that fails.
|
166 |
|
|
$blocked = array(
|
167 |
|
|
'recipient' => $admin->name,
|
168 |
|
|
'subject' => $this->randomName(20),
|
169 |
|
|
'body[value]' => $this->randomName(100),
|
170 |
|
|
);
|
171 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
172 |
|
|
$this->assertText(t('Your message was not sent because you have exceeded your sending limit. You are allowed to send 5 messages every 1 hour.'));
|
173 |
|
|
|
174 |
|
|
// Verify that replies can't be sent either.
|
175 |
|
|
$this->drupalGet('messages');
|
176 |
|
|
$this->clickLink($edit['subject']);
|
177 |
|
|
$reply = array(
|
178 |
|
|
'body[value]' => $this->randomName(100),
|
179 |
|
|
);
|
180 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
181 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
/**
|
185 |
|
|
* Test receive limit with messages as limits object.
|
186 |
|
|
*/
|
187 |
|
|
function testReceiveLimitsMessages() {
|
188 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
189 |
|
|
$user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
190 |
|
|
|
191 |
|
|
$this->drupalLogin($admin);
|
192 |
|
|
|
193 |
|
|
$settings = array(
|
194 |
|
|
'privatemsg_limits_receive_enabled' => TRUE,
|
195 |
|
|
'privatemsg_limits_receive_amount' => 3,
|
196 |
|
|
'privatemsg_limits_receive_amount_role_3' => 5,
|
197 |
|
|
);
|
198 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
199 |
|
|
|
200 |
|
|
// Check empty inbox.
|
201 |
|
|
$this->drupalGet('messages');
|
202 |
|
|
$this->assertText(t('You are currently using @percent% (@used messages) of your @limit messages limit.', array('@percent' => 0, '@used' => 0, '@limit' => 5)));
|
203 |
|
|
|
204 |
|
|
$this->drupalLogin($user);
|
205 |
|
|
$this->drupalGet('messages');
|
206 |
|
|
$this->assertText(t('You are currently using @percent% (@used messages) of your @limit messages limit.', array('@percent' => 0, '@used' => 0, '@limit' => 3)));
|
207 |
|
|
|
208 |
|
|
// Send three messages from user to admin.
|
209 |
|
|
for ($i = 0; $i < 3; $i++) {
|
210 |
|
|
$edit = array(
|
211 |
|
|
'recipient' => $admin->name,
|
212 |
|
|
'subject' => $this->randomName(20),
|
213 |
|
|
'body[value]' => $this->randomName(100),
|
214 |
|
|
);
|
215 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
216 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
// Try sending an additional message.
|
220 |
|
|
$blocked = array(
|
221 |
|
|
'recipient' => $admin->name,
|
222 |
|
|
'subject' => $this->randomName(20),
|
223 |
|
|
'body[value]' => $this->randomName(100),
|
224 |
|
|
);
|
225 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
226 |
|
|
$this->assertText(t("Your message mailbox is currently full. You are allowed a maximum of @limit messages in your mailbox at one time. You won't be able to send or receive new messages until you delete some existing ones.", array('@limit' => 3)), 'Limit exceeded message displayed.');
|
227 |
|
|
|
228 |
|
|
// Try to reply to a sent message.
|
229 |
|
|
$this->drupalGet('messages/sent');
|
230 |
|
|
$this->clickLink($edit['subject']);
|
231 |
|
|
$reply = array(
|
232 |
|
|
'body[value]' => $this->randomName(100),
|
233 |
|
|
);
|
234 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
235 |
|
|
$this->assertText(t("Your message mailbox is currently full. You are allowed a maximum of @limit messages in your mailbox at one time. You won't be able to send or receive new messages until you delete some existing ones.", array('@limit' => 3)), 'Limit exceeded message displayed.');
|
236 |
|
|
|
237 |
|
|
// Check user limits.
|
238 |
|
|
$this->drupalGet('messages');
|
239 |
|
|
$this->assertText(t('You are currently using @percent% (@used messages) of your @limit messages limit.', array('@percent' => 100, '@used' => 3, '@limit' => 3)));
|
240 |
|
|
|
241 |
|
|
// Check admin limits.
|
242 |
|
|
$this->drupalLogin($admin);
|
243 |
|
|
$this->drupalGet('messages');
|
244 |
|
|
$this->assertText(t('You are currently using @percent% (@used messages) of your @limit messages limit.', array('@percent' => 60, '@used' => 3, '@limit' => 5)));
|
245 |
|
|
|
246 |
|
|
// Try to send a message to the user.
|
247 |
|
|
$blocked = array(
|
248 |
|
|
'recipient' => $user->name,
|
249 |
|
|
'subject' => $this->randomName(20),
|
250 |
|
|
'body[value]' => $this->randomName(100),
|
251 |
|
|
);
|
252 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
253 |
|
|
$this->assertText(t("This message cannot be sent to @user because @user's mailbox is full.", array('@user' => $user->name)));
|
254 |
|
|
|
255 |
|
|
// Try to reply to a message.
|
256 |
|
|
$this->drupalGet('messages');
|
257 |
|
|
$this->clickLink($edit['subject']);
|
258 |
|
|
$this->assertNoText(t('Send message'));
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
/**
|
262 |
|
|
* Test receive limit with messages as limits object.
|
263 |
|
|
*/
|
264 |
|
|
function testReceiveLimitsThreads() {
|
265 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
266 |
|
|
$user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
267 |
|
|
|
268 |
|
|
$this->drupalLogin($admin);
|
269 |
|
|
|
270 |
|
|
$settings = array(
|
271 |
|
|
'privatemsg_limits_receive_enabled' => TRUE,
|
272 |
|
|
'privatemsg_limits_receive_amount' => 3,
|
273 |
|
|
'privatemsg_limits_receive_amount_role_3' => 5,
|
274 |
|
|
'privatemsg_limits_receive_object' => 'thread',
|
275 |
|
|
);
|
276 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
277 |
|
|
|
278 |
|
|
// Check empty inbox.
|
279 |
|
|
$this->drupalGet('messages');
|
280 |
|
|
$this->assertText(t('You are currently using @percent% (@used conversations) of your @limit conversations limit.', array('@percent' => 0, '@used' => 0, '@limit' => 5)));
|
281 |
|
|
|
282 |
|
|
$this->drupalLogin($user);
|
283 |
|
|
$this->drupalGet('messages');
|
284 |
|
|
$this->assertText(t('You are currently using @percent% (@used conversations) of your @limit conversations limit.', array('@percent' => 0, '@used' => 0, '@limit' => 3)));
|
285 |
|
|
|
286 |
|
|
// Send three messages from user to admin.
|
287 |
|
|
for ($i = 0; $i < 3; $i++) {
|
288 |
|
|
$edit = array(
|
289 |
|
|
'recipient' => $admin->name,
|
290 |
|
|
'subject' => $this->randomName(20),
|
291 |
|
|
'body[value]' => $this->randomName(100),
|
292 |
|
|
);
|
293 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
294 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
// Try sending an additional message.
|
298 |
|
|
$blocked = array(
|
299 |
|
|
'recipient' => $admin->name,
|
300 |
|
|
'subject' => $this->randomName(20),
|
301 |
|
|
'body[value]' => $this->randomName(100),
|
302 |
|
|
);
|
303 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
304 |
|
|
$this->assertText(t("Your message mailbox is currently full. You are allowed a maximum of @limit conversations in your mailbox at one time. You won't be able to start or receive new conversations until you delete some existing ones.", array('@limit' => 3)), 'Limit exceeded message displayed.');
|
305 |
|
|
|
306 |
|
|
// Try to reply to a sent message.
|
307 |
|
|
$this->drupalGet('messages/sent');
|
308 |
|
|
$this->clickLink($edit['subject']);
|
309 |
|
|
$reply = array(
|
310 |
|
|
'body[value]' => $this->randomName(100),
|
311 |
|
|
);
|
312 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
313 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
314 |
|
|
|
315 |
|
|
// Check user limits.
|
316 |
|
|
$this->drupalGet('messages');
|
317 |
|
|
$this->assertText(t('You are currently using @percent% (@used conversations) of your @limit conversations limit.', array('@percent' => 100, '@used' => 3, '@limit' => 3)));
|
318 |
|
|
|
319 |
|
|
// Check admin limits.
|
320 |
|
|
$this->drupalLogin($admin);
|
321 |
|
|
$this->drupalGet('messages');
|
322 |
|
|
$this->assertText(t('You are currently using @percent% (@used conversations) of your @limit conversations limit.', array('@percent' => 60, '@used' => 3, '@limit' => 5)));
|
323 |
|
|
|
324 |
|
|
// Try to send a message to the user.
|
325 |
|
|
$blocked = array(
|
326 |
|
|
'recipient' => $user->name,
|
327 |
|
|
'subject' => $this->randomName(20),
|
328 |
|
|
'body[value]' => $this->randomName(100),
|
329 |
|
|
);
|
330 |
|
|
$this->drupalPost('messages/new', $blocked, t('Send message'));
|
331 |
|
|
$this->assertText(t("This message cannot be sent to @user because @user's mailbox is full.", array('@user' => $user->name)));
|
332 |
|
|
|
333 |
|
|
// Try to reply to a message.
|
334 |
|
|
$this->drupalGet('messages');
|
335 |
|
|
$this->clickLink($edit['subject']);
|
336 |
|
|
$reply = array(
|
337 |
|
|
'body[value]' => $this->randomName(100),
|
338 |
|
|
);
|
339 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
340 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user->name)));
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
/**
|
344 |
|
|
* Test limiting the number of recipients.
|
345 |
|
|
*/
|
346 |
|
|
function testRecipientsLimits() {
|
347 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
348 |
|
|
$user1 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
349 |
|
|
$user2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
350 |
|
|
$user3 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
351 |
|
|
|
352 |
|
|
$this->drupalLogin($admin);
|
353 |
|
|
|
354 |
|
|
$settings = array(
|
355 |
|
|
'privatemsg_limits_recipients_enabled' => TRUE,
|
356 |
|
|
'privatemsg_limits_recipients_amount' => 1,
|
357 |
|
|
'privatemsg_limits_recipients_amount_role_3' => 2,
|
358 |
|
|
);
|
359 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
360 |
|
|
|
361 |
|
|
// Send a message to a single user.
|
362 |
|
|
$edit = array(
|
363 |
|
|
'recipient' => $user1->name,
|
364 |
|
|
'subject' => $this->randomName(20),
|
365 |
|
|
'body[value]' => $this->randomName(100),
|
366 |
|
|
);
|
367 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
368 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user1->name)));
|
369 |
|
|
|
370 |
|
|
// Send a message to two users.
|
371 |
|
|
$edit = array(
|
372 |
|
|
'recipient' => $user1->name . ', ' . $user2->name,
|
373 |
|
|
'subject' => $this->randomName(20),
|
374 |
|
|
'body[value]' => $this->randomName(100),
|
375 |
|
|
);
|
376 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
377 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user1->name . ', ' . $user2->name)));
|
378 |
|
|
|
379 |
|
|
// Try sending a message to three users.
|
380 |
|
|
$edit = array(
|
381 |
|
|
'recipient' => $user1->name . ', ' . $user2->name . ', ' . $user3->name,
|
382 |
|
|
'subject' => $this->randomName(20),
|
383 |
|
|
'body[value]' => $this->randomName(100),
|
384 |
|
|
);
|
385 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
386 |
|
|
$this->assertText(t('You are not allowed to send a message to more than @number recipients.', array('@number' => 2)), 'Not allowed message displayed.');
|
387 |
|
|
|
388 |
|
|
// Login in as user.
|
389 |
|
|
$this->drupalLogin($user1);
|
390 |
|
|
// Send a message to a single users.
|
391 |
|
|
$edit = array(
|
392 |
|
|
'recipient' => $user2->name,
|
393 |
|
|
'subject' => $this->randomName(20),
|
394 |
|
|
'body[value]' => $this->randomName(100),
|
395 |
|
|
);
|
396 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
397 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user2->name)));
|
398 |
|
|
|
399 |
|
|
// Try sending a message to two users.
|
400 |
|
|
$edit = array(
|
401 |
|
|
'recipient' => $user2->name . ', ' . $user3->name,
|
402 |
|
|
'subject' => $this->randomName(20),
|
403 |
|
|
'body[value]' => $this->randomName(100),
|
404 |
|
|
);
|
405 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
406 |
|
|
$this->assertText(t('You are not allowed to send a message to more than @number recipients.', array('@number' => 1)), 'Not allowed message displayed.');
|
407 |
|
|
}
|
408 |
|
|
|
409 |
|
|
/**
|
410 |
|
|
* Tests for limiting the number of messages per thread.
|
411 |
|
|
*/
|
412 |
|
|
function testNumberOfMessagesBlock() {
|
413 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
414 |
|
|
$user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
415 |
|
|
|
416 |
|
|
$this->drupalLogin($admin);
|
417 |
|
|
|
418 |
|
|
$settings = array(
|
419 |
|
|
'privatemsg_limits_messages_per_thread' => 2,
|
420 |
|
|
'privatemsg_limits_messages_per_thread_action' => 'block-message',
|
421 |
|
|
);
|
422 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
423 |
|
|
|
424 |
|
|
// Send a message to a user.
|
425 |
|
|
$edit = array(
|
426 |
|
|
'recipient' => $user->name,
|
427 |
|
|
'subject' => $this->randomName(20),
|
428 |
|
|
'body[value]' => $this->randomName(100),
|
429 |
|
|
);
|
430 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
431 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user->name)));
|
432 |
|
|
|
433 |
|
|
// Send a reply.
|
434 |
|
|
$this->drupalLogin($user);
|
435 |
|
|
$this->drupalGet('messages');
|
436 |
|
|
$this->clickLink($edit['subject']);
|
437 |
|
|
$edit = array(
|
438 |
|
|
'body[value]' => $this->randomName(100),
|
439 |
|
|
);
|
440 |
|
|
$this->drupalPost(NULL, $edit, t('Send message'));
|
441 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
442 |
|
|
|
443 |
|
|
// Try to send another one.
|
444 |
|
|
$edit = array(
|
445 |
|
|
'body[value]' => $this->randomName(100),
|
446 |
|
|
);
|
447 |
|
|
$this->drupalPost(NULL, $edit, t('Send message'));
|
448 |
|
|
$this->assertText(t("This message cannot be sent because the thread already contains @limit messages (the maximum number of messages permitted per thread). To send this message, please create a new message thread.", array('@limit' => 2)));
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
/**
|
452 |
|
|
* Tests for limiting the number of messages per thread.
|
453 |
|
|
*/
|
454 |
|
|
function testNumberOfMessagesCreate() {
|
455 |
|
|
$admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
|
456 |
|
|
$user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
|
457 |
|
|
|
458 |
|
|
$this->drupalLogin($admin);
|
459 |
|
|
|
460 |
|
|
$settings = array(
|
461 |
|
|
'privatemsg_limits_messages_per_thread' => 1,
|
462 |
|
|
'privatemsg_limits_messages_per_thread_action' => 'create-new',
|
463 |
|
|
);
|
464 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
|
465 |
|
|
|
466 |
|
|
// Send a message to a user.
|
467 |
|
|
$edit = array(
|
468 |
|
|
'recipient' => $user->name,
|
469 |
|
|
'subject' => $this->randomName(20),
|
470 |
|
|
'body[value]' => $this->randomName(100),
|
471 |
|
|
);
|
472 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
473 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $user->name)));
|
474 |
|
|
|
475 |
|
|
// Send a reply.
|
476 |
|
|
$this->drupalLogin($user);
|
477 |
|
|
$this->drupalGet('messages');
|
478 |
|
|
$this->clickLink($edit['subject']);
|
479 |
|
|
$reply = array(
|
480 |
|
|
'body[value]' => $this->randomName(100),
|
481 |
|
|
);
|
482 |
|
|
$this->drupalPost(NULL, $reply, t('Send message'));
|
483 |
|
|
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $admin->name)));
|
484 |
|
|
// Make sure we are in a new thread and the original thread body isn't
|
485 |
|
|
// displayed anymore.
|
486 |
|
|
$this->assertNoText($edit['body[value]']);
|
487 |
|
|
$this->assertText($reply['body[value]']);
|
488 |
|
|
}
|
489 |
|
|
} |