You are here

public function UserRelationshipsPrivatemsgRecipientTestCase::testManyRelations in User Relationships 7

Test a relationship with bath api processing.

File

user_relationship_privatemsg/user_relationship_privatemsg.test, line 219
User relationship privatemsg tests.

Class

UserRelationshipsPrivatemsgRecipientTestCase
Tests cases to send messages to related users.

Code

public function testManyRelations() {

  // Create relationship.
  $relationship = array(
    'name' => $this
      ->randomName(),
    'machine_name' => strtolower($this
      ->randomName()),
    'plural_name' => $this
      ->randomName(),
    'requires_approval' => FALSE,
    'expires_val' => 0,
  );
  user_relationships_type_save((object) $relationship);

  // Flush permission cache.
  drupal_static_reset('user_relationships_types_load');
  $this
    ->checkPermissions(array(), TRUE);
  $have_permission = 'can have ' . $relationship['machine_name'] . ' relationships';
  $request_permission = 'can request ' . $relationship['machine_name'] . ' relationships';
  $maintain_permission = 'maintain ' . $relationship['machine_name'] . ' relationships';
  $admin = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
    $have_permission,
    $request_permission,
    'view relationship recipients',
    'administer user relationships',
    $maintain_permission,
    'write privatemsg to relationships',
    'access user profiles',
  ));
  $this
    ->drupalLogin($admin);

  // Create 25 users (more than are allowed to be process directly) and relate
  // them to the admin.
  $users = array();
  for ($i = 0; $i < 25; $i++) {
    $users[$i] = $this
      ->drupalCreateUser(array(
      'read privatemsg',
      'write privatemsg',
      $have_permission,
      $request_permission,
      'view relationship recipients',
      'write privatemsg to relationships',
    ));

    // Become related to that user.
    $this
      ->drupalGet('relationship/' . $users[$i]->uid . '/request/1');
    $this
      ->drupalPost(NULL, array(), t('Send'));
  }
  variable_set('privatemsg_recipient_small_threshold', 20);

  // Send a message to related users.
  $this
    ->drupalGet('messages/new');
  $this
    ->assertText(t('Enter the name of a user relationship to write a message to all related users. Example: @relationship.', array(
    '@relationship' => $relationship['plural_name'],
  )), t('Description is displayed.'));
  $message = array(
    'recipient' => $relationship['plural_name'],
    'subject' => $this
      ->randomName(),
    'body[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalPost(NULL, $message, t('Send message'));
  $this
    ->assertText(t('A message has been sent to your @relationship.', array(
    '@relationship' => $relationship['plural_name'],
  )));

  // Test if all recipients see the message.
  foreach ($users as $user) {
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet('messages');
    $this
      ->clickLink($message['subject']);
    $this
      ->assertText($message['body[value]']);
  }
}