function PrivatemsgRolesTestCase::testSendMessagetoRoleCron in Privatemsg 6.2
Same name and namespace in other branches
- 7.2 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testSendMessagetoRoleCron()
- 7 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testSendMessagetoRoleCron()
File
- privatemsg_roles/
privatemsg_roles.test, line 44 - This file contains tests for the privatemsg roles module
Class
- PrivatemsgRolesTestCase
- Test cases for the privatemsg_roles module.
Code
function testSendMessagetoRoleCron() {
$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);
}
// Update permissions.
$this
->checkPermissions(array(), TRUE);
// Create user with specific role permission.
$admin = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
'write privatemsg to role ' . $user1->roles[3],
));
$recipient = (object) array(
'recipient' => 3,
'type' => 'role',
'name' => $user1->roles[3],
);
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.'));
}
}