From d891a27350adb239c786c02d0f26decaea9bb328 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 13 Mar 2017 10:54:13 +1300 Subject: [PATCH] CRM-20247 Add test & ensure $is_recur is assigned to the message_template. --- CRM/Contribute/BAO/Contribution.php | 20 +++----- tests/phpunit/api/v3/ContributionTest.php | 62 +++++++++++++++++++---- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 612d7f6d8f..a7a2537acb 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2426,7 +2426,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * messages * @throws Exception */ - public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $returnMessageText = TRUE) { + public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText = TRUE) { $this->loadRelatedObjects($input, $ids); if (empty($this->_component)) { @@ -2439,11 +2439,10 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $values['receipt_date'] = $input['receipt_date']; } - $template = CRM_Core_Smarty::singleton(); - $this->_assignMessageVariablesToTemplate($values, $input, $template, $recur, $returnMessageText); + $template = $this->_assignMessageVariablesToTemplate($values, $input, $returnMessageText); //what does recur 'mean here - to do with payment processor return functionality but // what is the importance - if ($recur && !empty($this->_relatedObjects['paymentProcessor'])) { + if (!empty($this->contribution_recur_id) && !empty($this->_relatedObjects['paymentProcessor'])) { $paymentObject = Civi\Payment\System::singleton()->getByProcessor($this->_relatedObjects['paymentProcessor']); $entityID = $entity = NULL; @@ -2552,7 +2551,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $values['is_pay_later'] = 1; } - if ($recur && $paymentObject) { + if (!empty($this->contribution_recur_id) && $paymentObject) { $url = $paymentObject->subscriptionURL($membership->id, 'membership', 'cancel'); $template->assign('cancelSubscriptionUrl', $url); $url = $paymentObject->subscriptionURL($membership->id, 'membership', 'billing'); @@ -2788,13 +2787,12 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * * @param $values * @param $input - * @param CRM_Core_SMARTY $template - * @param bool $recur * @param bool $returnMessageText * * @return mixed */ - public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = TRUE) { + public function _assignMessageVariablesToTemplate(&$values, $input, $returnMessageText = TRUE) { + $template = CRM_Core_Smarty::singleton(); $template->assign('first_name', $this->_relatedObjects['contact']->first_name); $template->assign('last_name', $this->_relatedObjects['contact']->last_name); $template->assign('displayName', $this->_relatedObjects['contact']->display_name); @@ -2889,7 +2887,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac ) ); $template->assign('is_monetary', 1); - $template->assign('is_recur', (bool) $recur); + $template->assign('is_recur', !empty($this->contribution_recur_id)); $template->assign('currency', $this->currency); $template->assign('address', CRM_Utils_Address::format($input)); if (!empty($values['customGroup'])) { @@ -4699,8 +4697,6 @@ LIMIT 1;"; * @param int $contributionID * @param array $values * Values related to objects that have already been loaded. - * @param bool $recur - * Is it part of a recurring contribution. * @param bool $returnMessageText * Should text be returned instead of sent. This. * is because the function is also used to generate pdfs @@ -4723,7 +4719,7 @@ LIMIT 1;"; if (!$returnMessageText) { list($values['receipt_from_name'], $values['receipt_from_email']) = self::generateFromEmailAndName($input, $contribution); } - $return = $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText); + $return = $contribution->composeMessageArray($input, $ids, $values, $returnMessageText); // Contribution ID should really always be set. But ? if (!$returnMessageText && (!isset($input['receipt_update']) || $input['receipt_update']) && empty($contribution->receipt_date)) { civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id)); diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 79b1926835..e01cb93a9d 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2428,16 +2428,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * CRM-1960 - Test to ensure that completetransaction respects the is_email_receipt setting */ public function testCompleteTransactionWithEmailReceiptInput() { - // Create a Contribution Page with is_email_receipt = TRUE - $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array( - 'receipt_from_name' => 'Mickey Mouse', - 'receipt_from_email' => 'mickey@mouse.com', - 'title' => "Test Contribution Page", - 'financial_type_id' => 1, - 'currency' => 'CAD', - 'is_monetary' => TRUE, - 'is_email_receipt' => TRUE, - )); + $contributionPage = $this->createReceiptableContributionPage(); + $this->_params['contribution_page_id'] = $contributionPage['id']; $params = array_merge($this->_params, array('contribution_status_id' => 2)); $contribution = $this->callAPISuccess('contribution', 'create', $params); @@ -2453,6 +2445,35 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals('', $receipt_date); } + /** + * Test that $is_recur is assigned to the receipt. + */ + public function testCompleteTransactionForRecurring() { + + $this->swapMessageTemplateForTestTemplate(); + $recurring = $this->setUpRecurringContribution(); + $contributionPage = $this->createReceiptableContributionPage(array('is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1)); + + $this->_params['contribution_page_id'] = $contributionPage['id']; + $this->_params['contribution_recur_id'] = $recurring['id']; + + $contribution = $this->setUpForCompleteTransaction(); + + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $contribution['id'], + 'trxn_date' => date('2011-04-09'), + 'trxn_id' => 'kazam', + 'is_email_receipt' => 1, + )); + + $this->mut->checkMailLog(array( + 'is_recur:::1', + 'cancelSubscriptionUrl:::http://dummy.com', + )); + $this->mut->stop(); + $this->revertTemplateToReservedTemplate(); + } + /** * Complete the transaction using the template with all the possible. */ @@ -3494,4 +3515,25 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $mut->stop(); } + /** + * Create a Contribution Page with is_email_receipt = TRUE. + * + * @param array $params + * Params to overwrite with. + * + * @return array|int + */ + protected function createReceiptableContributionPage($params = array()) { + $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array_merge(array( + 'receipt_from_name' => 'Mickey Mouse', + 'receipt_from_email' => 'mickey@mouse.com', + 'title' => "Test Contribution Page", + 'financial_type_id' => 1, + 'currency' => 'CAD', + 'is_monetary' => TRUE, + 'is_email_receipt' => TRUE, + ), $params)); + return $contributionPage; + } + } -- 2.25.1