function PrivatemsgTestCase::testReadAllPermission in Privatemsg 7.2
Same name and namespace in other branches
- 6.2 privatemsg.test \PrivatemsgTestCase::testReadAllPermission()
- 6 privatemsg.test \PrivatemsgTestCase::testReadAllPermission()
- 7 privatemsg.test \PrivatemsgTestCase::testReadAllPermission()
Test correct handling of read all permissions.
File
- ./
privatemsg.test, line 543 - Test file for privatemsg.module
Class
Code
function testReadAllPermission() {
$author = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
));
$recipient = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
));
$admin = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
'read all private messages',
));
// Create new message.
$edit = array(
'recipient' => $recipient->name,
'subject' => $this
->randomName(20),
'body[value]' => $this
->randomName(100),
);
$this
->drupalLogin($author);
$this
->drupalPost('messages/new', $edit, t('Send message'));
$this
->assertText(t('A message has been sent to @recipients.', array(
'@recipients' => $recipient->name,
)), t('Message sent confirmation displayed'));
$this
->drupalLogin($admin);
$this
->drupalGet('messages/view/1');
$this
->assertText(t('This conversation is being viewed with escalated privileges and may not be the same as shown to normal users.'), t('Notice about read all mode displayed.'));
// Send a first response.
$admin_edit = array(
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost('messages/view/1', $admin_edit, t('Send message'));
// Make sure that the notice is not displayed anymore.
// @tod: Commented out because this does not work as expected.
$this
->assertNoText(t('This conversation is being viewed with escalated privileges and may not be the same as shown to normal users.'), t('Notice about read all mode not displayed.'));
// Make sure that both the existing message body and the new one are displayed.
$this
->assertText($edit['body[value]'], t('First message body displayed.'));
$this
->assertText($admin_edit['body[value]'], t('New message body displayed.'));
$admin_recipient_count = db_query("SELECT COUNT(*) FROM {pm_index} WHERE recipient = :recipient AND thread_id = :thread_id", array(
':recipient' => $admin->uid,
':thread_id' => 1,
))
->fetchField();
$this
->assertEqual($admin_recipient_count, 2, t('Admin is listed as recipient for every message once.'));
// Send a second response.
$admin_edit2 = array(
'body[value]' => $this
->randomName(100),
);
$this
->drupalPost('messages/view/1', $admin_edit2, t('Send message'));
// Make sure that both the existing message body and the new one are displayed.
$this
->assertText($edit['body[value]'], t('First message body displayed.'));
$this
->assertText($admin_edit['body[value]'], t('Second response body displayed.'));
$this
->assertText($admin_edit2['body[value]'], t('Third message body displayed.'));
$admin_recipient_count = db_query("SELECT COUNT(*) FROM {pm_index} WHERE recipient = :recipient AND thread_id = :thread_id", array(
':recipient' => $admin->uid,
':thread_id' => 1,
))
->fetchField();
$this
->assertEqual($admin_recipient_count, 3, t('Admin is listed as recipient for every message once.'));
}