public function MimeMailRulesTestCase::testMailToUserAction in Mime Mail 7
Create rule with "mimemail" action and fire it.
File
- tests/
mimemail_rules.test, line 57 - Functionality tests for the Rules integration in the Mime Mail module.
Class
- MimeMailRulesTestCase
- Tests the Rules integration.
Code
public function testMailToUserAction() {
$settings = array(
'key' => 'mail-key-' . $this
->randomName(),
'to' => $this
->randomName() . '@example.com',
'from' => $this
->randomName() . '@example.com',
'subject' => $this
->randomName(),
'body' => $this
->randomName(60) . '<div></div><br /><hr>',
'plaintext' => $this
->randomName(30) . '<div></div><br /><hr>',
);
// Set no language for the mail and check if the system default is used.
$rule = rule();
$rule
->action('mimemail', array(
'key' => $settings['key'],
'to' => $settings['to'],
'from_mail' => $settings['from'],
'subject' => $settings['subject'],
'body' => $settings['body'],
'plaintext' => $settings['plaintext'],
'language' => '',
))
->save();
$rule
->execute();
$mails = $this
->drupalGetMails(array(
'key' => $settings['key'],
));
$this
->assertEqual(count($mails), 1);
$mail = reset($mails);
$this
->assertEqual($mail['to'], $settings['to']);
$this
->assertEqual($mail['from'], $settings['from']);
$this
->assertEqual($mail['subject'], $settings['subject']);
$this
->assertEqual($mail['params']['context']['body'], $settings['body']);
$this
->assertEqual($mail['params']['plaintext'], $settings['plaintext']);
$this
->assertEqual($mail['language']->language, language_default('language'));
// Explicitly set another language for the mail.
$rule_action = $rule
->elementMap()
->lookup(3);
unset($rule_action->settings['language:select']);
$rule_action->settings['language'] = 'de';
$rule_action->settings['key'] = $settings['key'];
$rule
->save();
$rule
->execute();
$mails = $this
->drupalGetMails(array(
'key' => $settings['key'],
));
$this
->assertEqual(count($mails), 2);
$mail = end($mails);
$this
->assertEqual($mail['language']->language, 'de');
}