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