function PrivatemsgBlockUserCase::testRoleBlockRecipient in Privatemsg 6
Same name and namespace in other branches
- 6.2 pm_block_user/pm_block_user.test \PrivatemsgBlockUserCase::testRoleBlockRecipient()
- 7.2 pm_block_user/pm_block_user.test \PrivatemsgBlockUserCase::testRoleBlockRecipient()
- 7 pm_block_user/pm_block_user.test \PrivatemsgBlockUserCase::testRoleBlockRecipient()
Test role blocking rules.
File
- pm_block_user/
pm_block_user.test, line 27 - Test file for pm_block_user.module
Class
- PrivatemsgBlockUserCase
- @file Test file for pm_block_user.module
Code
function testRoleBlockRecipient() {
// User id 3, Role id 3.
$author_user = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
'access user profiles',
));
// User id 4, Role id 4.
$blocked_user = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
'access user profiles',
));
// User id 5, Role id 5.
$admin_user = $this
->drupalCreateUser(array(
'administer privatemsg settings',
));
// Login the admin user and set up the role blocking rules.
$this
->drupalLogin($admin_user);
$this
->drupalPost('admin/settings/messages/block', array(), t('More'));
// If this fails we still have the default empty block user form.
$this
->assertNoText(t('No rules have been added'), t('The block form now allows adding rules.'));
// If author role is 3 and recipent role is 4, disallow sending of messages.
$edit = array(
'block_actions[0][author]' => 3,
'block_actions[0][recipient]' => 4,
'block_actions[0][action]' => 1,
'block_actions[0][enabled]' => 1,
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
// Verify that the user doesn't show up in the autocomplete.
// Login the user that will write a message to the user with the blocked role.
$this
->drupalLogin($author_user);
$this
->drupalGet('messages/new');
$this
->assertText(t('Write new message'), t('Author user can write messages.'));
$this
->drupalGet('messages/autocomplete/' . $blocked_user->name);
$this
->assertNoText($blocked_user->name, t('User with blocked role does not appear in autocomplete results.'));
// Verify that link to send private message to blocked user is not shown on their profile page.
$this
->drupalGet('user/' . $blocked_user->uid);
$this
->assertNoText(t('Send this user a private message'), t("Author user cannot see link to send blocked user a message on blocked user's profile."));
// Verify that it is not possible to manually write a message to blocked user.
$this
->drupalGet('messages/new');
$message = array(
'recipient' => $blocked_user->name,
'subject' => $this
->randomName(20),
'body' => $this
->randomName(50),
);
$this
->drupalPost('messages/new', $message, t('Send message'));
$this
->assertText(t('You are not permitted to send messages to @recipient.', array(
'@recipient' => $blocked_user->name,
)), t('Author user message to blocked user has been blocked.'));
// Verify that unblocked user can receive message from a multi-recipient message that includes blocked user.
$this
->drupalGet('messages/new');
$message = array(
'recipient' => $admin_user->name . ', ' . $blocked_user->name,
'subject' => $this
->randomName(20),
'body' => $this
->randomName(50),
);
$this
->drupalPost('messages/new', $message, t('Send message'));
$this
->assertText(t('You are not permitted to send messages to @recipient.', array(
'@recipient' => $blocked_user->name,
)), t('Author user message to blocked user has been blocked.'));
$this
->assertText(t('A message has been sent to @recipient.', array(
'@recipient' => $admin_user->name,
)), t('Author user message sent to admin user.'));
}