From 669f45efe5fdcdc424ff10fc601657ea1adc1023 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 31 Mar 2018 11:23:57 +1100 Subject: [PATCH] CRM-2144 Ensure consistancy with previous behavior where user emails 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 --- CRM/Core/BAO/Email.php | 5 +++-- tests/phpunit/CRM/Core/BAO/EmailTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CRM/Core/BAO/Email.php b/CRM/Core/BAO/Email.php index e78dc24af7..3cb40c5916 100644 --- a/CRM/Core/BAO/Email.php +++ b/CRM/Core/BAO/Email.php @@ -304,6 +304,7 @@ AND reset_date IS NULL return $fromEmailValues; } + $contactFromEmails = []; // add logged in user's active email ids $contactID = CRM_Core_Session::singleton()->getLoggedInContactID(); if ($contactID) { @@ -321,10 +322,10 @@ AND reset_date IS NULL if (!empty($emailVal['is_primary'])) { $fromEmailHtml .= ' ' . ts('(preferred)'); } - $fromEmailValues[$emailId] = $fromEmailHtml; + $contactFromEmails[$fromEmail] = $fromEmailHtml; } } - return $fromEmailValues; + return CRM_Utils_Array::crmArrayMerge($contactFromEmails, $fromEmailValues); } /** diff --git a/tests/phpunit/CRM/Core/BAO/EmailTest.php b/tests/phpunit/CRM/Core/BAO/EmailTest.php index 39c4d879eb..b2abc69c66 100644 --- a/tests/phpunit/CRM/Core/BAO/EmailTest.php +++ b/tests/phpunit/CRM/Core/BAO/EmailTest.php @@ -149,4 +149,22 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { $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', []); + } + } -- 2.25.1