You are here

function MessageSubscribeEmailNotificationsTest::testEmailNotifications in Message Subscribe 7

Test opting in/out of default email notifications.

File

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

Class

MessageSubscribeEmailNotificationsTest
Test automatic email notification flagging.

Code

function testEmailNotifications() {

  // 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;
  $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',
      ),
    ),
  );
  $this
    ->assertEqual($uids, $expected_uids, 'All expected subscribers were fetched.');
  flag('unflag', 'subscribe_node', $node->nid, $user1);

  // Opt out of default email notifications.
  $wrapper = entity_metadata_wrapper('user', $user1);
  $wrapper->message_subscribe_email
    ->set(FALSE);
  flag('flag', 'subscribe_node', $node->nid, $user1);
  $uids = message_subscribe_get_subscribers('node', $node, $message);

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