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_Financial_BAO_FinancialItemTest
31 class CRM_Financial_BAO_FinancialItemTest
extends CiviUnitTestCase
{
33 public function setUp() {
40 public function testAdd() {
42 $lastName = 'Whatson';
44 'first_name' => $firstName,
45 'last_name' => $lastName,
46 'contact_type' => 'Individual',
49 $contact = CRM_Contact_BAO_Contact
::add($params);
53 'contact_id' => $contact->id
,
54 'total_amount' => $price,
55 'financial_type_id' => 1,
61 $contribution = CRM_Contribute_BAO_Contribution
::add($cParams, $defaults);
63 'entity_id' => $contribution->id
,
64 'entity_table' => 'civicrm_contribution',
65 'price_field_id' => 1,
67 'label' => 'Contribution Amount',
68 'unit_price' => $price,
69 'line_total' => $price,
70 'price_field_value_id' => 1,
71 'financial_type_id' => 1,
74 $lineItem = CRM_Price_BAO_LineItem
::create($lParams);
75 CRM_Financial_BAO_FinancialItem
::add($lineItem, $contribution);
76 $result = $this->assertDBNotNull(
77 'CRM_Financial_DAO_FinancialItem',
81 'Database check on added financial item record.'
83 $this->assertEquals($result, $price, 'Verify Amount for Financial Item');
87 * Check method retrive()
89 public function testRetrieve() {
91 $lastName = 'Whatson';
93 'first_name' => $firstName,
94 'last_name' => $lastName,
95 'contact_type' => 'Individual',
98 $contact = CRM_Contact_BAO_Contact
::add($params);
101 'contact_id' => $contact->id
,
102 'total_amount' => $price,
103 'financial_type_id' => 1,
109 $contribution = CRM_Contribute_BAO_Contribution
::add($cParams, $defaults);
111 'entity_id' => $contribution->id
,
112 'entity_table' => 'civicrm_contribution',
113 'price_field_id' => 1,
115 'label' => 'Contribution Amount',
116 'unit_price' => $price,
117 'line_total' => $price,
118 'price_field_value_id' => 1,
119 'financial_type_id' => 1,
122 $lineItem = CRM_Price_BAO_LineItem
::create($lParams);
123 CRM_Financial_BAO_FinancialItem
::add($lineItem, $contribution);
126 'entity_id' => $lineItem->id
,
127 'entity_table' => 'civicrm_line_item',
129 $financialItem = CRM_Financial_BAO_FinancialItem
::retrieve($fParams, $values);
130 $this->assertEquals($financialItem->amount
, $price, 'Verify financial item amount.');
134 * Check method create()
136 public function testCreate() {
137 $firstName = 'Shane';
138 $lastName = 'Whatson';
140 'first_name' => $firstName,
141 'last_name' => $lastName,
142 'contact_type' => 'Individual',
145 $contact = CRM_Contact_BAO_Contact
::add($params);
148 'contact_id' => $contact->id
,
149 'total_amount' => $price,
150 'financial_type_id' => 1,
156 $contribution = CRM_Contribute_BAO_Contribution
::add($cParams, $defaults);
158 'entity_id' => $contribution->id
,
159 'entity_table' => 'civicrm_contribution',
160 'price_field_id' => 1,
162 'label' => 'Contribution Amount',
163 'unit_price' => $price,
164 'line_total' => $price,
165 'price_field_value_id' => 1,
166 'financial_type_id' => 1,
169 $lineItem = CRM_Price_BAO_LineItem
::create($lParams);
171 'contact_id' => $contact->id
,
172 'description' => 'Contribution Amount',
174 'financial_account_id' => 1,
176 'transaction_date' => date('YmdHis'),
177 'entity_id' => $lineItem->id
,
178 'entity_table' => 'civicrm_line_item',
181 CRM_Financial_BAO_FinancialItem
::create($fParams);
182 $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
183 $entityTrxn->entity_table
= 'civicrm_contribution';
184 $entityTrxn->entity_id
= $contribution->id
;
185 $entityTrxn->amount
= $price;
186 if ($entityTrxn->find(TRUE)) {
187 $entityId = $entityTrxn->entity_id
;
190 $result = $this->assertDBNotNull(
191 'CRM_Financial_DAO_FinancialItem',
195 'Database check on added financial item record.'
198 $this->assertEquals($result, $price, 'Verify Amount for Financial Item');
199 $entityResult = $this->assertDBNotNull(
200 'CRM_Financial_DAO_EntityFinancialTrxn',
204 'Database check on added entity financial trxn record.'
206 $this->assertEquals($entityResult, $price, 'Verify Amount for Financial Item');
212 public function testCreateEntityTrxn() {
214 'name' => 'Donations' . substr(sha1(rand()), 0, 7),
215 'is_deductible' => 0,
221 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($fParams, $ids);
222 $financialTrxn = new CRM_Financial_DAO_FinancialTrxn();
223 $financialTrxn->to_financial_account_id
= $financialAccount->id
;
224 $financialTrxn->total_amount
= $amount;
225 $financialTrxn->save();
227 'entity_table' => 'civicrm_contribution',
229 'financial_trxn_id' => $financialTrxn->id
,
233 $entityTrxn = CRM_Financial_BAO_FinancialItem
::createEntityTrxn($params);
234 $entityResult = $this->assertDBNotNull(
235 'CRM_Financial_DAO_EntityFinancialTrxn',
239 'Database check on added entity financial trxn record.'
241 $this->assertEquals($entityResult, $amount, 'Verify Amount for Financial Item');
246 * Check method retrieveEntityFinancialTrxn()
248 public function testRetrieveEntityFinancialTrxn() {
249 $entityTrxn = self
::testCreateEntityTrxn();
251 'entity_table' => 'civicrm_contribution',
253 'financial_trxn_id' => $entityTrxn->financial_trxn_id
,
254 'amount' => $entityTrxn->amount
,
257 CRM_Financial_BAO_FinancialItem
::retrieveEntityFinancialTrxn($params);
258 $entityResult = $this->assertDBNotNull(
259 'CRM_Financial_DAO_EntityFinancialTrxn',
260 $entityTrxn->financial_trxn_id
,
263 'Database check on added entity financial trxn record.'
265 $this->assertEquals($entityResult, $entityTrxn->amount
, 'Verify Amount for Financial Item');