You are here

function PrivatemsgLimitsTestCase::testRecipientsLimits in Privatemsg 7

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

Test limiting the number of recipients.

File

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

Class

PrivatemsgLimitsTestCase
Test cases for the privatemsg_limits module.

Code

function testRecipientsLimits() {
  $admin = $this
    ->drupalCreateUser(array(
    'administer privatemsg settings',
    'write privatemsg',
    'read privatemsg',
  ));
  $user1 = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));
  $user2 = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));
  $user3 = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));
  $this
    ->drupalLogin($admin);
  $settings = array(
    'privatemsg_limits_recipients_enabled' => TRUE,
    'privatemsg_limits_recipients_amount' => 1,
    'privatemsg_limits_recipients_amount_role_3' => 2,
  );
  $this
    ->drupalPost('admin/config/messaging/privatemsg/limits', $settings, t('Save configuration'));

  // Send a message to a single user.
  $edit = array(
    'recipient' => $user1->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' => $user1->name,
  )));

  // Send a message to two users.
  $edit = array(
    'recipient' => $user1->name . ', ' . $user2->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' => $user1->name . ', ' . $user2->name,
  )));

  // Try sending a message to three users.
  $edit = array(
    'recipient' => $user1->name . ', ' . $user2->name . ', ' . $user3->name,
    'subject' => $this
      ->randomName(20),
    'body[value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost('messages/new', $edit, t('Send message'));
  $this
    ->assertText(t('You are not allowed to send a message to more than @number recipients.', array(
    '@number' => 2,
  )), 'Not allowed message displayed.');

  // Login in as user.
  $this
    ->drupalLogin($user1);

  // Send a message to a single users.
  $edit = array(
    'recipient' => $user2->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' => $user2->name,
  )));

  // Try sending a message to two users.
  $edit = array(
    'recipient' => $user2->name . ', ' . $user3->name,
    'subject' => $this
      ->randomName(20),
    'body[value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost('messages/new', $edit, t('Send message'));
  $this
    ->assertText(t('You are not allowed to send a message to more than @number recipients.', array(
    '@number' => 1,
  )), 'Not allowed message displayed.');
}