-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from bugfolder/211_extra_mail_support
Issue #211: Add support for CC, BCC, Reply-to to “Send mail” actions.
- Loading branch information
Showing
3 changed files
with
146 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,30 @@ function rules_system_action_info() { | |
t('User <[email protected]>, Another User <[email protected]>'), | ||
))), | ||
), | ||
'cc' => array( | ||
'type' => 'text', | ||
'label' => t('CC'), | ||
'description' => t("CC recipient(s) (same form as To)"), | ||
'translatable' => TRUE, | ||
'optional' => TRUE, | ||
'allow null' => TRUE, | ||
), | ||
'bcc' => array( | ||
'type' => 'text', | ||
'label' => t('BCC'), | ||
'description' => t("BCC recipient(s) (same form as To)"), | ||
'translatable' => TRUE, | ||
'optional' => TRUE, | ||
'allow null' => TRUE, | ||
), | ||
'reply_to' => array( | ||
'type' => 'text', | ||
'label' => t('Reply-to'), | ||
'description' => t('Reply-to address (same for as To)'), | ||
'translatable' => TRUE, | ||
'optional' => TRUE, | ||
'allow null' => TRUE, | ||
), | ||
'subject' => array( | ||
'type' => 'text', | ||
'label' => t('Subject'), | ||
|
@@ -268,6 +292,30 @@ function rules_system_action_info() { | |
'options list' => 'entity_plus_metadata_user_roles', | ||
'description' => t('Select the roles whose users should receive the mail.'), | ||
), | ||
'cc' => array( | ||
'type' => 'text', | ||
'label' => t('CC'), | ||
'description' => t("CC recipient(s) (same form as To)"), | ||
'translatable' => TRUE, | ||
'optional' => TRUE, | ||
'allow null' => TRUE, | ||
), | ||
'bcc' => array( | ||
'type' => 'text', | ||
'label' => t('BCC'), | ||
'description' => t("BCC recipient(s) (same form as To)"), | ||
'translatable' => TRUE, | ||
'optional' => TRUE, | ||
'allow null' => TRUE, | ||
), | ||
'reply_to' => array( | ||
'type' => 'text', | ||
'label' => t('Reply-to'), | ||
'description' => t('Reply-to address (same for as To)'), | ||
'translatable' => TRUE, | ||
'optional' => TRUE, | ||
'allow null' => TRUE, | ||
), | ||
'subject' => array( | ||
'type' => 'text', | ||
'label' => t('Subject'), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
*/ | ||
class RulesTestCase extends BackdropWebTestCase { | ||
protected $normal_role; | ||
|
||
/** | ||
* Overrides BackdropWebTestCase::setUp(). | ||
*/ | ||
|
@@ -1396,6 +1396,30 @@ class RulesIntegrationTestCase extends BackdropWebTestCase { | |
config_set('rules.settings','rules_debug_log', 1); | ||
} | ||
|
||
/** | ||
* Asserts that the most recently sent email message has the given value in | ||
* the mail's headers. | ||
* | ||
* The field in $name must have the content described in $value. | ||
* | ||
* @param $name | ||
* Name of field or message property to assert. Examples: subject, body, id, ... | ||
* @param $value | ||
* Value of the field to assert. | ||
* @param $message | ||
* Message to display. | ||
* | ||
* @return | ||
* TRUE on pass, FALSE on fail. | ||
* | ||
* @see BackdropWebTestCase::assertMail() | ||
*/ | ||
protected function assertMailHeaders($name, $value = '', $message = '') { | ||
$captured_emails = state_get('test_email_collector', array()); | ||
$email = end($captured_emails); | ||
return $this->assertTrue($email && isset($email['headers'][$name]) && $email['headers'][$name] == $value, $message, t('Email')); | ||
} | ||
|
||
/** | ||
* Just makes sure the access callback run without errors. | ||
*/ | ||
|
@@ -2114,6 +2138,15 @@ class RulesIntegrationTestCase extends BackdropWebTestCase { | |
rules_action('mail', $settings + array('from' => '[email protected]'))->execute(); | ||
$this->assertMail('from', '[email protected]', 'Specified from address has been used'); | ||
|
||
rules_action('mail', $settings + array('cc' => '[email protected]'))->execute(); | ||
$this->assertMailHeaders('Cc', '[email protected]', 'Specified CC address has been used'); | ||
|
||
rules_action('mail', $settings + array('bcc' => '[email protected]'))->execute(); | ||
$this->assertMailHeaders('Bcc', '[email protected]', 'Specified BCC address has been used'); | ||
|
||
rules_action('mail', $settings + array('reply_to' => '[email protected]'))->execute(); | ||
$this->assertMailHeaders('Reply-to', '[email protected]', 'Specified Reply-to address has been used'); | ||
|
||
// Test sending mail to all users of a role. First clear the mail | ||
// collector to remove the mail sent in the previous line of code. | ||
state_set('test_email_collector', array()); | ||
|
@@ -2157,8 +2190,21 @@ class RulesIntegrationTestCase extends BackdropWebTestCase { | |
$mail = array_pop($mails); | ||
$this->assertTrue($mail['to'] == $user1->mail || $mail['to'] == $user2->mail, 'Mail to user of a role has been sent.'); | ||
|
||
// Execute action again and check that CC, BCC, and Reply-to were set. | ||
rules_action('mail_to_users_of_role', $settings + array( | ||
'roles' => $roles, | ||
'cc' => '[email protected]', | ||
'bcc' => '[email protected]', | ||
'reply_to' => '[email protected]', | ||
))->execute(); | ||
$mails = $this->backdropGetMails(); | ||
$mail = array_pop($mails); | ||
$this->assertTrue($mail['headers']['Cc'] == '[email protected]', 'Mail to user of a role has been sent with correct CC.'); | ||
$this->assertTrue($mail['headers']['Bcc'] == '[email protected]', 'Mail to user of a role has been sent with correct BCC.'); | ||
$this->assertTrue($mail['headers']['Reply-to'] == '[email protected]', 'Mail to user of a role has been sent with correct Reply-to.'); | ||
|
||
// Execute action again, this time to send mail to both roles. | ||
// This time check that three mails were sent - one for each user.. | ||
// This time check that three mails were sent - one for each user. | ||
state_set('test_email_collector', array()); | ||
rules_action('mail_to_users_of_role', $settings + array('roles' => array_merge($roles, $additional_roles)))->execute(); | ||
$mails = $this->backdropGetMails(); | ||
|