You are here

function PrivatemsgRolesTestCase::testPermission in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testPermission()
  2. 7 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testPermission()

File

privatemsg_roles/privatemsg_roles.test, line 140
This file contains tests for the privatemsg roles module

Class

PrivatemsgRolesTestCase
Test cases for the privatemsg_roles module.

Code

function testPermission() {
  $user1 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));

  // Update permissions.
  $this
    ->checkPermissions(array(), TRUE);

  // Give permission to write only a specific role.
  $role_name = user_role_load($user1->roles[3])->name;
  $user2 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
    'write privatemsg to role ' . $role_name,
  ));
  $this
    ->drupalLogin($user2);

  // Send a message to the role of user 1 and 2.
  $edit = array(
    'recipient' => $user2->roles[4] . '[role]',
    'subject' => $this
      ->randomName(10),
    'body[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalPost('messages/new', $edit, t('Send message'));
  $this
    ->assertText(t('You must include at least one valid recipient.'));
}