function PrivatemsgRolesTestCase::testSendMessagetoRoleCron in Privatemsg 7
Same name and namespace in other branches
- 6.2 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testSendMessagetoRoleCron()
- 7.2 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testSendMessagetoRoleCron()
File
- privatemsg_roles/
privatemsg_roles.test, line 46 - This file contains tests for the privatemsg roles module
Class
- PrivatemsgRolesTestCase
- Test cases for the privatemsg_roles module.
Code
function testSendMessagetoRoleCron() {
$admin = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
'write privatemsg to roles',
));
$user1 = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
));
variable_set('privatemsg_recipient_small_threshold', 20);
variable_set('privatemgs_cron_recipient_per_run', 20);
// Create 26 users (more than are allowed to be process directly).
$users = array();
for ($i = 0; $i < 25; $i++) {
$users[$i] = $this
->drupalCreateUser();
// Add role of user 1 to user 2;
$edit = array(
'roles' => $users[$i]->roles + $user1->roles,
);
user_save($users[$i], $edit);
}
$recipient = user_role_load($user1->roles[4]);
$recipient->recipient = $recipient->rid;
$recipient->type = 'role';
privatemsg_new_thread(array(
$recipient,
), $subject = $this
->randomName(10), $body = $this
->randomName(50), array(
'author' => $admin,
));
// Run cron.
privatemsg_cron();
// Test a few recipients to see if they recieved the message.
foreach (array(
0,
5,
18,
) as $uid) {
$this
->drupalLogin($users[$uid]);
$this
->drupalGet('messages');
$this
->assertRaw($subject . '</a> <span class="marker">new</span>', t('Message is displayed as new'));
$this
->clickLink($subject);
$this
->assertText($body, t('Thread starter body displayed.'));
}
// Make sure that user 20 has not yet recieved the message.
$this
->drupalLogin($users[20]);
$this
->drupalGet('messages');
$this
->assertNoText($subject, t('Message is not yet displayed for this user'));
// Run cron again.
privatemsg_cron();
// Test that the remaining recipients do now see the message too.
foreach (array(
20,
24,
) as $uid) {
$this
->drupalLogin($users[$uid]);
$this
->drupalGet('messages');
$this
->assertRaw($subject . '</a> <span class="marker">new</span>', t('Message is displayed as new'));
$this
->clickLink($subject);
$this
->assertText($body, t('Thread starter body displayed.'));
}
}