Skip to content

Commit

Permalink
CRM-2144 Ensure consistancy with previous behavior where user emails …
Browse files Browse the repository at this point in the history
…are first then system from emails.

Add unit test to try to verify order of emails

Fix issue where email was not being used as array key causing wrong email to be used
  • Loading branch information
seamuslee001 committed Mar 31, 2018
1 parent 569281b commit 669f45e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CRM/Core/BAO/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public static function getFromEmail() {
return $fromEmailValues;
}

$contactFromEmails = [];
// add logged in user's active email ids
$contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
if ($contactID) {
Expand All @@ -321,10 +322,10 @@ public static function getFromEmail() {
if (!empty($emailVal['is_primary'])) {
$fromEmailHtml .= ' ' . ts('(preferred)');
}
$fromEmailValues[$emailId] = $fromEmailHtml;
$contactFromEmails[$fromEmail] = $fromEmailHtml;
}
}
return $fromEmailValues;
return CRM_Utils_Array::crmArrayMerge($contactFromEmails, $fromEmailValues);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/phpunit/CRM/Core/BAO/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,22 @@ public function testAllEmails() {
$this->contactDelete($contactId);
}

/**
* Test getting list of Emails for use in Receipts and Single Email sends
*/
public function testGetFromEmail() {
$this->createLoggedInUser();
$fromEmails = CRM_Core_BAO_Email::getFromEmail();
$emails = array_values($fromEmails);
$this->assertContains("(preferred)", $emails[0]);
Civi::settings()->set("allow_mail_from_logged_in_contact", 0);
$this->callAPISuccess('system', 'flush', []);
$fromEmails = CRM_Core_BAO_Email::getFromEmail();
$emails = array_values($fromEmails);
$this->assertNotContains("(preferred)", $emails[0]);
$this->assertContains("info@EXAMPLE.ORG", $emails[0]);
Civi::settings()->set("allow_mail_from_logged_in_contact", 1);
$this->callAPISuccess('system', 'flush', []);
}

}

0 comments on commit 669f45e

Please sign in to comment.