function PrivatemsgLimitsTestCase::testSendLimitsMessages in Privatemsg 7
Same name and namespace in other branches
- 6.2 privatemsg_limits/privatemsg_limits.test \PrivatemsgLimitsTestCase::testSendLimitsMessages()
- 7.2 privatemsg_limits/privatemsg_limits.test \PrivatemsgLimitsTestCase::testSendLimitsMessages()
Test sending limits with threads as limits object.
File
- privatemsg_limits/
privatemsg_limits.test, line 30 - This file contains tests for the privatemsg limits module
Class
- PrivatemsgLimitsTestCase
- Test cases for the privatemsg_limits module.
Code
function testSendLimitsMessages() {
$admin = $this
->drupalCreateUser(array(
'administer privatemsg settings',
'write privatemsg',
'read privatemsg',
));
$user = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
));
$this
->drupalLogin($admin);
$settings = array(
'privatemsg_limits_send_enabled' => TRUE,
'privatemsg_limits_send_amount' => 3,
'privatemsg_limits_send_amount_role_3' => 5,
);
$this
->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));
$this
->drupalLogin($user);
for ($i = 0; $i < 3; $i++) {
// Send three messages.
$edit = array(
'recipient' => $user->name,
'subject' => $this
->randomName(20),
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('A message has been sent to @recipients.', array(
'@recipients' => $user->name,
)));
}
// Send a fourth message that fails.
$blocked = array(
'recipient' => $user->name,
'subject' => $this
->randomName(20),
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost('messages/new', $blocked, t('Send message'));
$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.'));
// Verify that replies can't be sent either.
$this
->drupalGet('messages');
$this
->clickLink($edit['subject']);
$reply = array(
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost(NULL, $reply, t('Send message'));
$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.'));
// Now the same with admin, he should be able to send 5 messages.
$this
->drupalLogin($admin);
for ($i = 0; $i < 5; $i++) {
// Send three messages.
$edit = array(
'recipient' => $admin->name,
'subject' => $this
->randomName(20),
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('A message has been sent to @recipients.', array(
'@recipients' => $admin->name,
)));
}
// Send a sixth message that fails.
$blocked = array(
'recipient' => $admin->name,
'subject' => $this
->randomName(20),
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost('messages/new', $blocked, t('Send message'));
$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.'));
// Verify that replies can't be sent either.
$this
->drupalGet('messages');
$this
->clickLink($edit['subject']);
$reply = array(
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost(NULL, $reply, t('Send message'));
$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.'));
}