You are here

function PrivatemsgLimitsTestCase::testNumberOfMessagesCreate in Privatemsg 7

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

Tests for limiting the number of messages per thread.

File

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

Class

PrivatemsgLimitsTestCase
Test cases for the privatemsg_limits module.

Code

function testNumberOfMessagesCreate() {
  $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' => 1,
    'privatemsg_limits_messages_per_thread_action' => 'create-new',
  );
  $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']);
  $reply = array(
    'body[value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost(NULL, $reply, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @recipients.', array(
    '@recipients' => $admin->name,
  )));

  // Make sure we are in a new thread and the original thread body isn't
  // displayed anymore.
  $this
    ->assertNoText($edit['body[value]']);
  $this
    ->assertText($reply['body[value]']);
}