Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
6a488035 TO |
28 | |
29 | class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { | |
30 | ||
31 | function get_info() { | |
32 | return array( | |
f17d75bb | 33 | 'name' => 'FinancialTypeAccount BAOs', |
6a488035 | 34 | 'description' => 'Test all Contribute_BAO_Contribution methods.', |
f17d75bb | 35 | 'group' => 'CiviCRM BAO Tests', |
6a488035 TO |
36 | ); |
37 | } | |
38 | ||
39 | function setUp() { | |
40 | parent::setUp(); | |
f17d75bb | 41 | $this->organizationCreate(); |
6a488035 TO |
42 | } |
43 | ||
44 | /** | |
45 | * check method add() | |
46 | */ | |
47 | function testAdd() { | |
48 | $params = array( | |
49 | 'name' => 'TestFinancialAccount_1', | |
50 | 'accounting_code' => 4800, | |
51 | 'contact_id' => 1, | |
52 | 'is_deductible' => 0, | |
53 | 'is_active' => 1, | |
54 | 'is_reserved' => 0, | |
55 | ); | |
56 | ||
57 | $ids = array(); | |
58 | $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); | |
f17d75bb | 59 | $params['name'] = 'test_financialType1'; |
6a488035 | 60 | $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); |
f743a6eb | 61 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); |
6a488035 TO |
62 | $financialParams = array( |
63 | 'entity_table' => 'civicrm_financial_type', | |
64 | 'entity_id' => $financialType->id, | |
65 | 'account_relationship' => $relationTypeId, | |
66 | 'financial_account_id' => $financialAccount->id, | |
67 | ); | |
68 | ||
69 | CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids); | |
70 | $result = $this->assertDBNotNull( | |
71 | 'CRM_Financial_DAO_EntityFinancialAccount', | |
72 | $financialAccount->id, | |
73 | 'entity_id', | |
74 | 'financial_account_id', | |
75 | 'Database check on added financial type record.' | |
76 | ); | |
77 | $this->assertEquals( $result, $financialType->id, 'Verify Account Type'); | |
78 | } | |
79 | ||
80 | /** | |
81 | * check method del() | |
82 | */ | |
83 | function testDel() { | |
84 | $params = array( | |
85 | 'name' => 'TestFinancialAccount_2', | |
86 | 'is_deductible' => 0, | |
87 | 'is_active' => 1, | |
88 | 'is_reserved' => 0, | |
89 | ); | |
90 | ||
91 | $ids = array(); | |
92 | $defaults = array(); | |
93 | $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); | |
f17d75bb | 94 | $params['name'] = 'test_financialType2'; |
6a488035 | 95 | $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); |
f743a6eb | 96 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' ")); |
6a488035 TO |
97 | $financialParams = array( |
98 | 'entity_table' => 'civicrm_financial_type', | |
99 | 'entity_id' => $financialType->id, | |
100 | 'account_relationship' => $relationTypeId, | |
101 | 'financial_account_id' => $financialAccount->id, | |
102 | ); | |
103 | $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids); | |
104 | CRM_Financial_BAO_FinancialTypeAccount::del($financialAccountType->id); | |
105 | $params = array('id' => $financialAccountType->id ); | |
106 | $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); | |
107 | $this->assertEquals( empty($result), true, 'Verify financial types record deletion.'); | |
108 | } | |
109 | ||
110 | /** | |
111 | * check method getFinancialAccount() | |
112 | */ | |
113 | function testRetrieve() { | |
114 | $params = array( | |
115 | 'name' => 'TestFinancialAccount_3', | |
116 | 'is_deductible' => 0, | |
117 | 'is_active' => 1, | |
118 | 'is_reserved' => 0, | |
119 | ); | |
120 | $ids = array(); | |
121 | $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); | |
f17d75bb | 122 | $params['name'] = 'test_financialType3'; |
6a488035 | 123 | $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); |
f743a6eb | 124 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); |
6a488035 TO |
125 | $financialParams = array( |
126 | 'entity_table' => 'civicrm_financial_type', | |
127 | 'entity_id' => $financialType->id, | |
128 | 'account_relationship' => $relationTypeId, | |
129 | 'financial_account_id' => $financialAccount->id, | |
130 | ); | |
131 | ||
132 | CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids); | |
133 | $defaults = array(); | |
134 | $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::retrieve($financialParams, $defaults); | |
1c5f06af PN |
135 | $this->assertEquals( $financialAccountType['entity_id'], $financialType->id, 'Verify Entity Id.'); |
136 | $this->assertEquals( $financialAccountType['financial_account_id'], $financialAccount->id, 'Verify Financial Account Id.'); | |
6a488035 TO |
137 | } |
138 | ||
139 | /** | |
140 | * check method getFinancialAccount() | |
141 | */ | |
142 | function testGetFinancialAccount() { | |
143 | $params = array( | |
144 | 'name' => 'TestFinancialAccount', | |
145 | 'accounting_code' => 4800, | |
146 | 'is_deductible' => 0, | |
147 | 'is_active' => 1, | |
148 | 'is_reserved' => 0, | |
149 | ); | |
150 | $ids = array(); | |
151 | $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); | |
f17d75bb | 152 | $params = array( |
6a488035 | 153 | 'financial_account_id' => $financialAccount->id, |
f17d75bb PN |
154 | 'payment_processor_type_id' => 1, |
155 | 'domain_id' => 1, | |
156 | 'billing_mode' => 1, | |
157 | 'name' => 'paymentProcessor', | |
6a488035 | 158 | ); |
f17d75bb PN |
159 | $processor = CRM_Financial_BAO_PaymentProcessor::create($params); |
160 | ||
6a488035 | 161 | $account = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount( |
f17d75bb PN |
162 | $processor->id, |
163 | 'civicrm_payment_processor' | |
6a488035 | 164 | ); |
f17d75bb | 165 | $this->assertEquals($account, 'TestFinancialAccount', 'Verify Financial Account Name'); |
6a488035 TO |
166 | } |
167 | ||
168 | /** | |
169 | * check method getInstrumentFinancialAccount() | |
170 | */ | |
171 | function testGetInstrumentFinancialAccount() { | |
172 | $paymentInstrumentValue = 1; | |
173 | $params = array( | |
174 | 'name' => 'Donations', | |
175 | 'is_deductible' => 0, | |
176 | 'is_active' => 1, | |
177 | ); | |
178 | $ids = array(); | |
179 | $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); | |
180 | $optionParams = array( | |
181 | 'name' => 'Credit Card', | |
182 | 'value' => $paymentInstrumentValue, | |
183 | ); | |
184 | $optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults); | |
f743a6eb | 185 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); |
6a488035 TO |
186 | $financialParams = array( |
187 | 'entity_table' => 'civicrm_option_value', | |
188 | 'entity_id' => $optionValue->id, | |
189 | 'account_relationship' => $relationTypeId, | |
190 | 'financial_account_id' => $financialAccount->id, | |
191 | ); | |
192 | ||
193 | CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids); | |
194 | $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentValue); | |
195 | ||
196 | $this->assertEquals( $financialAccountId, $financialAccount->id, 'Verify Payment Instrument'); | |
197 | } | |
f743a6eb | 198 | } |