You are here

function PrivatemsgLimitsTestCase::testNumberOfMessagesBlock in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_limits/privatemsg_limits.test \PrivatemsgLimitsTestCase::testNumberOfMessagesBlock()
  2. 7.2 privatemsg_limits/privatemsg_limits.test \PrivatemsgLimitsTestCase::testNumberOfMessagesBlock()

Tests for limiting the number of messages per thread.

File

privatemsg_limits/privatemsg_limits.test, line 412
This file contains tests for the privatemsg limits module

Class

PrivatemsgLimitsTestCase
Test cases for the privatemsg_limits module.

Code

function testNumberOfMessagesBlock() {
  $admin = $this
    ->drupalCreateUser(array(
    'administer privatemsg settings',
    'write privatemsg',
    'read privatemsg',
  ));
  $user = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));
  $this
    ->drupalLogin($admin);
  $settings = array(
    'privatemsg_limits_messages_per_thread' => 2,
    'privatemsg_limits_messages_per_thread_action' => 'block-message',
  );
  $this
    ->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));

  // Send a message to a user.
  $edit = array(
    'recipient' => $user->name,
    'subject' => $this
      ->randomName(20),
    'body[value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost('messages/new', $edit, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @recipients.', array(
    '@recipients' => $user->name,
  )));

  // Send a reply.
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('messages');
  $this
    ->clickLink($edit['subject']);
  $edit = array(
    'body[value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost(NULL, $edit, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @recipients.', array(
    '@recipients' => $admin->name,
  )));

  // Try to send another one.
  $edit = array(
    'body[value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost(NULL, $edit, t('Send message'));
  $this
    ->assertText(t("This message cannot be sent because the thread already contains @limit messages (the maximum number of messages permitted per thread). To send this message, please create a new message thread.", array(
    '@limit' => 2,
  )));
}