3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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_Financial_BAO_FinancialItemTest
32 class CRM_Financial_BAO_FinancialItemTest
extends CiviUnitTestCase
{
34 public function setUp() {
41 public function testAdd() {
43 $lastName = 'Whatson';
45 'first_name' => $firstName,
46 'last_name' => $lastName,
47 'contact_type' => 'Individual',
50 $contact = CRM_Contact_BAO_Contact
::add($params);
54 'contact_id' => $contact->id
,
55 'total_amount' => $price,
56 'financial_type_id' => 1,
62 $contribution = CRM_Contribute_BAO_Contribution
::add($cParams, $defaults);
64 'entity_id' => $contribution->id
,
65 'entity_table' => 'civicrm_contribution',
66 'price_field_id' => 1,
68 'label' => 'Contribution Amount',
69 'unit_price' => $price,
70 'line_total' => $price,
71 'price_field_value_id' => 1,
72 'financial_type_id' => 1,
75 $lineItem = CRM_Price_BAO_LineItem
::create($lParams);
76 CRM_Financial_BAO_FinancialItem
::add($lineItem, $contribution);
77 $result = $this->assertDBNotNull(
78 'CRM_Financial_DAO_FinancialItem',
82 'Database check on added financial item record.'
84 $this->assertEquals($result, $price, 'Verify Amount for Financial Item');
88 * Check method retrive()
90 public function testRetrieve() {
92 $lastName = 'Whatson';
94 'first_name' => $firstName,
95 'last_name' => $lastName,
96 'contact_type' => 'Individual',
99 $contact = CRM_Contact_BAO_Contact
::add($params);
102 'contact_id' => $contact->id
,
103 'total_amount' => $price,
104 'financial_type_id' => 1,
110 $contribution = CRM_Contribute_BAO_Contribution
::add($cParams, $defaults);
112 'entity_id' => $contribution->id
,
113 'entity_table' => 'civicrm_contribution',
114 'price_field_id' => 1,
116 'label' => 'Contribution Amount',
117 'unit_price' => $price,
118 'line_total' => $price,
119 'price_field_value_id' => 1,
120 'financial_type_id' => 1,
123 $lineItem = CRM_Price_BAO_LineItem
::create($lParams);
124 CRM_Financial_BAO_FinancialItem
::add($lineItem, $contribution);
127 'entity_id' => $lineItem->id
,
128 'entity_table' => 'civicrm_line_item',
130 $financialItem = CRM_Financial_BAO_FinancialItem
::retrieve($fParams, $values);
131 $this->assertEquals($financialItem->amount
, $price, 'Verify financial item amount.');
135 * Check method create()
137 public function testCreate() {
138 $firstName = 'Shane';
139 $lastName = 'Whatson';
141 'first_name' => $firstName,
142 'last_name' => $lastName,
143 'contact_type' => 'Individual',
146 $contact = CRM_Contact_BAO_Contact
::add($params);
149 'contact_id' => $contact->id
,
150 'total_amount' => $price,
151 'financial_type_id' => 1,
157 $contribution = CRM_Contribute_BAO_Contribution
::add($cParams, $defaults);
159 'entity_id' => $contribution->id
,
160 'entity_table' => 'civicrm_contribution',
161 'price_field_id' => 1,
163 'label' => 'Contribution Amount',
164 'unit_price' => $price,
165 'line_total' => $price,
166 'price_field_value_id' => 1,
167 'financial_type_id' => 1,
170 $lineItem = CRM_Price_BAO_LineItem
::create($lParams);
172 'contact_id' => $contact->id
,
173 'description' => 'Contribution Amount',
175 'financial_account_id' => 1,
177 'transaction_date' => date('YmdHis'),
178 'entity_id' => $lineItem->id
,
179 'entity_table' => 'civicrm_line_item',
182 CRM_Financial_BAO_FinancialItem
::create($fParams);
183 $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
184 $entityTrxn->entity_table
= 'civicrm_contribution';
185 $entityTrxn->entity_id
= $contribution->id
;
186 $entityTrxn->amount
= $price;
187 if ($entityTrxn->find(TRUE)) {
188 $entityId = $entityTrxn->entity_id
;
191 $result = $this->assertDBNotNull(
192 'CRM_Financial_DAO_FinancialItem',
196 'Database check on added financial item record.'
199 $this->assertEquals($result, $price, 'Verify Amount for Financial Item');
200 $entityResult = $this->assertDBNotNull(
201 'CRM_Financial_DAO_EntityFinancialTrxn',
205 'Database check on added entity financial trxn record.'
207 $this->assertEquals($entityResult, $price, 'Verify Amount for Financial Item');
213 public function testCreateEntityTrxn() {
215 'name' => 'Donations' . substr(sha1(rand()), 0, 7),
216 'is_deductible' => 0,
222 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($fParams, $ids);
223 $financialTrxn = new CRM_Financial_DAO_FinancialTrxn();
224 $financialTrxn->to_financial_account_id
= $financialAccount->id
;
225 $financialTrxn->total_amount
= $amount;
226 $financialTrxn->save();
228 'entity_table' => 'civicrm_contribution',
230 'financial_trxn_id' => $financialTrxn->id
,
234 $entityTrxn = CRM_Financial_BAO_FinancialItem
::createEntityTrxn($params);
235 $entityResult = $this->assertDBNotNull(
236 'CRM_Financial_DAO_EntityFinancialTrxn',
240 'Database check on added entity financial trxn record.'
242 $this->assertEquals($entityResult, $amount, 'Verify Amount for Financial Item');
247 * Check method retrieveEntityFinancialTrxn()
249 public function testRetrieveEntityFinancialTrxn() {
250 $entityTrxn = self
::testCreateEntityTrxn();
252 'entity_table' => 'civicrm_contribution',
254 'financial_trxn_id' => $entityTrxn->financial_trxn_id
,
255 'amount' => $entityTrxn->amount
,
258 CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($params);
259 $entityResult = $this->assertDBNotNull(
260 'CRM_Financial_DAO_EntityFinancialTrxn',
261 $entityTrxn->financial_trxn_id
,
264 'Database check on added entity financial trxn record.'
266 $this->assertEquals($entityResult, $entityTrxn->amount
, 'Verify Amount for Financial Item');
270 * Check method getPreviousFinancialItem().
272 public function testGetPreviousFinancialItem() {
273 $contactId = $this->individualCreate();
276 'contact_id' => $contactId,
278 'financial_type_id' => 1,
279 'contribution_status_id' => 1,
280 'payment_instrument_id' => 1,
281 'source' => 'STUDENT',
282 'receive_date' => '20160522000000',
283 'receipt_date' => '20160522000000',
284 'non_deductible_amount' => 0.00,
285 'total_amount' => 100.00,
286 'trxn_id' => '22ereerwww444444',
287 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81',
290 $contribution = CRM_Contribute_BAO_Contribution
::create($params);
293 'id' => $contribution->id
,
294 'total_amount' => 300.00,
297 $contribution = CRM_Contribute_BAO_Contribution
::create($params);
298 $financialItem = CRM_Financial_BAO_FinancialItem
::getPreviousFinancialItem($contribution->id
);
299 $params = array('id' => $financialItem->id
);
300 $financialItem = $this->callAPISuccess('FinancialItem', 'get', $params);
301 $this->assertEquals($financialItem['values'][$financialItem['id']]['amount'], 200.00, "The amounts do not match.");