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_FinancialTypeAccountTest
31 class CRM_Financial_BAO_FinancialTypeAccountTest
extends CiviUnitTestCase
{
33 public function setUp() {
35 $this->organizationCreate();
41 public function testAdd() {
43 'name' => 'TestFinancialAccount_1',
44 'accounting_code' => 4800,
52 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
53 $params['name'] = 'test_financialType1';
54 $financialType = CRM_Financial_BAO_FinancialType
::add($params, $ids);
55 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
56 $financialParams = array(
57 'entity_table' => 'civicrm_financial_type',
58 'entity_id' => $financialType->id
,
59 'account_relationship' => $relationTypeId,
60 'financial_account_id' => $financialAccount->id
,
63 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
64 $result = $this->assertDBNotNull(
65 'CRM_Financial_DAO_EntityFinancialAccount',
66 $financialAccount->id
,
68 'financial_account_id',
69 'Database check on added financial type record.'
71 $this->assertEquals($result, $financialType->id
, 'Verify Account Type');
77 public function testDel() {
79 'name' => 'TestFinancialAccount_2',
87 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
88 $params['name'] = 'test_financialType2';
89 $financialType = CRM_Financial_BAO_FinancialType
::add($params, $ids);
90 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
91 $financialParams = array(
92 'entity_table' => 'civicrm_financial_type',
93 'entity_id' => $financialType->id
,
94 'account_relationship' => $relationTypeId,
95 'financial_account_id' => $financialAccount->id
,
97 $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
98 CRM_Financial_BAO_FinancialTypeAccount
::del($financialAccountType->id
);
99 $params = array('id' => $financialAccountType->id
);
100 $result = CRM_Financial_BAO_FinancialType
::retrieve($params, $defaults);
101 $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
105 * Check method getFinancialAccount()
107 public function testRetrieve() {
109 'name' => 'TestFinancialAccount_3',
110 'is_deductible' => 0,
115 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
116 $params['name'] = 'test_financialType3';
117 $financialType = CRM_Financial_BAO_FinancialType
::add($params, $ids);
118 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
119 $financialParams = array(
120 'entity_table' => 'civicrm_financial_type',
121 'entity_id' => $financialType->id
,
122 'account_relationship' => $relationTypeId,
123 'financial_account_id' => $financialAccount->id
,
126 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
128 $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount
::retrieve($financialParams, $defaults);
129 $this->assertEquals($financialAccountType['entity_id'], $financialType->id
, 'Verify Entity Id.');
130 $this->assertEquals($financialAccountType['financial_account_id'], $financialAccount->id
, 'Verify Financial Account Id.');
134 * Check method getFinancialAccount()
136 public function testGetFinancialAccount() {
138 'name' => 'TestFinancialAccount',
139 'accounting_code' => 4800,
140 'is_deductible' => 0,
145 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
147 'financial_account_id' => $financialAccount->id
,
148 'payment_processor_type_id' => 1,
151 'name' => 'paymentProcessor',
153 $processor = CRM_Financial_BAO_PaymentProcessor
::create($params);
155 $account = CRM_Financial_BAO_FinancialTypeAccount
::getFinancialAccount(
157 'civicrm_payment_processor'
159 $this->assertEquals($account, 'TestFinancialAccount', 'Verify Financial Account Name');
163 * Check method getInstrumentFinancialAccount()
165 public function testGetInstrumentFinancialAccount() {
166 $paymentInstrumentValue = 1;
168 'name' => 'Donations',
169 'is_deductible' => 0,
173 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
174 $optionParams = array(
175 'name' => 'Credit Card',
176 'value' => $paymentInstrumentValue,
178 $optionValue = CRM_Core_BAO_OptionValue
::retrieve($optionParams, $defaults);
179 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
180 $financialParams = array(
181 'entity_table' => 'civicrm_option_value',
182 'entity_id' => $optionValue->id
,
183 'account_relationship' => $relationTypeId,
184 'financial_account_id' => $financialAccount->id
,
187 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
188 $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount($paymentInstrumentValue);
190 $this->assertEquals($financialAccountId, $financialAccount->id
, 'Verify Payment Instrument');