From 0a5651eb79a6398eda24837b2b34b35e0e0de22c Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 12 Jan 2016 17:40:07 +0530 Subject: [PATCH] -- CRM-16259, added unit test for assignProportionalLineItems() ---------------------------------------- * CRM-16259: Create Payment API https://issues.civicrm.org/jira/browse/CRM-16259 --- .../CRM/Contribute/BAO/ContributionTest.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 5ceb984f7c..3257c89e90 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -636,13 +636,20 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { } /** - * Add() method (add and edit modes of participant) + * addPayments() method (add and edit modes of participant) */ public function testAddPayments() { list($lineItems, $contribution) = $this->addParticipantWithContribution(); foreach ($lineItems as $value) { CRM_Contribute_BAO_Contribution::addPayments($value, array($contribution)); } + $this->checkItemValues($contribution); + } + + /** + * checks db values for financial item + */ + public function checkItemValues($contribution) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType(4, $relationTypeId); $query = "SELECT eft1.entity_id, ft.total_amount, eft1.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') @@ -663,6 +670,23 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; Event::delete($this->_eventId); } + /** + * assignProportionalLineItems() method (add and edit modes of participant) + */ + public function testAssignProportionalLineItems() { + list($lineItems, $contribution) = $this->addParticipantWithContribution(); + $contributions['total_amount'] = $contribution->total_amount; + $params = array( + 'contribution_id' => $contribution->id, + 'total_amount' => 150.00, + ); + $trxn = new CRM_Financial_DAO_FinancialTrxn(); + $trxn->orderBy('id DESC'); + $trxn->find(TRUE); + CRM_Contribute_BAO_Contribution::assignProportionalLineItems($params, $trxn, $contributions); + $this->checkItemValues($contribution); + } + /** * Add participant with contribution * -- 2.25.1