3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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_Contribute_BAO_ContributionTest
32 class CRM_Contribute_BAO_ContributionTest
extends CiviUnitTestCase
{
35 * Clean up after tests.
37 public function tearDown() {
38 $this->quickCleanUpFinancialEntities();
43 * Test create method (create and update modes).
45 public function testCreate() {
46 $contactId = $this->individualCreate();
49 'contact_id' => $contactId,
51 'financial_type_id' => 1,
52 'contribution_status_id' => 1,
53 'payment_instrument_id' => 1,
54 'source' => 'STUDENT',
55 'receive_date' => '20080522000000',
56 'receipt_date' => '20080522000000',
57 'non_deductible_amount' => 0.00,
58 'total_amount' => 200.00,
61 'trxn_id' => '22ereerwww444444',
62 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81',
63 'thankyou_date' => '20080522',
67 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
69 $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transaction id creation.');
70 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
72 //update contribution amount
73 $params['id'] = $contribution['id'];
74 $params['fee_amount'] = 10;
75 $params['net_amount'] = 190;
77 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
79 $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .');
80 $this->assertEquals($params['net_amount'], $contribution['net_amount'], 'Check for Amount updation.');
84 * Create() method with custom data.
86 public function testCreateWithCustomData() {
87 $contactId = $this->individualCreate();
90 $customGroup = $this->customGroupCreate(array('extends' => 'Contribution'));
91 $customGroupID = $customGroup['id'];
92 $customGroup = $customGroup['values'][$customGroupID];
96 'data_type' => 'String',
97 'html_type' => 'Text',
99 'custom_group_id' => $customGroupID,
101 $customField = CRM_Core_BAO_CustomField
::create($fields);
104 'contact_id' => $contactId,
106 'financial_type_id' => 1,
107 'contribution_status_id' => 1,
108 'payment_instrument_id' => 1,
109 'source' => 'STUDENT',
110 'receive_date' => '20080522000000',
111 'receipt_date' => '20080522000000',
113 'non_deductible_amount' => 0.00,
114 'total_amount' => 200.00,
117 'trxn_id' => '22ereerwww322323',
118 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
119 'thankyou_date' => '20080522',
120 'skipCleanMoney' => TRUE,
123 $params['custom'] = array(
124 $customField->id
=> array(
126 'value' => 'Test custom value',
128 'custom_field_id' => $customField->id
,
129 'custom_group_id' => $customGroupID,
130 'table_name' => $customGroup['table_name'],
131 'column_name' => $customField->column_name
,
137 $contribution = CRM_Contribute_BAO_Contribution
::create($params);
139 // Check that the custom field value is saved
140 $customValueParams = array(
141 'entityID' => $contribution->id
,
142 'custom_' . $customField->id
=> 1,
144 $values = CRM_Core_BAO_CustomValueTable
::getValues($customValueParams);
145 $this->assertEquals('Test custom value', $values['custom_' . $customField->id
], 'Check the custom field value');
147 $this->assertEquals($params['trxn_id'], $contribution->trxn_id
, 'Check for transcation id creation.');
148 $this->assertEquals($contactId, $contribution->contact_id
, 'Check for contact id for Conribution.');
152 * CRM-21026 Test ContributionCount after contribution created with disabled FT
154 public function testContributionCountDisabledFinancialType() {
155 $contactId = $this->individualCreate();
156 $financialType = array(
157 'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7),
161 $finType = $this->callAPISuccess('financial_type', 'create', $financialType);
163 'contact_id' => $contactId,
165 'financial_type_id' => $finType['id'],
166 'contribution_status_id' => 1,
167 'payment_instrument_id' => 1,
168 'source' => 'STUDENT',
169 'receive_date' => '20080522000000',
170 'receipt_date' => '20080522000000',
172 'non_deductible_amount' => 0.00,
173 'total_amount' => 200.00,
176 'trxn_id' => '22ereerwww322323',
177 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
178 'thankyou_date' => '20080522',
180 $this->callAPISuccess('Contribution', 'create', $params);
181 $this->callAPISuccess('financial_type', 'create', array('is_active' => 0, 'id' => $finType['id']));
182 $contributionCount = CRM_Contribute_BAO_Contribution
::contributionCount($contactId);
183 $this->assertEquals(1, $contributionCount);
187 * DeleteContribution() method
189 public function testDeleteContribution() {
190 $contactId = $this->individualCreate();
193 'contact_id' => $contactId,
195 'financial_type_id' => 1,
196 'contribution_status_id' => 1,
197 'payment_instrument_id' => 1,
198 'source' => 'STUDENT',
199 'receive_date' => '20080522000000',
200 'receipt_date' => '20080522000000',
202 'non_deductible_amount' => 0.00,
203 'total_amount' => 200.00,
206 'trxn_id' => '33ereerwww322323',
207 'invoice_id' => '33ed39c9e9ee6ef6031621ce0eafe6da70',
208 'thankyou_date' => '20080522',
209 'sequential' => TRUE,
212 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
214 CRM_Contribute_BAO_Contribution
::deleteContribution($contribution['id']);
216 $this->assertDBNull('CRM_Contribute_DAO_Contribution', $contribution['trxn_id'],
217 'id', 'trxn_id', 'Database check for deleted Contribution.'
222 * Create honor-contact method.
224 public function testCreateAndGetHonorContact() {
225 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
226 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
227 $email = "{$firstName}.{$lastName}@example.com";
229 //Get profile id of name honoree_individual used to create profileContact
230 $honoreeProfileId = NULL;
231 $ufGroupDAO = new CRM_Core_DAO_UFGroup();
232 $ufGroupDAO->name
= 'honoree_individual';
233 if ($ufGroupDAO->find(TRUE)) {
234 $honoreeProfileId = $ufGroupDAO->id
;
239 'first_name' => $firstName,
240 'last_name' => $lastName,
243 $softParam = array('soft_credit_type_id' => 1);
245 $honoreeContactId = CRM_Contact_BAO_Contact
::createProfileContact($params, CRM_Core_DAO
::$_nullArray,
246 NULL, NULL, $honoreeProfileId
249 $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $honoreeContactId, 'first_name', 'id', $firstName,
250 'Database check for created honor contact record.'
252 //create contribution on behalf of honary.
254 $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe'));
257 'contact_id' => $contactId,
259 'financial_type_id' => 4,
260 'contribution_status_id' => 1,
261 'receive_date' => date('Ymd'),
262 'total_amount' => 66,
266 $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
267 $id = $contribution['id'];
268 $softParam['contact_id'] = $honoreeContactId;
269 $softParam['contribution_id'] = $id;
270 $softParam['currency'] = $contribution['currency'];
271 $softParam['amount'] = $contribution['total_amount'];
273 //Create Soft Contribution for honoree contact
274 CRM_Contribute_BAO_ContributionSoft
::add($softParam);
276 $this->assertDBCompareValue('CRM_Contribute_DAO_ContributionSoft', $id, 'contact_id',
277 'contribution_id', $honoreeContactId, 'Check DB for honor contact of the contribution'
279 //get honorary information
280 $getHonorContact = CRM_Contribute_BAO_Contribution
::getHonorContacts($honoreeContactId);
281 $this->assertEquals(array(
283 'honor_type' => 'In Honor of',
284 'honorId' => $contactId,
285 'display_name' => 'Mr. John Doe II',
286 'type' => 'Event Fee',
288 'amount' => '$ 66.00',
290 'receive_date' => date('Y-m-d 00:00:00'),
291 'contribution_status' => 'Completed',
293 ), $getHonorContact);
295 $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $honoreeContactId, 'first_name', 'id', $firstName,
296 'Database check for created honor contact record.'
299 //get annual contribution information
300 $annual = CRM_Contribute_BAO_Contribution
::annual($contactId);
302 $currencySymbol = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency', CRM_Core_Config
::singleton()->defaultCurrency
, 'symbol', 'name');
303 $this->assertDBCompareValue('CRM_Contribute_DAO_Contribution', $id, 'total_amount',
304 'id', ltrim($annual[2], $currencySymbol), 'Check DB for total amount of the contribution'
309 * Display sort name during.
310 * Update multiple contributions
313 public function testsortName() {
315 'first_name' => 'Shane',
316 'last_name' => 'Whatson',
317 'contact_type' => 'Individual',
320 $contact = CRM_Contact_BAO_Contact
::add($params);
322 //Now check $contact is object of contact DAO..
323 $this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object');
325 $contactId = $contact->id
;
327 'contact_id' => $contactId,
329 'financial_type_id' => 1,
330 'contribution_status_id' => 1,
331 'payment_instrument_id' => 1,
332 'source' => 'STUDENT',
333 'receive_date' => '20080522000000',
334 'receipt_date' => '20080522000000',
336 'non_deductible_amount' => 0.00,
337 'total_amount' => 300.00,
340 'trxn_id' => '22ereerwww323',
341 'invoice_id' => '22ed39c9e9ee621ce0eafe6da70',
342 'thankyou_date' => '20080522',
343 'sequential' => TRUE,
346 $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
348 $this->assertEquals($param['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
349 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
351 //display sort name during Update multiple contributions
352 $sortName = CRM_Contribute_BAO_Contribution
::sortName($contribution['id']);
354 $this->assertEquals('Whatson, Shane', $sortName, 'Check for sort name.');
358 * Add premium during online Contribution.
362 public function testAddPremium() {
363 $contactId = $this->individualCreate();
370 'name' => 'TEST Premium',
372 'imageOption' => 'noImage',
373 'MAX_FILE_SIZE' => 2097152,
376 'min_contribution' => 100,
379 $premium = CRM_Contribute_BAO_ManagePremiums
::add($params, $ids);
381 $this->assertEquals('TEST Premium', $premium->name
, 'Check for premium name.');
384 'contact_id' => $contactId,
386 'financial_type_id' => 1,
387 'contribution_status_id' => 1,
388 'payment_instrument_id' => 1,
389 'source' => 'STUDENT',
390 'receive_date' => '20080522000000',
391 'receipt_date' => '20080522000000',
393 'non_deductible_amount' => 0.00,
394 'total_amount' => 300.00,
397 'trxn_id' => '33erdfrwvw434',
398 'invoice_id' => '98ed34f7u9hh672ce0eafe8fb92',
399 'thankyou_date' => '20080522',
400 'sequential' => TRUE,
402 $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
404 $this->assertEquals($param['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
405 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
407 //parameter for adding premium to contribution
409 'product_id' => $premium->id
,
410 'contribution_id' => $contribution['id'],
411 'product_option' => NULL,
414 $contributionProduct = CRM_Contribute_BAO_Contribution
::addPremium($data);
415 $this->assertEquals($contributionProduct->product_id
, $premium->id
, 'Check for Product id .');
418 CRM_Contribute_BAO_ManagePremiums
::del($premium->id
);
419 $this->assertDBNull('CRM_Contribute_DAO_Product', $premium->name
,
420 'id', 'name', 'Database check for deleted Product.'
425 * Check duplicate contribution id.
426 * during the contribution import
427 * checkDuplicateIds();
429 public function testcheckDuplicateIds() {
430 $contactId = $this->individualCreate();
433 'contact_id' => $contactId,
435 'financial_type_id' => 1,
436 'contribution_status_id' => 1,
437 'payment_instrument_id' => 1,
438 'source' => 'STUDENT',
439 'receive_date' => '20080522000000',
440 'receipt_date' => '20080522000000',
442 'non_deductible_amount' => 0.00,
443 'total_amount' => 300.00,
446 'trxn_id' => '76ereeswww835',
447 'invoice_id' => '93ed39a9e9hd621bs0eafe3da82',
448 'thankyou_date' => '20080522',
449 'sequential' => TRUE,
452 $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
454 $this->assertEquals($param['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
455 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
457 'id' => $contribution['id'],
458 'trxn_id' => $contribution['trxn_id'],
459 'invoice_id' => $contribution['invoice_id'],
461 $contributionID = CRM_Contribute_BAO_Contribution
::checkDuplicateIds($data);
462 $this->assertEquals($contributionID, $contribution['id'], 'Check for duplicate transcation id .');
466 * Check credit note id creation
467 * when a contribution is cancelled or refunded
468 * createCreditNoteId();
470 public function testCreateCreditNoteId() {
471 $contactId = $this->individualCreate();
474 'contact_id' => $contactId,
476 'financial_type_id' => 1,
477 'contribution_status_id' => 3,
478 'payment_instrument_id' => 1,
479 'source' => 'STUDENT',
480 'receive_date' => '20080522000000',
481 'receipt_date' => '20080522000000',
483 'non_deductible_amount' => 0.00,
484 'total_amount' => 300.00,
487 'trxn_id' => '76ereeswww835',
488 'invoice_id' => '93ed39a9e9hd621bs0eafe3da82',
489 'thankyou_date' => '20080522',
490 'sequential' => TRUE,
493 $creditNoteId = CRM_Contribute_BAO_Contribution
::createCreditNoteId();
494 $contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
495 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
496 $this->assertEquals($creditNoteId, $contribution['creditnote_id'], 'Check if credit note id is created correctly.');
500 * Create() method (create and update modes).
502 public function testIsPaymentFlag() {
503 $contactId = $this->individualCreate();
506 'contact_id' => $contactId,
508 'financial_type_id' => 1,
509 'contribution_status_id' => 1,
510 'payment_instrument_id' => 1,
511 'source' => 'STUDENT',
512 'receive_date' => '20080522000000',
513 'receipt_date' => '20080522000000',
514 'non_deductible_amount' => 0.00,
515 'total_amount' => 200.00,
518 'trxn_id' => '22ereerwww4444xx',
519 'invoice_id' => '86ed39c9e9ee6ef6541621ce0eafe7eb81',
520 'thankyou_date' => '20080522',
521 'sequential' => TRUE,
523 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
525 $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
526 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
529 'trxn_id' => $params['trxn_id'],
533 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
534 $this->assertEquals(1, $financialTrxn->N
, 'Mismatch count for is payment flag.');
535 //update contribution amount
536 $params['id'] = $contribution['id'];
537 $params['total_amount'] = 150;
538 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
540 $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .');
541 $this->assertEquals($params['total_amount'], $contribution['total_amount'], 'Check for Amount updation.');
543 'trxn_id' => $params['trxn_id'],
547 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
548 $this->assertEquals(2, $financialTrxn->N
, 'Mismatch count for is payment flag.');
549 $trxnArray['is_payment'] = 0;
550 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
551 $this->assertEquals(1, $financialTrxn->N
, 'Mismatch count for is payment flag.');
555 * Create() method (create and update modes).
557 public function testIsPaymentFlagForPending() {
558 $contactId = $this->individualCreate();
561 'contact_id' => $contactId,
563 'financial_type_id' => 1,
564 'contribution_status_id' => 2,
565 'payment_instrument_id' => 1,
566 'source' => 'STUDENT',
568 'receive_date' => '20080522000000',
569 'receipt_date' => '20080522000000',
570 'non_deductible_amount' => 0.00,
571 'total_amount' => 200.00,
574 'trxn_id' => '22ereerwww4444yy',
575 'invoice_id' => '86ed39c9e9yy6ef6541621ce0eafe7eb81',
576 'thankyou_date' => '20080522',
577 'sequential' => TRUE,
580 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
582 $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transaction id creation.');
583 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
586 'trxn_id' => $params['trxn_id'],
590 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
591 $this->assertEquals(2, $financialTrxn->N
, 'Mismatch count for is payment flag.');
592 $trxnArray['is_payment'] = 1;
593 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
594 $this->assertEquals(NULL, $financialTrxn, 'Mismatch count for is payment flag.');
595 //update contribution amount
596 $params['id'] = $contribution['id'];
597 $params['contribution_status_id'] = 1;
599 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
601 $this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .');
602 $this->assertEquals($params['contribution_status_id'], $contribution['contribution_status_id'], 'Check for status updation.');
604 'trxn_id' => $params['trxn_id'],
608 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
609 $this->assertEquals(1, $financialTrxn->N
, 'Mismatch count for is payment flag.');
610 $trxnArray['is_payment'] = 0;
611 $financialTrxn = CRM_Core_BAO_FinancialTrxn
::retrieve($trxnArray, $defaults);
612 $this->assertEquals(2, $financialTrxn->N
, 'Mismatch count for is payment flag.');
616 * addPayments() method (add and edit modes of participant)
618 public function testAddPayments() {
619 list($lineItems, $contribution) = $this->addParticipantWithContribution();
620 CRM_Contribute_BAO_Contribution
::addPayments([$contribution]);
621 $this->checkItemValues($contribution);
625 * checks db values for financial item
627 public function checkItemValues($contribution) {
628 $toFinancialAccount = CRM_Contribute_PseudoConstant
::getRelationalFinancialAccount(4, 'Accounts Receivable Account is');
629 $query = "SELECT eft1.entity_id, ft.total_amount, eft1.amount FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution')
630 INNER JOIN civicrm_entity_financial_trxn eft1 ON (eft1.financial_trxn_id = eft.financial_trxn_id AND eft1.entity_table = 'civicrm_financial_item')
631 WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
633 $queryParams[1] = array($contribution->id
, 'Integer');
634 $queryParams[2] = array($toFinancialAccount, 'Integer');
636 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
637 $amounts = array(100.00, 50.00);
638 while ($dao->fetch()) {
639 $this->assertEquals(150.00, $dao->total_amount
, 'Mismatch of total amount paid.');
640 $this->assertEquals($dao->amount
, array_pop($amounts), 'Mismatch of amount proportionally assigned to financial item');
645 * assignProportionalLineItems() method (add and edit modes of participant)
647 public function testAssignProportionalLineItems() {
648 list($lineItems, $contribution) = $this->addParticipantWithContribution();
650 'contribution_id' => $contribution->id
,
651 'total_amount' => 150.00,
653 $trxn = new CRM_Financial_DAO_FinancialTrxn();
654 $trxn->orderBy('id DESC');
656 CRM_Contribute_BAO_Contribution
::assignProportionalLineItems($params, $trxn->id
, $contribution->total_amount
);
657 $this->checkItemValues($contribution);
661 * Add participant with contribution
665 public function addParticipantWithContribution() {
666 // creating price set, price field
667 $this->_contactId
= $this->individualCreate();
668 $event = $this->eventCreate();
669 $this->_eventId
= $event['id'];
670 $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4);
671 $paramsSet['name'] = CRM_Utils_String
::titleToVar($paramsSet['title']);
672 $paramsSet['is_active'] = TRUE;
673 $paramsSet['financial_type_id'] = 4;
674 $paramsSet['extends'] = 1;
676 $priceset = CRM_Price_BAO_PriceSet
::create($paramsSet);
677 $priceSetId = $priceset->id
;
679 //Checking for priceset added in the table.
680 $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
681 'id', $paramsSet['title'], 'Check DB for created priceset'
683 $paramsField = array(
684 'label' => 'Price Field',
685 'name' => CRM_Utils_String
::titleToVar('Price Field'),
686 'html_type' => 'CheckBox',
687 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
688 'option_value' => array('1' => 100, '2' => 200),
689 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
690 'option_weight' => array('1' => 1, '2' => 2),
691 'option_amount' => array('1' => 100, '2' => 200),
692 'is_display_amounts' => 1,
694 'options_per_line' => 1,
695 'is_active' => array('1' => 1, '2' => 1),
696 'price_set_id' => $priceset->id
,
698 'financial_type_id' => CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'),
700 $priceField = CRM_Price_BAO_PriceField
::create($paramsField);
701 $eventParams = array(
702 'id' => $this->_eventId
,
703 'financial_type_id' => 4,
706 CRM_Event_BAO_Event
::create($eventParams);
707 CRM_Price_BAO_PriceSet
::addTo('civicrm_event', $this->_eventId
, $priceSetId);
709 $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id
));
710 $participantParams = array(
711 'financial_type_id' => 4,
712 'event_id' => $this->_eventId
,
715 'fee_currency' => 'USD',
716 'contact_id' => $this->_contactId
,
718 $participant = CRM_Event_BAO_Participant
::add($participantParams);
719 $contributionParams = array(
720 'total_amount' => 150,
722 'contact_id' => $this->_contactId
,
723 'financial_type_id' => 4,
724 'contribution_status_id' => 1,
725 'partial_payment_total' => 300.00,
726 'partial_amount_to_pay' => 150,
727 'contribution_mode' => 'participant',
728 'participant_id' => $participant->id
,
729 'sequential' => TRUE,
732 foreach ($priceFields['values'] as $key => $priceField) {
733 $lineItems[1][$key] = array(
734 'price_field_id' => $priceField['price_field_id'],
735 'price_field_value_id' => $priceField['id'],
736 'label' => $priceField['label'],
737 'field_title' => $priceField['label'],
739 'unit_price' => $priceField['amount'],
740 'line_total' => $priceField['amount'],
741 'financial_type_id' => $priceField['financial_type_id'],
744 $contributionParams['line_item'] = $lineItems;
745 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams)['values'][0];
747 $paymentParticipant = array(
748 'participant_id' => $participant->id
,
749 'contribution_id' => $contribution['id'],
751 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant);
753 $contributionObject = new CRM_Contribute_BAO_Contribution();
754 $contributionObject->id
= $contribution['id'];
755 $contributionObject->find(TRUE);
757 return array($lineItems, $contributionObject);
761 * checkLineItems() check if total amount matches the sum of line total
763 public function testcheckLineItems() {
766 'receive_date' => '2010-01-20',
767 'total_amount' => 100,
768 'financial_type_id' => 3,
769 'line_items' => array(
771 'line_item' => array(
773 'entity_table' => 'civicrm_contribution',
774 'price_field_id' => 8,
775 'price_field_value_id' => 16,
782 'entity_table' => 'civicrm_contribution',
783 'price_field_id' => 8,
784 'price_field_value_id' => 17,
789 'financial_type_id' => 1,
797 CRM_Contribute_BAO_Contribution
::checkLineItems($params);
798 $this->fail("Missed expected exception");
800 catch (Exception
$e) {
801 $this->assertEquals("Line item total doesn't match with total amount.", $e->getMessage());
803 $this->assertEquals(3, $params['line_items'][0]['line_item'][0]['financial_type_id']);
804 $params['total_amount'] = 300;
805 CRM_Contribute_BAO_Contribution
::checkLineItems($params);
809 * Test activity amount updation.
811 public function testActivityCreate() {
812 $contactId = $this->individualCreate();
816 'contact_id' => $contactId,
818 'financial_type_id' => 1,
819 'contribution_status_id' => 1,
820 'payment_instrument_id' => 1,
821 'source' => 'STUDENT',
822 'receive_date' => '20080522000000',
823 'receipt_date' => '20080522000000',
824 'non_deductible_amount' => 0.00,
825 'total_amount' => 100.00,
826 'trxn_id' => '22ereerwww444444',
827 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81',
828 'thankyou_date' => '20160519',
832 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
834 $this->assertEquals($params['total_amount'], $contribution['total_amount'], 'Check for total amount in contribution.');
835 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
837 // Check amount in activity.
838 $activityParams = array(
839 'source_record_id' => $contribution['id'],
840 'activity_type_id' => CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Contribution'),
842 // @todo use api instead.
843 $activity = CRM_Activity_BAO_Activity
::retrieve($activityParams, $defaults);
845 $this->assertEquals($contribution['id'], $activity->source_record_id
, 'Check for activity associated with contribution.');
846 $this->assertEquals("$ 100.00 - STUDENT", $activity->subject
, 'Check for total amount in activity.');
848 $params['id'] = $contribution['id'];
849 $params['total_amount'] = 200;
851 $contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
853 $this->assertEquals($params['total_amount'], $contribution['total_amount'], 'Check for total amount in contribution.');
854 $this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
856 // Retrieve activity again.
857 $activity = CRM_Activity_BAO_Activity
::retrieve($activityParams, $defaults);
859 $this->assertEquals($contribution['id'], $activity->source_record_id
, 'Check for activity associated with contribution.');
860 $this->assertEquals("$ 200.00 - STUDENT", $activity->subject
, 'Check for total amount in activity.');
864 * Test checkContributeSettings.
866 public function testCheckContributeSettings() {
867 $settings = CRM_Contribute_BAO_Contribution
::checkContributeSettings('deferred_revenue_enabled');
868 $this->assertNull($settings);
870 'contribution_invoice_settings' => array(
871 'deferred_revenue_enabled' => '1',
874 $this->callAPISuccess('Setting', 'create', $params);
875 $settings = CRM_Contribute_BAO_Contribution
::checkContributeSettings('deferred_revenue_enabled');
876 $this->assertEquals($settings, 1, 'Check for settings has failed');
880 * Test allowUpdateRevenueRecognitionDate.
882 public function testAllowUpdateRevenueRecognitionDate() {
883 $contactId = $this->individualCreate();
885 'contact_id' => $contactId,
886 'receive_date' => '2010-01-20',
887 'total_amount' => 100,
888 'financial_type_id' => 4,
890 $order = $this->callAPISuccess('order', 'create', $params);
891 $allowUpdate = CRM_Contribute_BAO_Contribution
::allowUpdateRevenueRecognitionDate($order['id']);
892 $this->assertTrue($allowUpdate);
894 $event = $this->eventCreate();
896 'contact_id' => $contactId,
897 'receive_date' => '2010-01-20',
898 'total_amount' => 300,
899 'financial_type_id' => $this->getFinancialTypeId('Event Fee'),
900 'contribution_status_id' => 'Completed',
902 $priceFields = $this->createPriceSet('event', $event['id']);
903 foreach ($priceFields['values'] as $key => $priceField) {
904 $lineItems[$key] = array(
905 'price_field_id' => $priceField['price_field_id'],
906 'price_field_value_id' => $priceField['id'],
907 'label' => $priceField['label'],
908 'field_title' => $priceField['label'],
910 'unit_price' => $priceField['amount'],
911 'line_total' => $priceField['amount'],
912 'financial_type_id' => $priceField['financial_type_id'],
913 'entity_table' => 'civicrm_participant',
916 $params['line_items'][] = array(
917 'line_item' => $lineItems,
919 'contact_id' => $contactId,
920 'event_id' => $event['id'],
923 'register_date' => '2007-07-21 00:00:00',
924 'source' => 'Online Event Registration: API Testing',
927 $order = $this->callAPISuccess('order', 'create', $params);
928 $allowUpdate = CRM_Contribute_BAO_Contribution
::allowUpdateRevenueRecognitionDate($order['id']);
929 $this->assertFalse($allowUpdate);
932 'contact_id' => $contactId,
933 'receive_date' => '2010-01-20',
934 'total_amount' => 200,
935 'financial_type_id' => $this->getFinancialTypeId('Member Dues'),
936 'contribution_status_id' => 'Completed',
938 $membershipType = $this->membershipTypeCreate();
939 $priceFields = $this->createPriceSet();
940 $lineItems = array();
941 foreach ($priceFields['values'] as $key => $priceField) {
942 $lineItems[$key] = array(
943 'price_field_id' => $priceField['price_field_id'],
944 'price_field_value_id' => $priceField['id'],
945 'label' => $priceField['label'],
946 'field_title' => $priceField['label'],
948 'unit_price' => $priceField['amount'],
949 'line_total' => $priceField['amount'],
950 'financial_type_id' => $priceField['financial_type_id'],
951 'entity_table' => 'civicrm_membership',
952 'membership_type_id' => $membershipType,
955 $params['line_items'][] = array(
956 'line_item' => array(array_pop($lineItems)),
958 'contact_id' => $contactId,
959 'membership_type_id' => $membershipType,
960 'join_date' => '2006-01-21',
961 'start_date' => '2006-01-21',
962 'end_date' => '2006-12-21',
963 'source' => 'Payment',
968 $order = $this->callAPISuccess('order', 'create', $params);
969 $allowUpdate = CRM_Contribute_BAO_Contribution
::allowUpdateRevenueRecognitionDate($order['id']);
970 $this->assertFalse($allowUpdate);
974 * Test calculateFinancialItemAmount().
976 public function testcalculateFinancialItemAmount() {
980 'amountParams' => array(
982 'previous_line_total' => 300,
985 'context' => 'changedAmount',
986 'expectedItemAmount' => -200,
990 'amountParams' => array(
992 'previous_line_total' => 100,
995 'context' => 'changePaymentInstrument',
996 'expectedItemAmount' => -100,
1000 'is_quick_config' => TRUE,
1001 'total_amount' => 110,
1004 'amountParams' => array(
1005 'item_amount' => 100,
1007 'context' => 'changedAmount',
1008 'expectedItemAmount' => 100,
1012 'is_quick_config' => TRUE,
1013 'total_amount' => 110,
1016 'amountParams' => array(
1017 'item_amount' => NULL,
1019 'context' => 'changedAmount',
1020 'expectedItemAmount' => 110,
1024 'is_quick_config' => TRUE,
1025 'total_amount' => 110,
1028 'amountParams' => array(
1029 'item_amount' => NULL,
1032 'expectedItemAmount' => 100,
1035 foreach ($testParams as $params) {
1036 $itemAmount = CRM_Contribute_BAO_Contribution
::calculateFinancialItemAmount($params['params'], $params['amountParams'], $params['context']);
1037 $this->assertEquals($itemAmount, $params['expectedItemAmount'], 'Invalid Financial Item amount.');
1042 * Test recording of amount with comma separator.
1044 public function testCommaSeparatorAmount() {
1045 $contactId = $this->individualCreate();
1048 'contact_id' => $contactId,
1049 'currency' => 'USD',
1050 'financial_type_id' => 1,
1051 'contribution_status_id' => 8,
1052 'payment_instrument_id' => 1,
1053 'receive_date' => '20080522000000',
1054 'receipt_date' => '20080522000000',
1055 'total_amount' => '20000.00',
1056 'partial_payment_total' => '20,000.00',
1057 'partial_amount_to_pay' => '8,000.00',
1060 $contribution = $this->callAPISuccess('Contribution', 'create', $params);
1061 $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($contribution['id'], 'DESC');
1062 $financialTrxn = $this->callAPISuccessGetSingle(
1065 'id' => $lastFinancialTrxnId['financialTrxnId'],
1066 'return' => array('total_amount'),
1069 $this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid Tax amount.');
1073 * Test for function getSalesTaxFinancialAccounts().
1075 public function testgetSalesTaxFinancialAccounts() {
1076 $this->enableTaxAndInvoicing();
1077 $financialType = $this->createFinancialType();
1078 $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
1079 $expectedResult = array($financialAccount->financial_account_id
=> $financialAccount->financial_account_id
);
1080 $financialType = $this->createFinancialType();
1081 $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
1082 $expectedResult[$financialAccount->financial_account_id
] = $financialAccount->financial_account_id
;
1083 $salesTaxFinancialAccount = CRM_Contribute_BAO_Contribution
::getSalesTaxFinancialAccounts();
1084 $this->assertTrue(($salesTaxFinancialAccount == $expectedResult), 'Function returned wrong values.');
1088 * Test for function createProportionalEntry().
1090 * @param string $thousandSeparator
1091 * punctuation used to refer to thousands.
1093 * @dataProvider getThousandSeparators
1095 public function testCreateProportionalEntry($thousandSeparator) {
1096 $this->setCurrencySeparators($thousandSeparator);
1097 list($contribution, $financialAccount) = $this->createContributionWithTax();
1099 'total_amount' => 55,
1100 'to_financial_account_id' => $financialAccount->financial_account_id
,
1101 'payment_instrument_id' => 1,
1102 'trxn_date' => date('Ymd'),
1104 'entity_id' => $contribution['id'],
1106 $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
1107 $entityParams = array(
1108 'contribution_total_amount' => $contribution['total_amount'],
1109 'trxn_total_amount' => 55,
1110 'line_item_amount' => 100,
1112 $previousLineItem = CRM_Financial_BAO_FinancialItem
::getPreviousFinancialItem($contribution['id']);
1114 'entity_table' => 'civicrm_financial_item',
1115 'entity_id' => $previousLineItem['id'],
1116 'financial_trxn_id' => (string) $financialTrxn['id'],
1118 CRM_Contribute_BAO_Contribution
::createProportionalEntry($entityParams, $eftParams);
1119 $trxnTestArray = array_merge($eftParams, array(
1120 'amount' => '50.00',
1122 $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
1126 * Test for function createProportionalEntry with zero amount().
1128 * @param string $thousandSeparator
1129 * punctuation used to refer to thousands.
1131 * @dataProvider getThousandSeparators
1133 public function testCreateProportionalEntryZeroAmount($thousandSeparator) {
1134 $this->setCurrencySeparators($thousandSeparator);
1135 list($contribution, $financialAccount) = $this->createContributionWithTax(array('total_amount' => 0));
1137 'total_amount' => 0,
1138 'to_financial_account_id' => $financialAccount->financial_account_id
,
1139 'payment_instrument_id' => 1,
1140 'trxn_date' => date('Ymd'),
1142 'entity_id' => $contribution['id'],
1144 $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
1145 $entityParams = array(
1146 'contribution_total_amount' => $contribution['total_amount'],
1147 'trxn_total_amount' => 0,
1148 'line_item_amount' => 0,
1150 $previousLineItem = CRM_Financial_BAO_FinancialItem
::getPreviousFinancialItem($contribution['id']);
1152 'entity_table' => 'civicrm_financial_item',
1153 'entity_id' => $previousLineItem['id'],
1154 'financial_trxn_id' => (string) $financialTrxn['id'],
1156 CRM_Contribute_BAO_Contribution
::createProportionalEntry($entityParams, $eftParams);
1157 $trxnTestArray = array_merge($eftParams, array(
1160 $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
1164 * Test for function getLastFinancialItemIds().
1166 public function testgetLastFinancialItemIds() {
1167 list($contribution, $financialAccount) = $this->createContributionWithTax();
1168 list($ftIds, $taxItems) = CRM_Contribute_BAO_Contribution
::getLastFinancialItemIds($contribution['id']);
1169 $this->assertEquals(count($ftIds), 1, 'Invalid count.');
1170 $this->assertEquals(count($taxItems), 1, 'Invalid count.');
1171 foreach ($taxItems as $value) {
1172 $this->assertEquals($value['amount'], 10, 'Invalid tax amount.');
1177 * Test for function createProportionalFinancialEntries().
1179 public function testcreateProportionalFinancialEntries() {
1180 list($contribution, $financialAccount) = $this->createContributionWithTax();
1182 'total_amount' => 50,
1183 'to_financial_account_id' => $financialAccount->financial_account_id
,
1184 'payment_instrument_id' => 1,
1185 'trxn_date' => date('Ymd'),
1187 'entity_id' => $contribution['id'],
1189 $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
1190 $entityParams = array(
1191 'contribution_total_amount' => $contribution['total_amount'],
1192 'trxn_total_amount' => 55,
1193 'trxn_id' => $financialTrxn['id'],
1195 $lineItems = CRM_Price_BAO_LineItem
::getLineItemsByContributionID($contribution['id']);
1196 list($ftIds, $taxItems) = CRM_Contribute_BAO_Contribution
::getLastFinancialItemIds($contribution['id']);
1197 CRM_Contribute_BAO_Contribution
::createProportionalFinancialEntries($entityParams, $lineItems, $ftIds, $taxItems);
1199 'entity_table' => 'civicrm_financial_item',
1200 'financial_trxn_id' => $financialTrxn['id'],
1202 $entityFinancialTrxn = $this->callAPISuccess('EntityFinancialTrxn', 'Get', $eftParams);
1203 $this->assertEquals($entityFinancialTrxn['count'], 2, 'Invalid count.');
1204 $testAmount = array(5, 50);
1205 foreach ($entityFinancialTrxn['values'] as $value) {
1206 $this->assertEquals($value['amount'], array_pop($testAmount), 'Invalid amount stored in civicrm_entity_financial_trxn.');
1211 * Test to check if amount is proportionally asigned for PI change.
1213 public function testProportionallyAssignedForPIChange() {
1214 list($contribution, $financialAccount) = $this->createContributionWithTax();
1216 'id' => $contribution['id'],
1217 'payment_instrument_id' => 3,
1219 $this->callAPISuccess('Contribution', 'create', $params);
1220 $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($contribution['id'], 'DESC');
1222 'entity_table' => 'civicrm_financial_item',
1223 'financial_trxn_id' => $lastFinancialTrxnId['financialTrxnId'],
1225 $entityFinancialTrxn = $this->callAPISuccess('EntityFinancialTrxn', 'Get', $eftParams);
1226 $this->assertEquals($entityFinancialTrxn['count'], 2, 'Invalid count.');
1227 $testAmount = array(10, 100);
1228 foreach ($entityFinancialTrxn['values'] as $value) {
1229 $this->assertEquals($value['amount'], array_pop($testAmount), 'Invalid amount stored in civicrm_entity_financial_trxn.');
1234 * Function to create contribution with tax.
1236 public function createContributionWithTax($params = array()) {
1237 if (!isset($params['total_amount'])) {
1238 $params['total_amount'] = 100;
1240 $contactId = $this->individualCreate();
1241 $this->enableTaxAndInvoicing();
1242 $financialType = $this->createFinancialType();
1243 $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
1244 $form = new CRM_Contribute_Form_Contribution();
1246 $form->testSubmit(array(
1247 'total_amount' => $params['total_amount'],
1248 'financial_type_id' => $financialType['id'],
1249 'contact_id' => $contactId,
1250 'contribution_status_id' => 1,
1251 'price_set_id' => 0,
1253 CRM_Core_Action
::ADD
1255 $contribution = $this->callAPISuccessGetSingle('Contribution',
1257 'contact_id' => $contactId,
1258 'return' => array('tax_amount', 'total_amount'),
1261 return array($contribution, $financialAccount);
1265 * Test processOnBehalfOrganization() function.
1267 public function testProcessOnBehalfOrganization() {
1269 'phone' => '11111111',
1270 'email' => 'testorg@gmail.com',
1271 'street_address' => 'test Street',
1272 'city' => 'test City',
1273 'state_province' => 'AA',
1274 'postal_code' => '222222',
1275 'country' => 'United States',
1277 $contactID = $this->individualCreate();
1278 $orgId = $this->organizationCreate(array('organization_name' => 'testorg1'));
1279 $orgCount = $this->callAPISuccessGetCount('Contact', array(
1280 'contact_type' => "Organization",
1281 'organization_name' => "testorg1",
1283 $this->assertEquals($orgCount, 1);
1285 $values = $params = array();
1286 $behalfOrganization = array(
1287 'organization_name' => 'testorg1',
1290 'phone' => $orgInfo['phone'],
1296 'email' => $orgInfo['email'],
1302 'street_address' => $orgInfo['street_address'],
1303 'city' => $orgInfo['city'],
1304 'location_type_id' => 3,
1305 'postal_code' => $orgInfo['postal_code'],
1307 'state_province' => 'AA',
1313 'organization_name' => 1,
1316 'street_address-3' => 1,
1318 'postal_code-3' => 1,
1320 'state_province-3' => 1,
1322 CRM_Contribute_Form_Contribution_Confirm
::processOnBehalfOrganization($behalfOrganization, $contactID, $values, $params, $fields);
1324 //Check whether new organisation is not created.
1325 $result = $this->callAPISuccess('Contact', 'get', array(
1326 'contact_type' => "Organization",
1327 'organization_name' => "testorg1",
1329 $this->assertEquals($result['count'], 1);
1331 //Assert all org values are updated.
1332 foreach ($orgInfo as $key => $val) {
1333 $this->assertEquals($result['values'][$orgId][$key], $val);
1336 //Check if alert is assigned to params if more than 1 dupe exists.
1337 $orgId = $this->organizationCreate(array('organization_name' => 'testorg1', 'email' => 'testorg@gmail.com'));
1338 CRM_Contribute_Form_Contribution_Confirm
::processOnBehalfOrganization($behalfOrganization, $contactID, $values, $params, $fields);
1339 $this->assertEquals($params['onbehalf_dupe_alert'], 1);
1343 * Test for replaceContributionTokens.
1344 * This function tests whether the contribution tokens are replaced with values from contribution.
1346 public function testReplaceContributionTokens() {
1347 $contactId1 = $this->individualCreate();
1349 'contact_id' => $contactId1,
1350 'receive_date' => '20120511',
1351 'total_amount' => 100.00,
1352 'financial_type_id' => 1,
1354 'invoice_id' => 67890,
1356 'contribution_status_id' => 2,
1358 $contribution1 = $this->contributionCreate($params);
1359 $contactId2 = $this->individualCreate();
1361 'contact_id' => $contactId2,
1362 'receive_date' => '20150511',
1363 'total_amount' => 200.00,
1364 'financial_type_id' => 1,
1366 'invoice_id' => 12345,
1368 'contribution_status_id' => 1,
1370 $contribution2 = $this->contributionCreate($params);
1371 $ids = array($contribution1, $contribution2);
1373 $subject = "This is a test for contribution ID: {contribution.contribution_id}";
1374 $text = "Contribution Amount: {contribution.total_amount}";
1375 $html = "<p>Contribution Source: {contribution.contribution_source}</p></br>
1376 <p>Contribution Invoice ID: {contribution.invoice_id}</p></br>
1377 <p>Contribution Receive Date: {contribution.receive_date}</p></br>";
1379 $subjectToken = CRM_Utils_Token
::getTokens($subject);
1380 $messageToken = CRM_Utils_Token
::getTokens($text);
1381 $messageToken = array_merge($messageToken, CRM_Utils_Token
::getTokens($html));
1383 $contributionDetails = CRM_Contribute_BAO_Contribution
::replaceContributionTokens(
1393 $this->assertEquals("Contribution Amount: $ 100.00", $contributionDetails[$contactId1]['text'], "The text does not match");
1394 $this->assertEquals("<p>Contribution Source: ABC</p></br>
1395 <p>Contribution Invoice ID: 12345</p></br>
1396 <p>Contribution Receive Date: May 11th, 2015</p></br>", $contributionDetails[$contactId2]['html'], "The html does not match");
1400 * Test for contribution with deferred revenue.
1402 public function testContributionWithDeferredRevenue() {
1403 $contactId = $this->individualCreate();
1404 Civi
::settings()->set('deferred_revenue_enabled', TRUE);
1406 'contact_id' => $contactId,
1407 'receive_date' => '20120511',
1408 'total_amount' => 100.00,
1409 'financial_type_id' => 'Event Fee',
1411 'invoice_id' => 67890,
1413 'contribution_status_id' => 'Completed',
1414 'revenue_recognition_date' => date('Ymd', strtotime("+3 month")),
1416 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1418 $this->callAPISuccessGetCount('EntityFinancialTrxn', array(
1419 'entity_table' => "civicrm_contribution",
1420 'entity_id' => $contribution['id'],
1423 $checkAgainst = array(
1424 'financial_trxn_id.to_financial_account_id.name' => 'Deferred Revenue - Event Fee',
1425 'financial_trxn_id.from_financial_account_id.name' => 'Event Fee',
1426 'financial_trxn_id' => '2',
1428 $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array(
1430 "financial_trxn_id.from_financial_account_id.name",
1431 "financial_trxn_id.to_financial_account_id.name",
1432 "financial_trxn_id",
1434 'entity_table' => "civicrm_contribution",
1435 'entity_id' => $contribution['id'],
1436 'financial_trxn_id.is_payment' => 0,
1439 $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array(
1440 'entity_table' => "civicrm_financial_item",
1441 'financial_trxn_id' => $result['financial_trxn_id'],
1442 'return' => array('entity_id'),
1445 $checkAgainst = array(
1446 'financial_account_id.name' => 'Deferred Revenue - Event Fee',
1447 'id' => $result['entity_id'],
1449 $result = $this->callAPISuccessGetSingle('FinancialItem', array(
1450 'id' => $result['entity_id'],
1451 'return' => array("financial_account_id.name"),
1456 * CRM-21424 Check if the receipt update is set after composing the receipt message
1458 public function testSendMailUpdateReceiptDate() {
1459 $ids = $values = array();
1460 $contactId = $this->individualCreate();
1462 'contact_id' => $contactId,
1463 'receive_date' => '20120511',
1464 'total_amount' => 100.00,
1465 'financial_type_id' => 'Donation',
1467 'contribution_status_id' => 'Completed',
1469 /* first test the scenario when sending an email */
1470 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1471 $contributionId = $contribution['id'];
1472 $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null');
1473 $input = array('receipt_update' => 0);
1474 CRM_Contribute_BAO_Contribution
::sendMail($input, $ids, $contributionId, $values);
1475 $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null');
1476 $input = array('receipt_update' => 1);
1477 CRM_Contribute_BAO_Contribution
::sendMail($input, $ids, $contributionId, $values);
1478 $this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set');
1480 /* repeat the same scenario for downloading a pdf */
1481 $contribution = $this->callAPISuccess('contribution', 'create', $params);
1482 $contributionId = $contribution['id'];
1483 $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null');
1484 $input = array('receipt_update' => 0);
1485 /* setting the lasast parameter (returnmessagetext) to TRUE is done by the download of the pdf */
1486 CRM_Contribute_BAO_Contribution
::sendMail($input, $ids, $contributionId, $values, TRUE);
1487 $this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null');
1488 $input = array('receipt_update' => 1);
1489 CRM_Contribute_BAO_Contribution
::sendMail($input, $ids, $contributionId, $values, TRUE);
1490 $this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set');