function PrivatemsgGroupsTestCase::testPermission in Privatemsg 7.2
Test global permissions and group permission.
File
- privatemsg_groups/
privatemsg_groups.test, line 158 - This file contains tests for the privatemsg groups module
Class
- PrivatemsgGroupsTestCase
- Test cases for the privatemsg_groups module.
Code
function testPermission() {
// Attempt to send message to group1 with no permission.
$this
->drupalLogin($this->user1);
$edit = array(
'recipient' => $this->group1->title . '[group]',
'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.'));
$this
->drupalLogout();
// Attempt to send message to group1 with write to all permission but
// no group permission.
$user2 = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
'write privatemsg to all organic groups',
));
og_group('node', $this->group1->nid, array(
'entity' => $user2->uid,
));
$this
->drupalLogin($user2);
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('A message has been sent to @group (group).', array(
'@group' => $this->group1->title,
)));
$this
->drupalLogout();
// Attempt to send message to group1 with write to own permission but
// no group permission.
$user3 = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
'write privatemsg to own organic groups',
));
og_group('node', $this->group1->nid, array(
'entity' => $user3->uid,
));
$this
->drupalLogin($user3);
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('You must include at least one valid recipient.'));
$this
->drupalLogout();
// Attempt to send message to group1 with write to own permission and
// group permission.
$roles = array_flip(og_roles('node', 'page', $this->group1->nid));
og_role_change_permissions($roles[OG_AUTHENTICATED_ROLE], array(
'write privatemsg to group' => 1,
));
$user4 = $this
->drupalCreateUser(array(
'read privatemsg',
'write privatemsg',
'write privatemsg to own organic groups',
));
og_group('node', $this->group1->nid, array(
'entity' => $user4->uid,
));
$this
->drupalLogin($user4);
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('A message has been sent to @group (group).', array(
'@group' => $this->group1->title,
)));
// Attempt to send message to group2 with write to own permission
$edit['recipient'] = $this->group2->title . '[group]';
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('You must include at least one valid recipient.'));
}