Unverified Commit 1130d034 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub

Merge pull request #13455 from eileenmcnaughton/payment_email_test

Add unit test for emailing receipts from additional payment page
parents f72d5f51 ecddfe70
......@@ -386,8 +386,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
if (!empty($result) && !empty($this->_params['is_email_receipt'])) {
$this->_params['contact_id'] = $this->_contactId;
$this->_params['contribution_id'] = $this->_contributionId;
// to get 'from email id' for send receipt
$this->fromEmailId = $this->_params['from_email_address'];
$sendReceipt = $this->emailReceipt($this->_params);
if ($sendReceipt) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
......@@ -509,6 +508,11 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
public function emailReceipt(&$params) {
$templateEngine = CRM_Core_Smarty::singleton();
// email receipt sending
list($contributorDisplayName, $contributorEmail, $doNotMail) = CRM_Contact_BAO_Contact::getContactDetails($params['contact_id']);
if (!$contributorEmail || $doNotMail) {
return FALSE;
}
$templateEngine->assign('contactDisplayName', $contributorDisplayName);
// send message template
if ($this->_component == 'event') {
......@@ -550,7 +554,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
$templateEngine->assign('paymentAmount', $params['total_amount']);
$templateEngine->assign('paymentsComplete', $paymentsComplete);
}
$templateEngine->assign('contactDisplayName', $this->_contributorDisplayName);
// assign trxn details
$templateEngine->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $params));
......@@ -565,22 +568,15 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
$sendTemplateParams = array(
'groupName' => 'msg_tpl_workflow_contribution',
'valueName' => 'payment_or_refund_notification',
'contactId' => $this->_contactId,
'contactId' => $params['contact_id'],
'PDFFilename' => ts('notification') . '.pdf',
);
// try to send emails only if email id is present
// and the do-not-email option is not checked for that contact
if ($this->_contributorEmail && !$this->_toDoNotEmail) {
if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
$receiptFrom = $params['from_email_address'];
}
$sendTemplateParams['from'] = $params['from_email_address'];
$sendTemplateParams['toName'] = $contributorDisplayName;
$sendTemplateParams['toEmail'] = $contributorEmail;
$sendTemplateParams['from'] = $receiptFrom;
$sendTemplateParams['toName'] = $this->_contributorDisplayName;
$sendTemplateParams['toEmail'] = $this->_contributorEmail;
}
list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
list($mailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
return $mailSent;
}
......
......@@ -129,11 +129,22 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
* Test the submit function that completes the partially paid Contribution using Credit Card.
*/
public function testAddPaymentUsingCreditCardForPartialyPaidContribution() {
$mut = new CiviMailUtils($this, TRUE);
$this->createContribution('Partially paid');
// pay additional amount by using Credit Card
$this->submitPayment(70, 'live');
$this->submitPayment(70, 'live', TRUE);
$this->checkResults(array(30, 70), 2);
$mut->assertSubjects(['Payment Receipt -']);
$mut->checkMailLog([
'Dear Anthony Anderson',
'Payment Details',
'Total Fees: $ 100.00',
'This Payment Amount: $ 70.00',
'Balance Owed: $ 0.00 ',
]);
$mut->stop();
}
/**
......@@ -332,9 +343,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
* Payment Amount
* @param string $mode
* Mode of Payment
*
* @param bool $isEmailReceipt
*/
public function submitPayment($amount, $mode = NULL) {
public function submitPayment($amount, $mode = NULL, $isEmailReceipt = FALSE) {
$form = new CRM_Contribute_Form_AdditionalPayment();
$submitParams = array(
......@@ -347,10 +358,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
'receive_date_time' => '11:27PM',
'trxn_date' => '2017-04-11 13:05:11',
'payment_processor_id' => 0,
'is_email_receipt' => $isEmailReceipt,
'from_email_address' => 'site@something.com',
);
if ($mode) {
$submitParams += array(
'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments),
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
'credit_card_number' => '411111111111111',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment