diff --git a/privatemsg.module b/privatemsg.module index 2ac06e3..f2f2071 100755 --- a/privatemsg.module +++ b/privatemsg.module @@ -1462,6 +1462,13 @@ function privatemsg_privatemsg_block_message($author, $recipients, $context = ar 'message' => t('%recipient has disabled private message receiving.', array('%recipient' => privatemsg_recipient_format($recipient, array('plain' => TRUE)))), ); } + // Do not send private messages to blocked users. + else if (isset($recipient->status) && (!$recipient->status)) { + $blocked[] = array( + 'recipient' => 'user_' . $recipient->uid, + 'message' => t('%recipient has disabled his or her account.', array('%recipient' => privatemsg_recipient_format($recipient, array('plain' => TRUE)))), + ); + } } return $blocked; diff --git a/privatemsg.test b/privatemsg.test index ed22447..5483c6a 100644 --- a/privatemsg.test +++ b/privatemsg.test @@ -238,10 +238,14 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { * Test sending message from the /messages/new page between two people */ 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')))); + // Create an author and two recipients. + $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 +269,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 +340,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' => $recipient2->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,8 +440,17 @@ 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 can not reply to this conversation because all recipients are blocked.')); + } /** * Test functionality around disabling private messaging. */