Commit | Line | Data |
---|---|---|
b5935203 | 1 | <?php |
b5935203 | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
b5935203 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
b5935203 | 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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
b5935203 | 27 | |
b5935203 | 28 | /** |
29 | * Class api_v3_TaxContributionPageTest | |
acb109b7 | 30 | * @group headless |
b5935203 | 31 | */ |
32 | class api_v3_TaxContributionPageTest extends CiviUnitTestCase { | |
33 | protected $_apiversion = 3; | |
34 | protected $params; | |
35 | protected $financialtypeID; | |
36 | protected $financialAccountId; | |
37 | protected $_entity = 'contribution_page'; | |
38 | protected $_priceSetParams = array(); | |
39 | protected $_paymentProcessorType; | |
40 | protected $payParams = array(); | |
41 | protected $paymentProceParams = array(); | |
42 | protected $settingValue = array(); | |
43 | protected $setInvoiceSettings; | |
44 | protected $_ids = array(); | |
45 | protected $_individualId; | |
46 | protected $financialAccHalftax; | |
47 | protected $financialtypeHalftax; | |
48 | protected $financialRelationHalftax; | |
49 | protected $halfFinancialAccId; | |
50 | protected $halfFinancialTypeId; | |
51 | public $DBResetRequired = TRUE; | |
52 | ||
53 | public function setUp() { | |
54 | parent::setUp(); | |
55 | $this->_individualId = $this->individualCreate(); | |
56 | $this->_orgId = $this->organizationCreate(NULL); | |
57 | ||
58 | $this->params = array( | |
92fcb95f | 59 | 'title' => "Test Contribution Page" . substr(sha1(rand()), 0, 7), |
b5935203 | 60 | 'financial_type_id' => 1, |
61 | 'payment_processor' => 1, | |
62 | 'currency' => 'NZD', | |
63 | 'goal_amount' => 350, | |
64 | 'is_pay_later' => 1, | |
65 | 'pay_later_text' => 'I will pay later', | |
66 | 'pay_later_receipt' => "I will pay later", | |
67 | 'is_monetary' => TRUE, | |
21dfd5f5 | 68 | 'is_billing_required' => TRUE, |
b5935203 | 69 | ); |
70 | ||
71 | $this->_priceSetParams = array( | |
92fcb95f TO |
72 | 'name' => 'tax_contribution' . substr(sha1(rand()), 0, 7), |
73 | 'title' => 'contributiontax' . substr(sha1(rand()), 0, 7), | |
b5935203 | 74 | 'is_active' => 1, |
75 | 'help_pre' => "Where does your goat sleep", | |
76 | 'help_post' => "thank you for your time", | |
77 | 'extends' => 2, | |
78 | 'financial_type_id' => 3, | |
79 | 'is_quick_config' => 0, | |
21dfd5f5 | 80 | 'is_reserved' => 0, |
b5935203 | 81 | ); |
6c6e6187 | 82 | // Financial Account with 20% tax rate |
b5935203 | 83 | $financialAccountSetparams = array( |
84 | #[domain_id] => | |
92fcb95f | 85 | 'name' => 'vat full taxrate account' . substr(sha1(rand()), 0, 7), |
b5935203 | 86 | 'contact_id' => $this->_orgId, |
87 | 'financial_account_type_id' => 2, | |
88 | 'is_tax' => 1, | |
89 | 'tax_rate' => 20.00, | |
90 | 'is_reserved' => 0, | |
91 | 'is_active' => 1, | |
92 | 'is_default' => 0, | |
93 | ); | |
94 | ||
95 | $financialAccount = $this->callAPISuccess('financial_account', 'create', $financialAccountSetparams); | |
96 | $this->financialAccountId = $financialAccount['id']; | |
97 | ||
98 | // Financial type having 'Sales Tax Account is' with liability financail account | |
99 | $financialType = array( | |
92fcb95f | 100 | 'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7), |
b5935203 | 101 | 'is_reserved' => 0, |
102 | 'is_active' => 1, | |
103 | ); | |
6c6e6187 | 104 | $priceField = $this->callAPISuccess('financial_type', 'create', $financialType); |
b5935203 | 105 | $this->financialtypeID = $priceField['id']; |
106 | $financialRelationParams = array( | |
107 | 'entity_table' => 'civicrm_financial_type', | |
108 | 'entity_id' => $this->financialtypeID, | |
109 | 'account_relationship' => 10, | |
21dfd5f5 | 110 | 'financial_account_id' => $this->financialAccountId, |
b5935203 | 111 | ); |
112 | $financialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationParams); | |
113 | ||
114 | // Financial type with 5% tax rate | |
115 | $financialAccHalftax = array( | |
92fcb95f | 116 | 'name' => 'vat half taxrate account' . substr(sha1(rand()), 0, 7), |
b5935203 | 117 | 'contact_id' => $this->_orgId, |
118 | 'financial_account_type_id' => 2, | |
119 | 'is_tax' => 1, | |
120 | 'tax_rate' => 5.00, | |
121 | 'is_reserved' => 0, | |
122 | 'is_active' => 1, | |
21dfd5f5 | 123 | 'is_default' => 0, |
b5935203 | 124 | ); |
125 | $halfFinancialAccount = CRM_Financial_BAO_FinancialAccount::add($financialAccHalftax); | |
126 | $this->halfFinancialAccId = $halfFinancialAccount->id; | |
31037a42 | 127 | $halfFinancialtypeHalftax = array( |
92fcb95f | 128 | 'name' => 'grassvariety2' . substr(sha1(rand()), 0, 7), |
b5935203 | 129 | 'is_reserved' => 0, |
130 | 'is_active' => 1, | |
131 | ); | |
31037a42 | 132 | |
b5935203 | 133 | $halfFinancialType = CRM_Financial_BAO_FinancialType::add($halfFinancialtypeHalftax); |
6c6e6187 | 134 | $this->halfFinancialTypeId = $halfFinancialType->id; |
31037a42 | 135 | $financialRelationHalftax = array( |
b5935203 | 136 | 'entity_table' => 'civicrm_financial_type', |
137 | 'entity_id' => $this->halfFinancialTypeId, | |
138 | 'account_relationship' => 10, | |
21dfd5f5 | 139 | 'financial_account_id' => $this->halfFinancialAccId, |
b5935203 | 140 | ); |
141 | ||
142 | $halfFinancialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax); | |
143 | ||
144 | // Enable component contribute setting | |
ec5da26a | 145 | $setInvoiceSettings = $this->enableTaxAndInvoicing(); |
b5935203 | 146 | |
147 | // Payment Processor | |
148 | $paymentProceParams = array( | |
149 | 'domain_id' => 1, | |
92fcb95f | 150 | 'name' => 'dummy' . substr(sha1(rand()), 0, 7), |
97502bac | 151 | 'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'), |
b5935203 | 152 | 'financial_account_id' => 12, |
153 | 'is_active' => 1, | |
154 | 'is_default' => 1, | |
b5935203 | 155 | 'user_name' => 'dummy', |
156 | 'url_site' => 'http://dummy.com', | |
157 | 'url_recur' => 'http://dummyrecur.com', | |
158 | 'class_name' => 'Payment_Dummy', | |
159 | 'billing_mode' => 1, | |
160 | 'is_recur' => 1, | |
21dfd5f5 | 161 | 'payment_type' => 1, |
b5935203 | 162 | ); |
163 | $result = $this->callAPISuccess('payment_processor', 'create', $paymentProceParams); | |
164 | $this->_ids['paymentProcessID'] = $result['id']; | |
165 | require_once 'api/v3/examples/PaymentProcessor/Create.php'; | |
166 | $this->assertAPISuccess($result); | |
167 | } | |
168 | ||
00be9182 | 169 | public function tearDown() { |
83644f47 | 170 | $this->quickCleanUpFinancialEntities(); |
b5935203 | 171 | } |
172 | ||
00be9182 | 173 | public function setUpContributionPage() { |
b5935203 | 174 | $contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
175 | if (empty($this->_ids['price_set'])) { | |
176 | $priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams); | |
177 | $this->_ids['price_set'][] = $priceSet['id']; | |
178 | } | |
179 | $priceSetID = $this->_price = reset($this->_ids['price_set']); | |
481a74f4 | 180 | CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); |
b5935203 | 181 | |
182 | if (empty($this->_ids['price_field'])) { | |
183 | $priceField = $this->callAPISuccess('price_field', 'create', array( | |
184 | 'price_set_id' => $priceSetID, | |
185 | 'label' => 'Goat Breed', | |
186 | 'html_type' => 'Radio', | |
187 | )); | |
188 | $this->_ids['price_field'] = array($priceField['id']); | |
189 | } | |
190 | if (empty($this->_ids['price_field_value'])) { | |
191 | $this->callAPISuccess('price_field_value', 'create', array( | |
192 | 'price_set_id' => $priceSetID, | |
193 | 'price_field_id' => $priceField['id'], | |
194 | 'label' => 'Long Haired Goat', | |
195 | 'amount' => 100, | |
21dfd5f5 | 196 | 'financial_type_id' => $this->financialtypeID, |
b5935203 | 197 | )); |
198 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( | |
199 | 'price_set_id' => $priceSetID, | |
200 | 'price_field_id' => $priceField['id'], | |
201 | 'label' => 'Shoe-eating Goat', | |
202 | 'amount' => 300, | |
21dfd5f5 | 203 | 'financial_type_id' => $this->halfFinancialTypeId, |
b5935203 | 204 | )); |
205 | $this->_ids['price_field_value'] = array($priceFieldValue['id']); | |
206 | } | |
207 | $this->_ids['contribution_page'] = $contributionPageResult['id']; | |
208 | } | |
209 | ||
210 | /** | |
83644f47 | 211 | * Online and offline contrbution from above created contribution page. |
212 | * | |
213 | * @param string $thousandSeparator | |
214 | * punctuation used to refer to thousands. | |
215 | * | |
216 | * @dataProvider getThousandSeparators | |
b5935203 | 217 | */ |
83644f47 | 218 | public function testCreateContributionOnline($thousandSeparator) { |
219 | $this->setCurrencySeparators($thousandSeparator); | |
b5935203 | 220 | $this->setUpContributionPage(); |
221 | $params = array( | |
222 | 'contact_id' => $this->_individualId, | |
223 | 'receive_date' => '20120511', | |
83644f47 | 224 | 'total_amount' => $this->formatMoneyInput(100.00), |
b5935203 | 225 | 'financial_type_id' => $this->financialtypeID, |
226 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
227 | 'payment_processor' => $this->_ids['paymentProcessID'], | |
228 | 'trxn_id' => 12345, | |
229 | 'invoice_id' => 67890, | |
230 | 'source' => 'SSF', | |
21dfd5f5 | 231 | 'contribution_status_id' => 1, |
b5935203 | 232 | ); |
31037a42 | 233 | |
3c27d467 | 234 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
b5935203 | 235 | $this->_ids['contributionId'] = $contribution['id']; |
a15773db TM |
236 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
237 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); | |
238 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID); | |
239 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); | |
240 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
ba4a1892 | 241 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); |
a15773db TM |
242 | $this->assertEquals($contribution['values'][$contribution['id']]['tax_amount'], 20); |
243 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1); | |
b5935203 | 244 | $this->_checkFinancialRecords($contribution, 'online'); |
245 | } | |
246 | ||
83644f47 | 247 | /** |
248 | * Create contribution with chained line items. | |
249 | * | |
250 | * @param string $thousandSeparator | |
251 | * punctuation used to refer to thousands. | |
252 | * | |
253 | * @dataProvider getThousandSeparators | |
254 | */ | |
255 | public function testCreateContributionChainedLineItems($thousandSeparator) { | |
256 | $this->setCurrencySeparators($thousandSeparator); | |
b5935203 | 257 | $this->setUpContributionPage(); |
258 | $params = array( | |
259 | 'contact_id' => $this->_individualId, | |
260 | 'receive_date' => '20120511', | |
261 | 'total_amount' => 400.00, | |
262 | 'financial_type_id' => $this->financialtypeID, | |
263 | 'trxn_id' => 12345, | |
264 | 'invoice_id' => 67890, | |
265 | 'source' => 'SSF', | |
266 | 'contribution_status_id' => 1, | |
267 | 'skipLineItem' => 1, | |
268 | 'api.line_item.create' => array( | |
269 | array( | |
270 | 'price_field_id' => $this->_ids['price_field'], | |
271 | 'qty' => 1, | |
272 | 'line_total' => '100', | |
273 | 'unit_price' => '100', | |
274 | 'financial_type_id' => $this->financialtypeID, | |
275 | ), | |
276 | array( | |
277 | 'price_field_id' => $this->_ids['price_field'], | |
278 | 'qty' => 1, | |
279 | 'line_total' => '300', | |
280 | 'unit_price' => '300', | |
281 | 'financial_type_id' => $this->halfFinancialTypeId, | |
282 | ), | |
283 | ), | |
284 | ); | |
285 | ||
3c27d467 | 286 | $contribution = $this->callAPISuccess('contribution', 'create', $params); |
b5935203 | 287 | |
6c6e6187 | 288 | $lineItems = $this->callAPISuccess('line_item', 'get', array( |
b5935203 | 289 | 'entity_id' => $contribution['id'], |
290 | 'contribution_id' => $contribution['id'], | |
291 | 'entity_table' => 'civicrm_contribution', | |
292 | 'sequential' => 1, | |
293 | )); | |
294 | $this->assertEquals(2, $lineItems['count']); | |
295 | } | |
296 | ||
00be9182 | 297 | public function testCreateContributionPayLaterOnline() { |
b5935203 | 298 | $this->setUpContributionPage(); |
299 | $params = array( | |
300 | 'contact_id' => $this->_individualId, | |
301 | 'receive_date' => '20120511', | |
302 | 'total_amount' => 100.00, | |
303 | 'financial_type_id' => $this->financialtypeID, | |
304 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
305 | 'trxn_id' => 12345, | |
306 | 'is_pay_later' => 1, | |
307 | 'invoice_id' => 67890, | |
308 | 'source' => 'SSF', | |
309 | 'contribution_status_id' => 2, | |
310 | ); | |
3c27d467 | 311 | $contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__); |
a15773db TM |
312 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
313 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); | |
314 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID); | |
315 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); | |
316 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
ba4a1892 | 317 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); |
a15773db TM |
318 | $this->assertEquals($contribution['values'][$contribution['id']]['tax_amount'], 20); |
319 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2); | |
b5935203 | 320 | $this->_checkFinancialRecords($contribution, 'payLater'); |
321 | } | |
92915c55 | 322 | |
83644f47 | 323 | /** |
324 | * Test online pending contributions. | |
325 | * | |
326 | * @param string $thousandSeparator | |
327 | * punctuation used to refer to thousands. | |
328 | * | |
329 | * @dataProvider getThousandSeparators | |
330 | */ | |
331 | public function testCreateContributionPendingOnline($thousandSeparator) { | |
332 | $this->setCurrencySeparators($thousandSeparator); | |
b5935203 | 333 | $this->setUpContributionPage(); |
334 | $params = array( | |
335 | 'contact_id' => $this->_individualId, | |
336 | 'receive_date' => '20120511', | |
83644f47 | 337 | 'total_amount' => $this->formatMoneyInput(100.00), |
b5935203 | 338 | 'financial_type_id' => $this->financialtypeID, |
339 | 'contribution_page_id' => $this->_ids['contribution_page'], | |
340 | 'trxn_id' => 12345, | |
341 | 'invoice_id' => 67890, | |
342 | 'source' => 'SSF', | |
343 | 'contribution_status_id' => 2, | |
344 | ); | |
345 | ||
3c27d467 | 346 | $contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__); |
a15773db TM |
347 | $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); |
348 | $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); | |
349 | $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID); | |
350 | $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); | |
351 | $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); | |
ba4a1892 | 352 | $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); |
a15773db TM |
353 | $this->assertEquals($contribution['values'][$contribution['id']]['tax_amount'], 20); |
354 | $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2); | |
b5935203 | 355 | $this->_checkFinancialRecords($contribution, 'pending'); |
83644f47 | 356 | $this->setCurrencySeparators($thousandSeparator); |
b5935203 | 357 | } |
358 | ||
79d7553f | 359 | /** |
a76b8bd8 | 360 | * Update a contribution. |
361 | * | |
b5935203 | 362 | * Function tests that line items, financial records are updated when contribution amount is changed |
363 | */ | |
00be9182 | 364 | public function testCreateUpdateContributionChangeTotal() { |
b5935203 | 365 | $this->setUpContributionPage(); |
366 | $this->contributionParams = array( | |
367 | 'contact_id' => $this->_individualId, | |
368 | 'receive_date' => '20120511', | |
369 | 'total_amount' => 100.00, | |
92915c55 | 370 | 'financial_type_id' => $this->financialtypeID, |
b5935203 | 371 | 'source' => 'SSF', |
372 | 'contribution_status_id' => 1, | |
373 | ); | |
374 | $contribution = $this->callAPISuccess('contribution', 'create', $this->contributionParams); | |
6c6e6187 | 375 | $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( |
b5935203 | 376 | 'entity_id' => $contribution['id'], |
377 | 'entity_table' => 'civicrm_contribution', | |
378 | 'sequential' => 1, | |
379 | 'return' => 'line_total', | |
380 | )); | |
381 | $this->assertEquals('100.00', $lineItems); | |
382 | $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); | |
383 | $this->assertEquals('120.00', $trxnAmount); | |
384 | $newParams = array( | |
385 | 'id' => $contribution['id'], | |
92915c55 | 386 | 'financial_type_id' => 1, // without tax rate i.e Donation |
21dfd5f5 | 387 | 'total_amount' => '300', |
b5935203 | 388 | ); |
a76b8bd8 | 389 | $contribution = $this->callAPISuccess('contribution', 'create', $newParams); |
b5935203 | 390 | |
6c6e6187 | 391 | $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( |
b5935203 | 392 | 'entity_id' => $contribution['id'], |
393 | 'entity_table' => 'civicrm_contribution', | |
394 | 'sequential' => 1, | |
395 | 'return' => 'line_total', | |
396 | )); | |
397 | ||
398 | $this->assertEquals('300.00', $lineItems); | |
399 | $trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']); | |
400 | $fitemAmount = $this->_getFinancialItemAmount($contribution['id']); | |
401 | $this->assertEquals('300.00', $trxnAmount); | |
402 | $this->assertEquals('300.00', $fitemAmount); | |
403 | } | |
404 | ||
405 | /** | |
100fef9d | 406 | * @param int $contId |
b5935203 | 407 | * |
408 | * @return null|string | |
409 | */ | |
00be9182 | 410 | public function _getFinancialTrxnAmount($contId) { |
b5935203 | 411 | $query = "SELECT |
412 | SUM( ft.total_amount ) AS total | |
413 | FROM civicrm_financial_trxn AS ft | |
414 | LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id | |
415 | WHERE ceft.entity_table = 'civicrm_contribution' | |
416 | AND ceft.entity_id = {$contId}"; | |
417 | $result = CRM_Core_DAO::singleValueQuery($query); | |
418 | return $result; | |
419 | } | |
420 | ||
421 | /** | |
100fef9d | 422 | * @param int $contId |
b5935203 | 423 | * |
424 | * @return null|string | |
425 | */ | |
00be9182 | 426 | public function _getFinancialItemAmount($contId) { |
b5935203 | 427 | $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution')); |
428 | $query = "SELECT | |
429 | SUM(amount) | |
430 | FROM civicrm_financial_item | |
431 | WHERE entity_table = 'civicrm_line_item' | |
432 | AND entity_id = {$lineItem}"; | |
433 | $result = CRM_Core_DAO::singleValueQuery($query); | |
434 | return $result; | |
435 | } | |
436 | ||
437 | /** | |
c490a46a | 438 | * @param array $params |
b5935203 | 439 | * @param $context |
440 | */ | |
00be9182 | 441 | public function _checkFinancialRecords($params, $context) { |
b5935203 | 442 | $entityParams = array( |
443 | 'entity_id' => $params['id'], | |
444 | 'entity_table' => 'civicrm_contribution', | |
445 | ); | |
446 | if ($context == 'pending') { | |
447 | $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams); | |
448 | $this->assertNull($trxn, 'No Trxn to be created until IPN callback'); | |
449 | return; | |
450 | } | |
451 | $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); | |
452 | $trxnParams = array( | |
453 | 'id' => $trxn['financial_trxn_id'], | |
454 | ); | |
455 | if ($context != 'online' && $context != 'payLater') { | |
456 | $compareParams = array( | |
457 | 'to_financial_account_id' => 6, | |
458 | 'total_amount' => 120, | |
459 | 'status_id' => 1, | |
460 | ); | |
461 | } | |
462 | if ($context == 'online') { | |
463 | $compareParams = array( | |
464 | 'to_financial_account_id' => 12, | |
465 | 'total_amount' => 120, | |
466 | 'status_id' => 1, | |
467 | ); | |
468 | } | |
469 | elseif ($context == 'payLater') { | |
470 | $compareParams = array( | |
471 | 'to_financial_account_id' => 7, | |
472 | 'total_amount' => 120, | |
473 | 'status_id' => 2, | |
474 | ); | |
475 | } | |
476 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams); | |
477 | $entityParams = array( | |
478 | 'financial_trxn_id' => $trxn['financial_trxn_id'], | |
479 | 'entity_table' => 'civicrm_financial_item', | |
480 | ); | |
481 | $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); | |
482 | $fitemParams = array( | |
483 | 'id' => $entityTrxn['entity_id'], | |
484 | ); | |
485 | $compareParams = array( | |
486 | 'amount' => 100, | |
487 | 'status_id' => 1, | |
488 | 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID), | |
489 | ); | |
490 | if ($context == 'payLater') { | |
491 | $compareParams = array( | |
492 | 'amount' => 100, | |
493 | 'status_id' => 3, | |
494 | 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID), | |
495 | ); | |
496 | } | |
497 | $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams); | |
498 | } | |
499 | ||
500 | /** | |
100fef9d | 501 | * @param int $financialTypeId |
f0be539a | 502 | * @return int |
b5935203 | 503 | */ |
00be9182 | 504 | public function _getFinancialAccountId($financialTypeId) { |
b5935203 | 505 | $accountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); |
506 | ||
507 | $searchParams = array( | |
92915c55 TO |
508 | 'entity_table' => 'civicrm_financial_type', |
509 | 'entity_id' => $financialTypeId, | |
b5935203 | 510 | 'account_relationship' => $accountRel, |
511 | ); | |
512 | ||
513 | $result = array(); | |
481a74f4 TO |
514 | CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result); |
515 | return CRM_Utils_Array::value('financial_account_id', $result); | |
b5935203 | 516 | } |
517 | ||
f0be539a | 518 | /** |
78ab0ca4 | 519 | * Test deleting a contribution. |
f0be539a | 520 | * |
78ab0ca4 | 521 | * (It is unclear why this is in this class - it seems like maybe it doesn't test anything not |
522 | * on the contribution test class & might be copy and paste....). | |
f0be539a | 523 | */ |
00be9182 | 524 | public function testDeleteContribution() { |
78ab0ca4 | 525 | $contributionID = $this->contributionCreate(array( |
526 | 'contact_id' => $this->_individualId, | |
527 | 'trxn_id' => 12389, | |
528 | 'financial_type_id' => $this->financialtypeID, | |
529 | 'invoice_id' => 'dfsdf', | |
530 | )); | |
531 | $this->callAPISuccess('contribution', 'delete', array('id' => $contributionID)); | |
b5935203 | 532 | } |
96025800 | 533 | |
b5935203 | 534 | } |