3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Core_BAO_FinancialTrxnTest
31 class CRM_Core_BAO_FinancialTrxnTest
extends CiviUnitTestCase
{
32 public function setUp() {
37 * Check method create().
39 public function testCreate() {
40 $contactId = $this->individualCreate();
42 $this->contributionCreate(array(
43 'contact_id' => $contactId,
44 'financial_type_id' => $financialTypeId,
47 'contribution_id' => $financialTypeId,
48 'to_financial_account_id' => 1,
49 'trxn_date' => 20091021184930,
50 'trxn_type' => 'Debit',
52 'net_amount' => 90.00,
54 'payment_processor' => 'Dummy',
55 'trxn_id' => 'test_01014000',
57 $FinancialTrxn = CRM_Core_BAO_FinancialTrxn
::create($params);
59 $result = $this->assertDBNotNull('CRM_Core_BAO_FinancialTrxn', $FinancialTrxn->id
,
61 'Database check on updated financial trxn record.'
64 $this->assertEquals($result, 10, 'Verify financial trxn total_amount.');
68 * Test getTotalPayments function.
70 public function testGetTotalPayments() {
71 $contactId = $this->individualCreate();
74 'contact_id' => $contactId,
76 'financial_type_id' => 1,
77 'contribution_status_id' => 2,
78 'payment_instrument_id' => 1,
79 'source' => 'STUDENT',
81 'receive_date' => '20080522000000',
82 'receipt_date' => '20080522000000',
83 'non_deductible_amount' => 0.00,
84 'total_amount' => 200.00,
87 'trxn_id' => '22ereerwwe4444yy',
88 'invoice_id' => '86ed39e9e9yy6ef6541621ce0eafe7eb81',
89 'thankyou_date' => '20080522',
92 $contribution = CRM_Contribute_BAO_Contribution
::create($params);
94 $this->assertEquals($params['trxn_id'], $contribution->trxn_id
);
95 $this->assertEquals($contactId, $contribution->contact_id
);
97 $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn
::getTotalPayments($contribution->id
);
98 $this->assertEquals(0, $totalPaymentAmount, 'Amount not matching.');
99 //update contribution amount
100 $params['id'] = $contribution->id
;
101 $params['contribution_status_id'] = 1;
103 $contribution = CRM_Contribute_BAO_Contribution
::create($params);
105 $this->assertEquals($params['trxn_id'], $contribution->trxn_id
);
106 $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id
);
108 $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn
::getTotalPayments($contribution->id
);
109 $this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.');