You are here

function MessageSubscribeEmailSubscribersTest::testGetSubscribers in Message Subscribe 7

Test getting the subscribers list.

File

message_subscribe_email/message_subscribe_email.test, line 100
Test for the Message subscribe email module.

Class

MessageSubscribeEmailSubscribersTest
Test getting email subscribes from context.

Code

function testGetSubscribers() {

  // Make sure we are notifying ourselves for this test.
  variable_set('message_subscribe_notify_own_actions', TRUE);
  $message = message_create('foo');
  $node = $this->node;
  $user1 = $this->user1;
  $user2 = $this->user2;
  $uids = message_subscribe_get_subscribers('node', $node, $message);

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

  // Assert sent emails.
  $email_count = count(variable_get('drupal_test_email_collector', array()));
  $this
    ->assertEqual($email_count, 1, 'Only one user was sent an email.');
}