From 4fb4e64fed3fd39d5497410f5b1ec89f06956be7 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 18 Feb 2017 08:52:26 +1100 Subject: [PATCH] Fall back to system wide information if no default from email can be found and no contribution page can be used and no receipt from is passed in and add test to prove it --- CRM/Contribute/BAO/Contribution.php | 3 +++ tests/phpunit/api/v3/ContributionTest.php | 29 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 8a611f35ed..a6b72f66c7 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4747,6 +4747,9 @@ LIMIT 1;"; if (!empty($domain['from_email'])) { return array($domain['from_name'], $domain['from_email']); } + if (!empty($domain['domain_email'])) { + return array($domain['name'], $domain['domain_email']); + } $userID = CRM_Core_Session::singleton()->getLoggedInContactID(); $userName = ''; $userEmail = ''; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index c6b6627250..18040298ef 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -3427,7 +3427,6 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testSendMailWithRepeatTransactionAPIFalltoContributionPage() { $mut = new CiviMailUtils($this, TRUE); $contributionPage = $this->contributionPageCreate(array('receipt_from_name' => 'CiviCRM LLC', 'receipt_from_email' => 'contributionpage@civicrm.org', 'is_email_receipt' => 1)); - $params['contribution_page_id'] = $contributionPage['id']; $paymentProcessorID = $this->paymentProcessorCreate(); $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( 'contact_id' => $this->_individualId, @@ -3463,4 +3462,32 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut->stop(); } + /** + * Test sending a mail via the API. + */ + public function testSendMailWithRepeatTransactionAPIFalltoSystemFromNoDefaultFrom() { + $mut = new CiviMailUtils($this, TRUE); + $originalContribution = $contribution = $this->setUpRepeatTransaction(array(), 'single'); + $fromEmail = $this->CallAPISuccess('optionValue', 'get', array('is_default' => 1, 'option_group_id' => 'from_email_address', 'sequential' => 1)); + foreach ($fromEmail['values'] as $from) { + $this->callAPISuccess('optionValue', 'create', array('is_default' => 0, 'id' => $from['id'])); + } + $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => CRM_Core_Config::domainID())); + $this->callAPISuccess('contribution', 'repeattransaction', array( + 'contribution_status_id' => 'Completed', + 'trxn_id' => uniqid(), + 'original_contribution_id' => $originalContribution, + ) + ); + $mut->checkMailLog(array( + 'From: ' . $domain['name'] . ' <' . $domain['domain_email'] . '>', + 'Contribution Information', + 'Please print this confirmation for your records', + ), array( + 'Event', + ) + ); + $mut->stop(); + } + } -- 2.25.1