Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
e9479dcf EM |
28 | /** |
29 | * Class CRM_Core_BAO_FinancialTrxnTest | |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
6a488035 | 32 | class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { |
00be9182 | 33 | public function setUp() { |
6a488035 TO |
34 | parent::setUp(); |
35 | } | |
36 | ||
37 | /** | |
78ab0ca4 | 38 | * Check method create(). |
6a488035 | 39 | */ |
00be9182 | 40 | public function testCreate() { |
92915c55 | 41 | $contactId = $this->individualCreate(); |
e6ff1593 | 42 | $financialTypeId = 1; |
78ab0ca4 | 43 | $this->contributionCreate(array( |
44 | 'contact_id' => $contactId, | |
45 | 'financial_type_id' => $financialTypeId, | |
46 | )); | |
92915c55 | 47 | $params = array( |
e6ff1593 | 48 | 'contribution_id' => $financialTypeId, |
6a488035 TO |
49 | 'to_financial_account_id' => 1, |
50 | 'trxn_date' => 20091021184930, | |
51 | 'trxn_type' => 'Debit', | |
52 | 'total_amount' => 10, | |
53 | 'net_amount' => 90.00, | |
54 | 'currency' => 'USD', | |
55 | 'payment_processor' => 'Dummy', | |
56 | 'trxn_id' => 'test_01014000', | |
57 | ); | |
58 | $FinancialTrxn = CRM_Core_BAO_FinancialTrxn::create($params); | |
59 | ||
60 | $result = $this->assertDBNotNull('CRM_Core_BAO_FinancialTrxn', $FinancialTrxn->id, | |
61 | 'total_amount', 'id', | |
62 | 'Database check on updated financial trxn record.' | |
63 | ); | |
64 | ||
65 | $this->assertEquals($result, 10, 'Verify financial trxn total_amount.'); | |
66 | } | |
96025800 | 67 | |
3efd9c58 | 68 | /** |
76c28c8d | 69 | * Test getTotalPayments function. |
3efd9c58 | 70 | */ |
76c28c8d DG |
71 | public function testGetTotalPayments() { |
72 | $contactId = $this->individualCreate(); | |
3efd9c58 DG |
73 | |
74 | $params = array( | |
75 | 'contact_id' => $contactId, | |
76 | 'currency' => 'USD', | |
77 | 'financial_type_id' => 1, | |
78 | 'contribution_status_id' => 2, | |
79 | 'payment_instrument_id' => 1, | |
80 | 'source' => 'STUDENT', | |
81 | 'is_pay_later' => 1, | |
82 | 'receive_date' => '20080522000000', | |
83 | 'receipt_date' => '20080522000000', | |
84 | 'non_deductible_amount' => 0.00, | |
85 | 'total_amount' => 200.00, | |
86 | 'fee_amount' => 5, | |
87 | 'net_amount' => 195, | |
88 | 'trxn_id' => '22ereerwwe4444yy', | |
89 | 'invoice_id' => '86ed39e9e9yy6ef6541621ce0eafe7eb81', | |
90 | 'thankyou_date' => '20080522', | |
91 | ); | |
92 | ||
76c28c8d | 93 | $contribution = CRM_Contribute_BAO_Contribution::create($params); |
3efd9c58 | 94 | |
76c28c8d DG |
95 | $this->assertEquals($params['trxn_id'], $contribution->trxn_id); |
96 | $this->assertEquals($contactId, $contribution->contact_id); | |
3efd9c58 DG |
97 | |
98 | $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id); | |
99 | $this->assertEquals(0, $totalPaymentAmount, 'Amount not matching.'); | |
100 | //update contribution amount | |
76c28c8d | 101 | $params['id'] = $contribution->id; |
3efd9c58 DG |
102 | $params['contribution_status_id'] = 1; |
103 | ||
76c28c8d | 104 | $contribution = CRM_Contribute_BAO_Contribution::create($params); |
3efd9c58 | 105 | |
76c28c8d DG |
106 | $this->assertEquals($params['trxn_id'], $contribution->trxn_id); |
107 | $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id); | |
3efd9c58 DG |
108 | |
109 | $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id); | |
110 | $this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.'); | |
3efd9c58 DG |
111 | } |
112 | ||
6a488035 | 113 | } |