You are here

public function SmtpUnitTest::testFailQueue in SMTP Authentication Support 7.2

Same name and namespace in other branches
  1. 7 tests/smtp.unit.test \SmtpUnitTest::testFailQueue()

Confirm the queue works.

File

tests/smtp.unit.test, line 123
Some tests for the SMTP module.

Class

SmtpUnitTest
@file Some tests for the SMTP module.

Code

public function testFailQueue() {

  // Turn on the queue failover.
  variable_set('smtp_queue_fail', TRUE);

  // Make sure the queue is disabled.
  variable_set('smtp_queue', FALSE);

  // Turn on email delivery.
  variable_set('smtp_deliver', TRUE);

  // Set some fake values for the delivery, it should fail and then cause the
  // email to go in to the queue.
  variable_set('smtp_from', 'drupal@example.com');
  variable_set('smtp_fromname', 'Drupal Simpletest');
  variable_set('smtp_host', 'smtp.gmail.com');
  variable_set('smtp_hostbackup', '');
  variable_set('smtp_password', 'THIS WILL NOT WORK!');
  variable_set('smtp_port', '465');
  variable_set('smtp_protocol', 'ssl');
  variable_set('smtp_username', 'hello@example.com');

  // Send a test message.
  $langcode = language_default('language');
  $sender = 'simpletest@example.com';
  $to_email = 'to_test@example.com';
  $reply_email = 'reply_test@example.com';
  $params = array();
  drupal_mail('smtp_tests', 'smtp_basic_test', $to_email, $langcode, $params);

  // Check the queue for messages.
  $queue_count = $this
    ->getQueueCount('smtp_failure_queue');
  $this
    ->assertEqual($queue_count, 1, 'An email was found in the failure queue.');
  $queue_count = $this
    ->getQueueCount();
  $this
    ->assertEqual($queue_count, 0, 'An email was not found in the regular email queue.');

  // Run the queue so that messages can be moved to the normal email queue.
  drupal_cron_run();

  // Check the queue for messages.
  $queue_count = $this
    ->getQueueCount();
  $this
    ->assertEqual($queue_count, 1, 'An email was found in the regular email queue.');
  $queue_count = $this
    ->getQueueCount('smtp_failure_queue');
  $this
    ->assertEqual($queue_count, 0, 'An email was not found in the failure queue.');
}