diff --git a/privatemsg.test b/privatemsg.test
index ed22447..e527f5d 100644
--- a/privatemsg.test
+++ b/privatemsg.test
@@ -76,7 +76,8 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
* Create user with 'read privatemsg' permission. Try to access mailbox and see if it gives allows access
*/
function testPrivatemsgReadPrivatemsgPermission() {
- $user_no_read_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
+ // Set up a user with the default permissions.
+ $user_no_read_msg = $this->drupalCreateUser();
$author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
$recipient = $this->drupalCreateUser(array('read privatemsg'));
$no_recipient = $this->drupalCreateUser(array('read privatemsg'));
@@ -112,12 +113,15 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
* Create user with 'write privatemsg' permission. Try to access Write New Message page and see if it gives allows access
*/
function testPrivatemsgWritePrivatemsgPermission() {
- $user_no_write_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
+ // Set up a user with the default permissions (no "read privatemsg"
+ // permission).
+ $user_no_write_msg = $this->drupalCreateUser();
$this->drupalLogin($user_no_write_msg);
$this->drupalGet('messages/new');
$this->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user without "write privatemsg" permission'));
- $user_write_msg = $this->drupalCreateUser(array('write privatemsg')); // set up user with write privatemsg permissions
+ // Set up a user with "write privatemsg" permissions.
+ $user_write_msg = $this->drupalCreateUser(array('write privatemsg'));
$this->drupalLogin($user_write_msg);
$this->drupalGet('messages/new');
$this->assertResponse(200, t('HTTP Response 200: Access to Write New Message page was authorized to user with "write privatemsg" permission'));
@@ -239,9 +243,13 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
*/
function testWriteReplyPrivatemsg() {
// Create a author and two recipients.
- $author = $this->drupalCreateUser(array('write privatemsg', 'select text format for privatemsg', filter_permission_name(filter_format_load('full_html'))));
+ $author = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'select text format for privatemsg', filter_permission_name(filter_format_load('full_html'))));
$recipient = $this->drupalCreateUser(array('read privatemsg'));
$recipient2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
+ // Set up a user with "read/write privatemsg" permissions.
+ $blocked_recipient = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
+ // Block this recipient to test users who cancelled their accounts.
+ user_save($blocked_recipient, array('status' => 0));
// Login author and go to new message form.
$this->drupalLogin($author);
@@ -265,12 +273,24 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
'subject' => $this->randomName(20),
'body[value]' => $this->randomName(100),
);
- // Invalid recipient
+ // Invalid recipient.
$editinvalid = array(
'recipient' => $this->randomName(5),
'subject' => $this->randomName(20),
'body[value]' => $this->randomName(100),
);
+ // Blocked recipient.
+ $editrecipientblocked = array(
+ 'recipient' => $blocked_recipient->name,
+ 'subject' => $this->randomName(20),
+ 'body[value]' => $this->randomName(100),
+ );
+ // Message for which the author will be blocked later.
+ $editauthorblocked = array(
+ 'recipient' => $recipient2->name,
+ 'subject' => $this->randomName(20),
+ 'body[value]' => $this->randomName(100),
+ );
// Empty body.
$editnobody = array(
'recipient' => $recipient->name,
@@ -324,6 +344,14 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
$this->assertText(t('You must include at least one valid recipient.'), 'Message was not sent.');
$this->assertText(t('The following recipients will not receive this private message: @recipients.', array('@recipients' => $editinvalid['recipient'])), 'Message about non-existing user displayed.');
+ $this->drupalPost('messages/new', $editrecipientblocked, t('Send message'));
+ $this->assertText(t('@recipients has disabled his or her account.', array('@recipients' => $blocked_recipient->name)), 'Message about blocked user displayed.');
+ $this->assertText(t('You are not allowed to send this message because all recipients are blocked.'), 'Message was not sent.');
+
+ // We will block the author later to test whether the reply form appears.
+ $this->drupalPost('messages/new', $editauthorblocked, t('Send message'));
+ $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
+
$this->drupalPost('messages/new', $editnobody, t('Send message'));
$this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
@@ -416,16 +444,28 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
$this->assertText($edit2['body[value]'], 'Found message body.');
// Confirm that we can read the reply that was sent.
$this->assertText($reply['body[value]'], 'Found reply body.');
- }
+ // Block the author.
+ user_save($author, array('status' => 0));
+ $this->drupalLogin($recipient2);
+ // Navigate into the message.
+ $this->drupalGet('messages');
+ $this->clickLink($editauthorblocked['subject']);
+ // Confirm that the reply form is not shown.
+ $this->assertNoText(t('Reply'), 'Reply form is not displayed.');
+ $this->assertText(t('You cannot reply to this conversation because all recipients have been blocked.'), 'All recipients blocked message is displayed.');
+ }
/**
* Test functionality around disabling private messaging.
*/
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
+ // Set up a user with "read/write privatemsg" permissions.
+ $enableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
+ // Set up a user with "read/write privatemsg" permissions.
+ $enableduser2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
+ // Set up a user with "read/write privatemsg" permissions.
+ $disableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'allow disabling privatemsg'));
// 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));