From: Dave Greenberg Date: Fri, 25 Dec 2015 00:44:23 +0000 (-0800) Subject: CRM-16259 - Addtional fixes from Eileen to deal with failure of new unit test. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=76c28c8de4f7e0064212fea8330b689bd9bffc04;p=civicrm-core.git CRM-16259 - Addtional fixes from Eileen to deal with failure of new unit test. ---------------------------------------- * CRM-16259: Create Payment API https://issues.civicrm.org/jira/browse/CRM-16259 --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index a784ba2c2c..1fa916f38d 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -141,6 +141,11 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } } } + else { + // Since the fee amount is expecting this (later on) ensure it is always set. + // It would only not be set for an update where it is unchanged. + $params['contribution_status_id'] = civicrm_api3('Contribution', 'getvalue', array('id' => $params['id'], 'return' => 'contribution_status_id')); + } //set defaults in create mode if (!$contributionID) { diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index d464559917..04de729343 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -421,7 +421,7 @@ WHERE ceft.entity_id = %1"; $params['trxnParams']['to_financial_account_id'] = $financialAccount; $params['trxnParams']['total_amount'] = $amount; $params['trxnParams']['fee_amount'] = $params['trxnParams']['net_amount'] = 0; - $params['trxnParams']['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); + $params['trxnParams']['status_id'] = $params['contribution_status_id']; $params['trxnParams']['contribution_id'] = $contributionId; $trxn = self::create($params['trxnParams']); if (empty($params['entity_id'])) { @@ -526,15 +526,17 @@ WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFina * @return array */ public static function getTotalPayments($contributionId) { - $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); - $sql = "SELECT SUM(ft.total_amount) FROM civicrm_financial_trxn ft - INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution') + $statusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); + + $sql = "SELECT SUM(ft.total_amount) FROM civicrm_financial_trxn ft + INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution') WHERE eft.entity_id = %1 AND ft.is_payment = 1 AND ft.status_id = %2"; $params = array( 1 => array($contributionId, 'Integer'), 2 => array($statusId, 'Integer'), ); + return CRM_Core_DAO::singleValueQuery($sql, $params); } diff --git a/CRM/Core/OptionGroup.php b/CRM/Core/OptionGroup.php index dcddadd583..55efe9cfd2 100644 --- a/CRM/Core/OptionGroup.php +++ b/CRM/Core/OptionGroup.php @@ -363,6 +363,10 @@ WHERE v.option_group_id = g.id } /** + * @deprecated + * + * This function is not cached. + * * @param string $groupName * @param $label * @param string $labelField diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 1c7f9d4d35..1ac600a5b6 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -84,6 +84,7 @@ function civicrm_api3_contribution_create(&$params) { _civicrm_api3_contribution_create_legacy_support_45($params); // Make sure tax calculation is handled via api. + // @todo this belongs in the BAO NOT the api. $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution'); diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index 85e7d914be..b36858bba8 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -67,12 +67,10 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { } /** - * Create() method (create and update modes). + * Test getTotalPayments function. */ - public function testIsPaymentFlagForPending() { - require_once 'CiviTest/Contact.php'; - $contactId = Contact::createIndividual(); - $ids = array('contribution' => NULL); + public function testGetTotalPayments() { + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -93,27 +91,24 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { 'thankyou_date' => '20080522', ); - $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids); + $contribution = CRM_Contribute_BAO_Contribution::create($params); - $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.'); - $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.'); + $this->assertEquals($params['trxn_id'], $contribution->trxn_id); + $this->assertEquals($contactId, $contribution->contact_id); $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id); $this->assertEquals(0, $totalPaymentAmount, 'Amount not matching.'); //update contribution amount - $ids = array('contribution' => $contribution->id); + $params['id'] = $contribution->id; $params['contribution_status_id'] = 1; - $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids); + $contribution = CRM_Contribute_BAO_Contribution::create($params); - $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id .'); - $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id, 'Check for status updation.'); + $this->assertEquals($params['trxn_id'], $contribution->trxn_id); + $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id); $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id); $this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.'); - //Delete Contribution - $this->contributionDelete($contribution->id); - Contact::delete($contactId); } }