function QueueMailTestCase::sendEmailAndTest in Queue Mail 7
Send an email and ensure it is queued or sent immediately.
Parameters
$mail_key: The key of the email to send.
$should_be_queued: Pass in TRUE to test if the email was queued, FALSE to test that it wasn't queued.
4 calls to QueueMailTestCase::sendEmailAndTest()
- QueueMailTestCase::testDoNotQueueMailedStoppedByOtherModules in ./
queue_mail.test - Test we don't send mail that is prevented from sending by other modules.
- QueueMailTestCase::testNonQueuedEmail in ./
queue_mail.test - Test that if we're not queuing any emails that they get sent as normal.
- QueueMailTestCase::testQueuedEmail in ./
queue_mail.test - Test that if we are queuing emails, that they get queued.
- QueueMailTestCase::testQueuedEmailKeyMatching in ./
queue_mail.test - This tests the matching of mailkeys to be queued.
File
- ./
queue_mail.test, line 105 - Simpletests for the Queue Mail module.
Class
- QueueMailTestCase
- Tests queue mail functionality.
Code
function sendEmailAndTest($mail_key = 'basic', $should_be_queued = TRUE, $should_be_sent = TRUE) {
$queue = _queue_mail_get_queue();
$queue_count_before = $queue
->numberOfItems();
$email_count_before = count($this
->drupalGetMails());
$content = $this
->randomName(32);
drupal_mail('queue_mail_test', $mail_key, 'info@example.com', language_default(), array(
'content' => $content,
));
$queue_count_after = $queue
->numberOfItems();
$email_count_after = count($this
->drupalGetMails());
// Now do the desired assertions.
if ($should_be_queued === TRUE) {
$this
->assertTrue($queue_count_after - $queue_count_before == 1, 'Email is queued.');
$this
->assertTrue($email_count_after - $email_count_before == 0, 'Queued email is not sent immediately.');
// Now run cron and see if our email gets sent.
$queue_count_before = $queue
->numberOfItems();
$email_count_before = count($this
->drupalGetMails());
$this
->cronRun();
$this
->assertMail('body', $content, 'Queued email content is sent.');
$queue_count_after = $queue
->numberOfItems();
$email_count_after = count($this
->drupalGetMails());
$this
->assertTrue($queue_count_after - $queue_count_before == -1, 'Email is sent from the queue.');
if ($should_be_sent) {
$this
->assertTrue($email_count_after - $email_count_before == 1, 'Queued email is sent on cron.');
}
else {
$this
->assertTrue($email_count_after - $email_count_before == 0, 'Queued email is not sent on cron.');
}
}
elseif ($should_be_queued === FALSE) {
$this
->assertTrue($queue_count_after - $queue_count_before == 0, 'Email is not queued.');
if ($should_be_sent) {
$this
->assertTrue($email_count_after - $email_count_before == 1, 'Email is sent immediately.');
$this
->assertMail('body', $content, 'Queued email content is sent.');
}
else {
$this
->assertTrue($email_count_after - $email_count_before == 0, 'Email is not sent immediately.');
}
}
}