tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / FinancialTrxnTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class CRM_Core_BAO_FinancialTrxnTest
30 */
31 class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
32 public function setUp() {
33 parent::setUp();
34 }
35
36 /**
37 * Check method create().
38 */
39 public function testCreate() {
40 $contactId = $this->individualCreate();
41 $financialTypeId = 1;
42 $this->contributionCreate(array(
43 'contact_id' => $contactId,
44 'financial_type_id' => $financialTypeId,
45 ));
46 $params = array(
47 'contribution_id' => $financialTypeId,
48 'to_financial_account_id' => 1,
49 'trxn_date' => 20091021184930,
50 'trxn_type' => 'Debit',
51 'total_amount' => 10,
52 'net_amount' => 90.00,
53 'currency' => 'USD',
54 'payment_processor' => 'Dummy',
55 'trxn_id' => 'test_01014000',
56 );
57 $FinancialTrxn = CRM_Core_BAO_FinancialTrxn::create($params);
58
59 $result = $this->assertDBNotNull('CRM_Core_BAO_FinancialTrxn', $FinancialTrxn->id,
60 'total_amount', 'id',
61 'Database check on updated financial trxn record.'
62 );
63
64 $this->assertEquals($result, 10, 'Verify financial trxn total_amount.');
65 }
66
67 /**
68 * Test getTotalPayments function.
69 */
70 public function testGetTotalPayments() {
71 $contactId = $this->individualCreate();
72
73 $params = array(
74 'contact_id' => $contactId,
75 'currency' => 'USD',
76 'financial_type_id' => 1,
77 'contribution_status_id' => 2,
78 'payment_instrument_id' => 1,
79 'source' => 'STUDENT',
80 'is_pay_later' => 1,
81 'receive_date' => '20080522000000',
82 'receipt_date' => '20080522000000',
83 'non_deductible_amount' => 0.00,
84 'total_amount' => 200.00,
85 'fee_amount' => 5,
86 'net_amount' => 195,
87 'trxn_id' => '22ereerwwe4444yy',
88 'invoice_id' => '86ed39e9e9yy6ef6541621ce0eafe7eb81',
89 'thankyou_date' => '20080522',
90 );
91
92 $contribution = CRM_Contribute_BAO_Contribution::create($params);
93
94 $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
95 $this->assertEquals($contactId, $contribution->contact_id);
96
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;
102
103 $contribution = CRM_Contribute_BAO_Contribution::create($params);
104
105 $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
106 $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id);
107
108 $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id);
109 $this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.');
110 }
111
112 }