You are here

function InactiveUserTest::testInactiveUserNotification in Inactive User 6

Same name and namespace in other branches
  1. 7 inactive_user.test \InactiveUserTest::testInactiveUserNotification()

Check inactive user and administrator notifications are working

File

./inactive_user.test, line 39
Test the basic functions of the Inactive User module.

Class

InactiveUserTest
Inactive user module testcase.

Code

function testInactiveUserNotification() {

  // Change user and admin notify options:
  // Notify user about one weeks of inactivity.
  // Notify admin about two week of inactivity
  $settings = array(
    'inactive_user_admin_email' => 'test@email.com',
    'inactive_user_notify' => '604800',
    'inactive_user_notify_admin' => '1209600',
  );
  $this
    ->inactiveUserSettings($settings);

  // Create an inactive user for more than a week.
  $inactive = $this
    ->drupalCreateInactiveUser(604800 + 3600);

  // Perform inactive validations
  $this
    ->checkInactiveAccounts();

  // One email should have been sent to the inactive user.
  $emails = $this
    ->drupalGetMails();
  $this
    ->assertEqual(count($emails), 1, t('Only one email has been sent for this inactivity validation.'));

  // Get the last email, and verify it was sent to user's email address
  $notification = array_pop($emails);
  $this
    ->assertEqual($notification['to'], $inactive->mail, t('User has been notified of its inactiviy period.'));

  // Create an inactive user for more than two weeks
  $inactive = $this
    ->drupalCreateInactiveUser(1209600 + 3600);

  // Perform inactive validations
  $this
    ->checkInactiveAccounts();

  // Two emails should have been sent: one for the user, other for the admin.
  // Note that the other inactive user has already been notified, and should
  // not generate any more emails.
  $emails = $this
    ->drupalGetMails();
  $this
    ->assertEqual(count($emails), 3, t('Two new emails have been sent for this inactivity validation.'));

  // Get the last email, and verify it was sent to user's email address
  $notification = array_pop($emails);
  $this
    ->assertEqual($notification['to'], $inactive->mail, t('User has been notified of its inactiviy period.'));

  // Get the other email, and verify it was sent to admin's email address
  $notification = array_pop($emails);
  $this
    ->assertEqual($notification['to'], $settings['inactive_user_admin_email'], t('Administrator has been notified of inactive users.'));
}