You are here

function MessageSubscribeSubscribersTest::testGetSubscribers in Message Subscribe 7

Test getting the subscribers list.

File

./message_subscribe.test, line 246
Test for the Message subscribe module.

Class

MessageSubscribeSubscribersTest
Test getting subscribes from context.

Code

function testGetSubscribers() {
  $message = message_create('foo', array(
    'uid' => $this->user1->uid,
  ));
  $node = $this->node;
  $user2 = $this->user2;
  $user_blocked = $this->user_blocked;
  $uids = message_subscribe_get_subscribers('node', $node, $message);

  // Assert subscribers data.
  $expected_uids = array(
    $user2->uid => array(
      'notifiers' => array(),
      'flags' => array(
        'subscribe_node',
        'subscribe_user',
      ),
    ),
  );
  $this
    ->assertEqual($uids, $expected_uids, 'All expected subscribers were fetched.');

  // Test none of users will get message if only blocked user is subscribed.
  $message = message_create('foo', array(
    'uid' => $this->user1->uid,
  ));
  $node1 = $this->node1;
  $uids = message_subscribe_get_subscribers('node', $node1, $message);

  // Assert subscribers data.
  $expected_uids = array();
  $this
    ->assertEqual($uids, $expected_uids, 'All expected subscribers were fetched.');

  // Test notifying all users, including those who are blocked.
  $subscribe_options['notify blocked users'] = TRUE;
  $uids = message_subscribe_get_subscribers('node', $node, $message, $subscribe_options);
  $expected_uids = array(
    $user2->uid => array(
      'notifiers' => array(),
      'flags' => array(
        'subscribe_node',
        'subscribe_user',
      ),
    ),
    $user_blocked->uid => array(
      'notifiers' => array(),
      'flags' => array(
        'subscribe_node',
      ),
    ),
  );
  $this
    ->assertEqual($uids, $expected_uids, 'All expected subscribers were fetched, including blocked users.');
  $user3 = $this
    ->drupalCreateUser(array(
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ));
  $user4 = $this
    ->drupalCreateUser(array(
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ));
  flag('flag', 'subscribe_node', $node->nid, $user3);
  flag('flag', 'subscribe_node', $node->nid, $user4);

  // Get subscribers from a given "last uid".
  $subscribe_options = array(
    'last uid' => $user2->uid,
  );
  $uids = message_subscribe_get_subscribers('node', $node, $message, $subscribe_options);
  $this
    ->assertEqual(array_keys($uids), array(
    $user3->uid,
    $user4->uid,
  ), 'All subscribers from "last uid" were fetched.');

  // Get a range of subscribers.
  $subscribe_options['range'] = 1;
  $uids = message_subscribe_get_subscribers('node', $node, $message, $subscribe_options);
  $this
    ->assertEqual(array_keys($uids), array(
    $user3->uid,
  ), 'All subscribers from "last uid" and "range" were fetched.');
}