function PrivatemsgTestCase::testDisablePrivatemsg in Privatemsg 6.2
Same name and namespace in other branches
- 7.2 privatemsg.test \PrivatemsgTestCase::testDisablePrivatemsg()
- 7 privatemsg.test \PrivatemsgTestCase::testDisablePrivatemsg()
Test functionality around disabling private messaging.
File
- ./
privatemsg.test, line 384 - Test file for privatemsg.module
Class
- PrivatemsgTestCase
- @file Test file for privatemsg.module
Code
function testDisablePrivatemsg() {
$admin_user = $this
->drupalCreateUser(array(
'administer permissions',
));
$enableduser = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
));
// set up user with read/write privatemsg permissions
$enableduser2 = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
));
// set up user with read/write privatemsg permissions
$disableduser = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
'allow disabling privatemsg',
));
// set up user with read/write privatemsg permissions
// Create a message between the users that we can use to test
$return = privatemsg_new_thread(array(
$disableduser,
), $this
->randomName(20), $this
->randomName(100), array(
'author' => $enableduser,
));
$mid = $return['message']['thread_id'];
$this
->drupalLogin($disableduser);
// Now disable $disabledUser.
$this
->drupalGet('user/' . $disableduser->uid . '/edit');
// Make sure that the checkbox is enabled by default.
$this
->assertFieldChecked('edit-pm-enable');
$edit = array(
'pm_enable' => FALSE,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$elements = $this
->xpath('//input[@id="edit-pm-enable"]');
return $this
->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), t('Checkbox is disabled.'));
// Verify that disableduser can list messages.
$this
->drupalGet('messages');
$this
->assertResponse(200, t('HTTP Response 200: Access to reading messages page is allowed.'));
// Verify that $disableduser can read messages but there is not reply form.
$this
->drupalGet('messages/view/' . $return['message']['thread_id']);
$this
->assertResponse(200, t('HTTP Response 200: Access to message thread page is allowed.'));
$this
->assertNoText(t('Reply to thread'), 'No reply form shown.');
// Verify that $disableduser cannot send a new message.
$this
->drupalGet('messages/new');
$this
->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user with private messaging disabled'));
// Use a newly loaded user object to test the API calls.
$disableduser_loaded = user_load($disableduser->uid, TRUE);
// Check that $disableduser cannot submit a reply.
$result = privatemsg_reply($return['message']['thread_id'], $this
->randomName(100), array(
'author' => $disableduser_loaded,
));
$this
->assertFalse($result['success'], 'Message reply was not sent.');
// Log in as $enableduser and try to send to $disabled user.
// Make sure that a message to multiple recipients still works if one is
// disabled.
$message = array(
'recipient' => $disableduser->name,
'subject' => $this
->randomName(20),
'body' => $this
->randomName(100),
);
$this
->drupalLogin($enableduser);
$this
->drupalPost('messages/new', $message, t('Send message'));
$this
->assertText(t('You are not allowed to send this message because all recipients are blocked.'));
// Make sure that a message to multiple recipients still works if one is
// disabled.
$messagemultiple = array(
'recipient' => $enableduser2->name . ', ' . $disableduser->name,
'subject' => $this
->randomName(20),
'body' => $this
->randomName(100),
);
$this
->drupalPost('messages/new', $messagemultiple, t('Send message'));
$this
->assertText(t('@recipient has disabled private message receiving.', array(
'@recipient' => $disableduser->name,
)), 'Message about user with disabled private messaging.');
$this
->assertText(t('A message has been sent to @recipients.', array(
'@recipients' => $enableduser2->name,
)), 'Message sent confirmation displayed.');
// Remove the permission to disable privatemsg.
$this
->drupalLogin($admin_user);
// 6 is the rid of the custom $disableduser role.
$edit = array(
'6[allow disabling privatemsg]' => FALSE,
);
$this
->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
// Make sure that the option is not visible anymore.
$this
->drupalLogin($disableduser);
$this
->drupalGet('user/' . $disableduser->uid . '/edit');
$this
->assertNoText(t('Enable Private Messaging'), t('Disable privatemsg setting not displayed'));
// Verify that the user is now allowed to write messages again.
$this
->drupalGet('messages/new');
$this
->assertNoText(t('You are not authorized to access this page.'), t('Access denied page is not displayed.'));
$this
->assertText(t('Write new message'), t('Write message form is displayed.'));
}