You are here

function PrivatemsgFilterTestCase::testInboxSentHandling in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg_filter/privatemsg_filter.test \PrivatemsgFilterTestCase::testInboxSentHandling()
  2. 7.2 privatemsg_filter/privatemsg_filter.test \PrivatemsgFilterTestCase::testInboxSentHandling()
  3. 7 privatemsg_filter/privatemsg_filter.test \PrivatemsgFilterTestCase::testInboxSentHandling()

Test correct handling of read all permissions.

File

privatemsg_filter/privatemsg_filter.test, line 33

Class

PrivatemsgFilterTestCase
Test filters, tags and inbox/sent handling.

Code

function testInboxSentHandling() {
  $author = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
    'delete privatemsg',
  ));
  $recipient = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));

  // Create new message.
  $edit = array(
    'recipient' => $recipient->name,
    'subject' => $this
      ->randomName(20),
    'body' => $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'));

  // Validate that the message is not displayed in the inbox of the author
  // but in the sent list.
  $this
    ->drupalGet('messages');
  $this
    ->assertNoText($edit['subject'], t('Thread not displayed in inbox for author.'));
  $this
    ->drupalGet('messages/sent');
  $this
    ->assertText($edit['subject'], t('Thread displayed in "Sent messages" for author.'));
  $this
    ->drupalGet('messages/list');
  $this
    ->assertText($edit['subject'], t('Thread displayed in "All messages" for author.'));

  // Write a reply as recipient.
  $this
    ->drupalLogin($recipient);
  $this
    ->drupalGet('messages');
  $this
    ->assertText($edit['subject'], t('Thread displayed in inbox for recipient.'));
  $this
    ->drupalGet('messages/sent');
  $this
    ->assertNoText($edit['subject'], t('Thread not displayed in "Sent messages" for recipient.'));
  $this
    ->drupalGet('messages/list');
  $this
    ->assertText($edit['subject'], t('Thread displayed in "All messages." for recipient.'));

  // Navigate to the new message.
  $this
    ->clickLink($edit['subject']);
  $response = array(
    'body' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost(NULL, $response, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @recipients.', array(
    '@recipients' => $author->name,
  )), t('Message sent confirmation displayed'));
  $this
    ->drupalGet('messages/sent');
  $this
    ->assertText($edit['subject'], t('Thread displayed in "Sent messages" for recipient.'));
  $this
    ->drupalLogin($author);
  $this
    ->drupalGet('messages');
  $this
    ->assertText($edit['subject'], t('Thread displayed in inbox for author.'));

  // Test for bug http://drupal.org/node/617648
  // Delete all messages for author.
  $delete = array(
    'threads[1]' => 1,
  );
  $this
    ->drupalPost(NULL, $delete, t('Delete'));
  $this
    ->assertNoText($edit['subject'], t('Thread has been deleted for author.'));

  // Write a reply as recipient.
  $this
    ->drupalLogin($recipient);
  $this
    ->drupalGet('messages');

  // Navigate to the new message.
  $this
    ->clickLink($edit['subject']);
  $response = array(
    'body' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost(NULL, $response, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @recipients.', array(
    '@recipients' => $author->name,
  )), t('Message sent confirmation displayed'));

  // Check if thread is visible again for author.
  $this
    ->drupalLogin($author);
  $this
    ->drupalGet('messages');
  $this
    ->assertText($edit['subject'], t('Thread displayed again in inbox for author.'));
}