From 3137781d03c0b140f79b1cb11590f40cb9bac2e7 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 4 Aug 2017 23:10:03 +0530 Subject: [PATCH] test build failure fix --- CRM/Core/BAO/FinancialTrxn.php | 16 +++++--------- CRM/Price/BAO/LineItem.php | 2 +- api/v3/FinancialTrxn.php | 2 +- .../CRM/Contribute/BAO/ContributionTest.php | 22 +++++-------------- tests/phpunit/CiviTest/CiviUnitTestCase.php | 1 - 5 files changed, 12 insertions(+), 31 deletions(-) diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index e14c607ec1..6ccafa5c9f 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -50,12 +50,9 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn { * @param array $params * (reference ) an assoc array of name/value pairs. * - * @param array $ids - * The array that holds all the DB ids. - * * @return CRM_Core_BAO_FinancialTrxn */ - public static function create(&$params, $ids = array()) { + public static function create(&$params) { $trxn = new CRM_Financial_DAO_FinancialTrxn(); $trxn->copyValues($params); @@ -63,18 +60,14 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn { $trxn->currency = CRM_Core_Config::singleton()->defaultCurrency; } - //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array - $financialTrxnID = CRM_Utils_Array::value('FinancialTrxn', $ids, CRM_Utils_Array::value('id', $params)); - $trxn->id = $financialTrxnID; - $trxn->save(); - // we shoudn't proceed further to record related entity financial trxns if it's update - if ($financialTrxnID) { + // We shoudn't proceed further to record related entity financial trxns if it's update. + if (!empty($params['id'])) { return $trxn; } - // save to entity_financial_trxn table + // Save to entity_financial_trxn table. $entityFinancialTrxnParams = array( 'entity_table' => CRM_Utils_Array::value('entity_table', $params, 'civicrm_contribution'), 'entity_id' => CRM_Utils_Array::value('entity_id', $params, CRM_Utils_Array::value('contribution_id', $params)), @@ -367,6 +360,7 @@ WHERE ceft.entity_id = %1"; 'total_amount' => CRM_Utils_Array::value('cost', $params) ? $params['cost'] : 0, 'currency' => CRM_Utils_Array::value('currency', $params), 'status_id' => array_search('Completed', $contributionStatuses), + 'entity_table' => 'civicrm_contribution', 'entity_id' => $params['contributionId'], ); CRM_Core_BAO_FinancialTrxn::create($financialtrxn); diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 81ea647c01..b100e71bb0 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -731,7 +731,7 @@ WHERE li.contribution_id = %1"; 'entity_id' => $newFinancialItem->id, 'entity_table' => 'civicrm_financial_item', )); - $reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues['financialTrxn']); + $reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues); // record reverse entity financial trxn linked to membership's related contribution civicrm_api3('EntityFinancialTrxn', 'create', array( 'entity_table' => "civicrm_contribution", diff --git a/api/v3/FinancialTrxn.php b/api/v3/FinancialTrxn.php index 23f19807cc..12058a157f 100644 --- a/api/v3/FinancialTrxn.php +++ b/api/v3/FinancialTrxn.php @@ -43,7 +43,7 @@ function civicrm_api3_financial_trxn_create($params) { throw new API_Exception("Mandatory key(s) missing from params array: both contribution_id and entity_id are missing"); } - return _civicrm_api3_basic_create('CRM_Core_BAO_FinancialTrxn', $params, 'FinancialTrxn'); + return _civicrm_api3_basic_create('CRM_Core_BAO_FinancialTrxn', $params); } /** diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index a39b1d306e..a43d94a493 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -1058,15 +1058,9 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; 'payment_instrument_id' => 1, 'trxn_date' => date('Ymd'), 'status_id' => 1, - ); - $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); - $params = array( - 'amount' => 50, - 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], - 'financial_trxn_id' => $financialTrxn['id'], ); - $this->callAPISuccess('EntityFinancialTrxn', 'create', $params); + $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); $entityParams = array( 'contribution_total_amount' => $contribution['total_amount'], 'trxn_total_amount' => 55, @@ -1076,11 +1070,11 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $eftParams = array( 'entity_table' => 'civicrm_financial_item', 'entity_id' => $previousLineItem['id'], - 'financial_trxn_id' => $financialTrxn['id'], + 'financial_trxn_id' => (string) $financialTrxn['id'], ); CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams); $trxnTestArray = array_merge($eftParams, array( - 'amount' => 50, + 'amount' => '50.00', )); $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray); } @@ -1104,20 +1098,14 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; public function testcreateProportionalFinancialEntries() { list($contribution, $financialAccount) = $this->createContributionWithTax(); $params = array( - 'total_amount' => 55, + 'total_amount' => 50, 'to_financial_account_id' => $financialAccount->financial_account_id, 'payment_instrument_id' => 1, 'trxn_date' => date('Ymd'), 'status_id' => 1, - ); - $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); - $params = array( - 'amount' => 50, - 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], - 'financial_trxn_id' => $financialTrxn['id'], ); - $this->callAPISuccess('EntityFinancialTrxn', 'create', $params); + $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); $entityParams = array( 'contribution_total_amount' => $contribution['total_amount'], 'trxn_total_amount' => 55, diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c94d2bdc0f..e434936742 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -897,7 +897,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { public function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) { $params += array( 'version' => $this->_apiversion, - 'debug' => 1, ); $result = $this->civicrm_api($entity, 'getsingle', $params); if (!is_array($result) || !empty($result['is_error']) || isset($result['values'])) { -- 2.25.1