3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviUnitTestCase.php';
30 * Class CRM_Financial_BAO_FinancialTypeAccountTest
32 class CRM_Financial_BAO_FinancialTypeAccountTest
extends CiviUnitTestCase
{
34 public function setUp() {
36 $this->organizationCreate();
42 public function testAdd() {
44 'name' => 'TestFinancialAccount_1',
45 'accounting_code' => 4800,
53 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
54 $params['name'] = 'test_financialType1';
55 $financialType = CRM_Financial_BAO_FinancialType
::add($params, $ids);
56 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
57 $financialParams = array(
58 'entity_table' => 'civicrm_financial_type',
59 'entity_id' => $financialType->id
,
60 'account_relationship' => $relationTypeId,
61 'financial_account_id' => $financialAccount->id
,
64 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
65 $result = $this->assertDBNotNull(
66 'CRM_Financial_DAO_EntityFinancialAccount',
67 $financialAccount->id
,
69 'financial_account_id',
70 'Database check on added financial type record.'
72 $this->assertEquals($result, $financialType->id
, 'Verify Account Type');
78 public function testDel() {
80 'name' => 'TestFinancialAccount_2',
88 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
89 $params['name'] = 'test_financialType2';
90 $financialType = CRM_Financial_BAO_FinancialType
::add($params, $ids);
91 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
92 $financialParams = array(
93 'entity_table' => 'civicrm_financial_type',
94 'entity_id' => $financialType->id
,
95 'account_relationship' => $relationTypeId,
96 'financial_account_id' => $financialAccount->id
,
98 $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
99 CRM_Financial_BAO_FinancialTypeAccount
::del($financialAccountType->id
);
100 $params = array('id' => $financialAccountType->id
);
101 $result = CRM_Financial_BAO_FinancialType
::retrieve($params, $defaults);
102 $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
106 * Check method getFinancialAccount()
108 public function testRetrieve() {
110 'name' => 'TestFinancialAccount_3',
111 'is_deductible' => 0,
116 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
117 $params['name'] = 'test_financialType3';
118 $financialType = CRM_Financial_BAO_FinancialType
::add($params, $ids);
119 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
120 $financialParams = array(
121 'entity_table' => 'civicrm_financial_type',
122 'entity_id' => $financialType->id
,
123 'account_relationship' => $relationTypeId,
124 'financial_account_id' => $financialAccount->id
,
127 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
129 $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount
::retrieve($financialParams, $defaults);
130 $this->assertEquals($financialAccountType['entity_id'], $financialType->id
, 'Verify Entity Id.');
131 $this->assertEquals($financialAccountType['financial_account_id'], $financialAccount->id
, 'Verify Financial Account Id.');
135 * Check method getFinancialAccount()
137 public function testGetFinancialAccount() {
139 'name' => 'TestFinancialAccount',
140 'accounting_code' => 4800,
141 'is_deductible' => 0,
146 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
148 'financial_account_id' => $financialAccount->id
,
149 'payment_processor_type_id' => 1,
152 'name' => 'paymentProcessor',
154 $processor = CRM_Financial_BAO_PaymentProcessor
::create($params);
156 $account = CRM_Financial_BAO_FinancialTypeAccount
::getFinancialAccount(
158 'civicrm_payment_processor'
160 $this->assertEquals($account, 'TestFinancialAccount', 'Verify Financial Account Name');
164 * Check method getInstrumentFinancialAccount()
166 public function testGetInstrumentFinancialAccount() {
167 $paymentInstrumentValue = 1;
169 'name' => 'Donations',
170 'is_deductible' => 0,
174 $financialAccount = CRM_Financial_BAO_FinancialAccount
::add($params, $ids);
175 $optionParams = array(
176 'name' => 'Credit Card',
177 'value' => $paymentInstrumentValue,
179 $optionValue = CRM_Core_BAO_OptionValue
::retrieve($optionParams, $defaults);
180 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
181 $financialParams = array(
182 'entity_table' => 'civicrm_option_value',
183 'entity_id' => $optionValue->id
,
184 'account_relationship' => $relationTypeId,
185 'financial_account_id' => $financialAccount->id
,
188 CRM_Financial_BAO_FinancialTypeAccount
::add($financialParams, $ids);
189 $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount($paymentInstrumentValue);
191 $this->assertEquals($financialAccountId, $financialAccount->id
, 'Verify Payment Instrument');