tests/phpunit - Declare `@group headless`
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Form / ContributionTest.php
CommitLineData
a084385f
EM
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
a084385f
EM
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
a084385f
EM
28/**
29 * Test APIv3 civicrm_contribute_* functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
acb109b7 33 * @group headless
a084385f
EM
34 */
35class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
36
37 /**
38 * Assume empty database with just civicrm_data.
39 */
40 protected $_individualId;
41 protected $_contribution;
42 protected $_financialTypeId = 1;
43 protected $_apiversion;
44 protected $_entity = 'Contribution';
45 protected $_params;
46 protected $_ids = array();
47 protected $_pageParams = array();
48
49 /**
50 * Parameters to create payment processor.
51 *
52 * @var array
53 */
54 protected $_processorParams = array();
55
56 /**
57 * ID of created event.
58 *
59 * @var int
60 */
61 protected $_eventID;
62
63 /**
64 * Payment instrument mapping.
65 *
66 * @var array
67 */
68 protected $paymentInstruments = array();
69
3e6a1f4a
EM
70 /**
71 * Products.
72 *
73 * @var array
74 */
75 protected $products = array();
76
39f47c0d
EM
77 /**
78 * Dummy payment processor.
79 *
7758bd2b 80 * @var CRM_Core_Payment_Dummy
39f47c0d 81 */
7758bd2b 82 protected $paymentProcessor;
39f47c0d 83
22e39333 84 /**
85 * Payment processor ID.
86 *
87 * @var int
88 */
89 protected $paymentProcessorID;
90
a084385f
EM
91 /**
92 * Setup function.
93 */
94 public function setUp() {
39f47c0d 95 $this->_apiversion = 3;
a084385f 96 parent::setUp();
39f47c0d 97 $this->createLoggedInUser();
a084385f 98
a084385f 99 $this->_individualId = $this->individualCreate();
a084385f
EM
100 $this->_params = array(
101 'contact_id' => $this->_individualId,
102 'receive_date' => '20120511',
103 'total_amount' => 100.00,
104 'financial_type_id' => $this->_financialTypeId,
105 'non_deductible_amount' => 10.00,
106 'fee_amount' => 5.00,
107 'net_amount' => 95.00,
108 'source' => 'SSF',
109 'contribution_status_id' => 1,
110 );
111 $this->_processorParams = array(
112 'domain_id' => 1,
113 'name' => 'Dummy',
114 'payment_processor_type_id' => 10,
115 'financial_account_id' => 12,
116 'is_active' => 1,
117 'user_name' => '',
118 'url_site' => 'http://dummy.com',
119 'url_recur' => 'http://dummy.com',
120 'billing_mode' => 1,
121 );
7758bd2b 122
a084385f
EM
123 $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
124 $this->paymentInstruments = $instruments['values'];
3e6a1f4a
EM
125 $product1 = $this->callAPISuccess('product', 'create', array(
126 'name' => 'Smurf',
127 'options' => 'brainy smurf, clumsy smurf, papa smurf',
128 ));
129
130 $this->products[] = $product1['values'][$product1['id']];
22e39333 131 $this->paymentProcessor = $this->dummyProcessorCreate();
132 $processor = $this->paymentProcessor->getPaymentProcessor();
133 $this->paymentProcessorID = $processor['id'];
a084385f
EM
134 }
135
136 /**
137 * Clean up after each test.
138 */
139 public function tearDown() {
140 $this->quickCleanUpFinancialEntities();
739a8336 141 $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address'));
a084385f
EM
142 }
143
144 /**
145 * Test the submit function on the contribution page.
146 */
147 public function testSubmit() {
148 $form = new CRM_Contribute_Form_Contribution();
149 $form->testSubmit(array(
150 'total_amount' => 50,
151 'financial_type_id' => 1,
152 'receive_date' => '04/21/2015',
153 'receive_date_time' => '11:27PM',
154 'contact_id' => $this->_individualId,
155 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
5e27919e 156 'contribution_status_id' => 1,
31760f81
EM
157 ),
158 CRM_Core_Action::ADD);
2b308818
DG
159 $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
160 $this->assertEmpty($contribution['amount_level']);
a084385f
EM
161 }
162
163 /**
164 * Test the submit function on the contribution page.
165 */
166 public function testSubmitCreditCard() {
167 $form = new CRM_Contribute_Form_Contribution();
168 $form->testSubmit(array(
169 'total_amount' => 50,
170 'financial_type_id' => 1,
171 'receive_date' => '04/21/2015',
172 'receive_date_time' => '11:27PM',
173 'contact_id' => $this->_individualId,
174 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
5e27919e 175 'contribution_status_id' => 1,
31760f81 176 ), CRM_Core_Action::ADD);
7758bd2b
EM
177 $this->callAPISuccessGetCount('Contribution', array(
178 'contact_id' => $this->_individualId,
179 'contribution_status_id' => 'Completed',
180 ),
181 1);
a084385f
EM
182 }
183
f8453bef 184 /**
185 * Test the submit function on the contribution page.
186 */
187 public function testSubmitCreditCardPayPal() {
188 $form = new CRM_Contribute_Form_Contribution();
189 $paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0));
190 $form->_mode = 'Live';
191 try {
192 $form->testSubmit(array(
193 'total_amount' => 50,
194 'financial_type_id' => 1,
195 'receive_date' => '04/21/2015',
196 'receive_date_time' => '11:27PM',
197 'contact_id' => $this->_individualId,
198 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
199 'contribution_status_id' => 1,
200 'credit_card_number' => 4444333322221111,
201 'cvv2' => 123,
202 'credit_card_exp_date' => array(
203 'M' => 9,
204 'Y' => 2025,
205 ),
206 'credit_card_type' => 'Visa',
207 'billing_first_name' => 'Junko',
208 'billing_middle_name' => '',
209 'billing_last_name' => 'Adams',
210 'billing_street_address-5' => '790L Lincoln St S',
211 'billing_city-5' => 'Maryknoll',
212 'billing_state_province_id-5' => 1031,
213 'billing_postal_code-5' => 10545,
214 'billing_country_id-5' => 1228,
215 'frequency_interval' => 1,
216 'frequency_unit' => 'month',
217 'installments' => '',
218 'hidden_AdditionalDetail' => 1,
219 'hidden_Premium' => 1,
220 'from_email_address' => '"civi45" <civi45@civicrm.com>',
221 'receipt_date' => '',
222 'receipt_date_time' => '',
223 'payment_processor_id' => $paymentProcessorID,
224 'currency' => 'USD',
225 'source' => '',
226 ), CRM_Core_Action::ADD);
227 }
228 catch (Civi\Payment\Exception\PaymentProcessorException $e) {
f9c3b374 229 $this->assertEquals('Transaction cannot be processed. Please use a different payment card.',
f8453bef 230 $e->getMessage());
231 }
232 $this->callAPISuccessGetCount('Contribution', array(
233 'contact_id' => $this->_individualId,
234 'contribution_status_id' => 'Pending',
235 ), 1);
236 }
237
22e39333 238 /**
239 * Test the submit function on the contribution page.
240 */
241 public function testSubmitCreditCardFee() {
242 $form = new CRM_Contribute_Form_Contribution();
243 print_r($this->paymentProcessor);
244 $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08));
245 $form->_mode = 'Live';
246 $form->testSubmit(array(
247 'total_amount' => 50,
248 'financial_type_id' => 1,
249 'receive_date' => '04/21/2015',
250 'receive_date_time' => '11:27PM',
251 'contact_id' => $this->_individualId,
252 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
253 'contribution_status_id' => 1,
254 'credit_card_number' => 4444333322221111,
255 'cvv2' => 123,
256 'credit_card_exp_date' => array(
257 'M' => 9,
258 'Y' => 2025,
259 ),
260 'credit_card_type' => 'Visa',
261 'billing_first_name' => 'Junko',
262 'billing_middle_name' => '',
263 'billing_last_name' => 'Adams',
264 'billing_street_address-5' => '790L Lincoln St S',
265 'billing_city-5' => 'Maryknoll',
266 'billing_state_province_id-5' => 1031,
267 'billing_postal_code-5' => 10545,
268 'billing_country_id-5' => 1228,
269 'frequency_interval' => 1,
270 'frequency_unit' => 'month',
271 'installments' => '',
272 'hidden_AdditionalDetail' => 1,
273 'hidden_Premium' => 1,
274 'from_email_address' => '"civi45" <civi45@civicrm.com>',
275 'receipt_date' => '',
276 'receipt_date_time' => '',
277 'payment_processor_id' => $this->paymentProcessorID,
278 'currency' => 'USD',
279 'source' => '',
280 ), CRM_Core_Action::ADD);
281
282 $contribution = $this->callAPISuccessGetSingle('Contribution', array(
283 'contact_id' => $this->_individualId,
284 'contribution_status_id' => 'Completed',
285 ));
286 $this->assertEquals('50', $contribution['total_amount']);
287 $this->assertEquals(.08, $contribution['fee_amount']);
288 $this->assertEquals(49.92, $contribution['net_amount']);
289 $this->assertEquals('tx', $contribution['trxn_id']);
2b308818 290 $this->assertEmpty($contribution['amount_level']);
22e39333 291 }
292
11829025
JMW
293 /**
294 * Test a fully deductible contribution submitted by credit card (CRM-16669).
295 */
296 public function testSubmitCreditCardFullyDeductible() {
297 $form = new CRM_Contribute_Form_Contribution();
298 $form->_mode = 'Live';
299 $form->testSubmit(array(
300 'total_amount' => 50,
301 'financial_type_id' => 1,
302 'receive_date' => '04/21/2015',
303 'receive_date_time' => '11:27PM',
304 'contact_id' => $this->_individualId,
305 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
306 'contribution_status_id' => 1,
307 'credit_card_number' => 4444333322221111,
308 'cvv2' => 123,
309 'credit_card_exp_date' => array(
310 'M' => 9,
311 'Y' => 2025,
312 ),
313 'credit_card_type' => 'Visa',
314 'billing_first_name' => 'Junko',
315 'billing_middle_name' => '',
316 'billing_last_name' => 'Adams',
317 'billing_street_address-5' => '790L Lincoln St S',
318 'billing_city-5' => 'Maryknoll',
319 'billing_state_province_id-5' => 1031,
320 'billing_postal_code-5' => 10545,
321 'billing_country_id-5' => 1228,
322 'frequency_interval' => 1,
323 'frequency_unit' => 'month',
324 'installments' => '',
325 'hidden_AdditionalDetail' => 1,
326 'hidden_Premium' => 1,
327 'from_email_address' => '"civi45" <civi45@civicrm.com>',
328 'receipt_date' => '',
329 'receipt_date_time' => '',
330 'payment_processor_id' => $this->paymentProcessorID,
331 'currency' => 'USD',
332 'source' => '',
333 ), CRM_Core_Action::ADD);
334
335 $contribution = $this->callAPISuccessGetSingle('Contribution', array(
336 'contact_id' => $this->_individualId,
337 'contribution_status_id' => 'Completed',
338 ));
339 $this->assertEquals('50', $contribution['total_amount']);
340 $this->assertEquals(0, $contribution['non_deductible_amount']);
341 }
342
7126b55c 343 /**
7758bd2b
EM
344 * Test the submit function with an invalid payment.
345 *
346 * We expect the contribution to be created but left pending. The payment has failed.
347 *
348 * Test covers CRM-16417 change to keep failed transactions.
349 *
350 * We are left with
351 * - 1 Contribution with status = Pending
352 * - 1 Line item
353 * - 1 civicrm_financial_item. This is linked to the line item and has a status of 3
7126b55c 354 */
7758bd2b 355 public function testSubmitCreditCardInvalid() {
7126b55c 356 $form = new CRM_Contribute_Form_Contribution();
7758bd2b
EM
357 $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 1));
358 try {
359 $form->testSubmit(array(
360 'total_amount' => 50,
361 'financial_type_id' => 1,
362 'receive_date' => '04/21/2015',
363 'receive_date_time' => '11:27PM',
364 'contact_id' => $this->_individualId,
365 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
22e39333 366 'payment_processor_id' => $this->paymentProcessorID,
7758bd2b
EM
367 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012),
368 'credit_card_number' => '411111111111111',
369 ), CRM_Core_Action::ADD,
739a8336 370 'live'
371 );
7758bd2b
EM
372 }
373 catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
40f5ec68
EM
374 $this->callAPISuccessGetCount('Contribution', array(
375 'contact_id' => $this->_individualId,
376 'contribution_status_id' => 'Pending',
377 ), 1);
7758bd2b
EM
378 $lineItem = $this->callAPISuccessGetSingle('line_item', array());
379 $this->assertEquals('50.00', $lineItem['unit_price']);
380 $this->assertEquals('50.00', $lineItem['line_total']);
381 $this->assertEquals(1, $lineItem['qty']);
382 $this->assertEquals(1, $lineItem['financial_type_id']);
383 $financialItem = $this->callAPISuccessGetSingle('financial_item', array(
384 'civicrm_line_item' => $lineItem['id'],
385 'entity_id' => $lineItem['id'],
386 ));
387 $this->assertEquals('50.00', $financialItem['amount']);
388 $this->assertEquals(3, $financialItem['status_id']);
389 return;
390 }
391 $this->fail('An expected exception has not been raised.');
7126b55c
EM
392 }
393
739a8336 394 /**
395 * Test the submit function creates a billing address if provided.
396 */
397 public function testSubmitCreditCardWithBillingAddress() {
398 $form = new CRM_Contribute_Form_Contribution();
399 $form->testSubmit(array(
400 'total_amount' => 50,
401 'financial_type_id' => 1,
402 'receive_date' => '04/21/2015',
403 'receive_date_time' => '11:27PM',
404 'contact_id' => $this->_individualId,
405 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
22e39333 406 'payment_processor_id' => $this->paymentProcessorID,
739a8336 407 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
408 'credit_card_number' => '411111111111111',
409 'billing_city-5' => 'Vancouver',
410 ), CRM_Core_Action::ADD,
411 'live'
412 );
413 $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id'));
414 $this->assertNotEmpty($contribution['address_id']);
415 $this->callAPISuccessGetSingle('Address', array(
416 'city' => 'Vancouver',
417 'location_type_id' => 5,
418 'id' => $contribution['address_id'],
419 ));
420
421 }
422
423 /**
424 * Test the submit function does not create a billing address if no details provided.
425 */
426 public function testSubmitCreditCardWithNoBillingAddress() {
427 $form = new CRM_Contribute_Form_Contribution();
428 $form->testSubmit(array(
429 'total_amount' => 50,
430 'financial_type_id' => 1,
431 'receive_date' => '04/21/2015',
432 'receive_date_time' => '11:27PM',
433 'contact_id' => $this->_individualId,
434 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
22e39333 435 'payment_processor_id' => $this->paymentProcessorID,
739a8336 436 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
437 'credit_card_number' => '411111111111111',
438 ), CRM_Core_Action::ADD,
439 'live'
440 );
441 $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id'));
442 $this->assertEmpty($contribution['address_id']);
443 $this->callAPISuccessGetCount('Address', array(
444 'city' => 'Vancouver',
445 'location_type_id' => 5,
446 ), 0);
447
448 }
449
a084385f
EM
450 /**
451 * Test the submit function on the contribution page.
452 */
453 public function testSubmitEmailReceipt() {
454 $form = new CRM_Contribute_Form_Contribution();
455 require_once 'CiviTest/CiviMailUtils.php';
456 $mut = new CiviMailUtils($this, TRUE);
457 $form->testSubmit(array(
458 'total_amount' => 50,
459 'financial_type_id' => 1,
460 'receive_date' => '04/21/2015',
461 'receive_date_time' => '11:27PM',
462 'contact_id' => $this->_individualId,
463 'is_email_receipt' => TRUE,
464 'from_email_address' => 'test@test.com',
5e27919e 465 'contribution_status_id' => 1,
31760f81 466 ), CRM_Core_Action::ADD);
a084385f
EM
467 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
468 $mut->checkMailLog(array(
469 '<p>Please print this receipt for your records.</p>',
470 )
471 );
472 $mut->stop();
473 }
df729ab1 474
31760f81
EM
475 /**
476 * Test that a contribution is assigned against a pledge.
477 */
478 public function testUpdatePledge() {
479 $pledge = $this->callAPISuccess('pledge', 'create', array(
480 'contact_id' => $this->_individualId,
481 'pledge_create_date' => date('Ymd'),
482 'start_date' => date('Ymd'),
483 'amount' => 100.00,
484 'pledge_status_id' => '2',
485 'pledge_financial_type_id' => '1',
486 'pledge_original_installment_amount' => 20,
487 'frequency_interval' => 5,
488 'frequency_unit' => 'year',
489 'frequency_day' => 15,
490 'installments' => 2,
491 'sequential' => 1,
492 ));
493 $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array(
494 'pledge_id' => $pledge['id'],
495 'options' => array('limit' => 1),
496 'return' => 'id',
497 ));
498 $form = new CRM_Contribute_Form_Contribution();
499 $form->testSubmit(array(
500 'total_amount' => 50,
501 'financial_type_id' => 1,
502 'receive_date' => '04/21/2015',
503 'receive_date_time' => '11:27PM',
504 'contact_id' => $this->_individualId,
505 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
506 'pledge_payment_id' => $pledgePaymentID,
5e27919e 507 'contribution_status_id' => 1,
31760f81
EM
508 ), CRM_Core_Action::ADD);
509 $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID));
510 $this->assertNotEmpty($pledgePayment['contribution_id']);
511 $this->assertEquals($pledgePayment['actual_amount'], 50);
512 $this->assertEquals(1, $pledgePayment['status_id']);
513 }
ef353929 514
3e6a1f4a
EM
515 /**
516 * Test functions involving premiums.
517 */
518 public function testPremiumUpdate() {
519 $form = new CRM_Contribute_Form_Contribution();
43bf07d6 520 $mut = new CiviMailUtils($this, TRUE);
3e6a1f4a
EM
521 $form->testSubmit(array(
522 'total_amount' => 50,
523 'financial_type_id' => 1,
524 'receive_date' => '04/21/2015',
525 'receive_date_time' => '11:27PM',
526 'contact_id' => $this->_individualId,
527 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
528 'contribution_status_id' => 1,
529 'product_name' => array($this->products[0]['id'], 1),
530 'fulfilled_date' => '',
43bf07d6
EM
531 'is_email_receipt' => TRUE,
532 'from_email_address' => 'test@test.com',
3e6a1f4a
EM
533 ), CRM_Core_Action::ADD);
534 $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array());
535 $this->assertEquals('clumsy smurf', $contributionProduct['product_option']);
43bf07d6
EM
536 $mut->checkMailLog(array(
537 'Premium Information',
538 'Smurf',
539 'clumsy smurf',
540 ));
541 $mut->stop();
3e6a1f4a
EM
542 }
543
39f47c0d
EM
544 /**
545 * Test functions involving premiums.
546 */
547 public function testPremiumUpdateCreditCard() {
548 $form = new CRM_Contribute_Form_Contribution();
549 $mut = new CiviMailUtils($this, TRUE);
550 $form->testSubmit(array(
551 'total_amount' => 50,
552 'financial_type_id' => 1,
553 'receive_date' => '04/21/2015',
554 'receive_date_time' => '11:27PM',
555 'contact_id' => $this->_individualId,
556 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
557 'contribution_status_id' => 1,
558 'product_name' => array($this->products[0]['id'], 1),
559 'fulfilled_date' => '',
560 'is_email_receipt' => TRUE,
561 'from_email_address' => 'test@test.com',
22e39333 562 'payment_processor_id' => $this->paymentProcessorID,
7758bd2b 563 'credit_card_exp_date' => array('M' => 5, 'Y' => 2026),
39f47c0d
EM
564 'credit_card_number' => '411111111111111',
565 ), CRM_Core_Action::ADD,
566 'live');
567 $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array());
568 $this->assertEquals('clumsy smurf', $contributionProduct['product_option']);
569 $mut->checkMailLog(array(
570 'Premium Information',
571 'Smurf',
572 'clumsy smurf',
573 ));
574 $mut->stop();
575 }
576
945f423d
EM
577 /**
578 * Test the submit function on the contribution page.
579 */
580 public function testSubmitWithNote() {
581 $form = new CRM_Contribute_Form_Contribution();
582 $form->testSubmit(array(
583 'total_amount' => 50,
584 'financial_type_id' => 1,
585 'receive_date' => '04/21/2015',
586 'receive_date_time' => '11:27PM',
587 'contact_id' => $this->_individualId,
588 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
589 'contribution_status_id' => 1,
590 'note' => 'Super cool and interesting stuff',
591 ),
592 CRM_Core_Action::ADD);
593 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
594 $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution'));
595 $this->assertEquals($note['note'], 'Super cool and interesting stuff');
596 }
597
598 /**
599 * Test the submit function on the contribution page.
600 */
601 public function testSubmitWithNoteCreditCard() {
602 $form = new CRM_Contribute_Form_Contribution();
603
604 $form->testSubmit(array(
605 'total_amount' => 50,
606 'financial_type_id' => 1,
607 'receive_date' => '04/21/2015',
608 'receive_date_time' => '11:27PM',
609 'contact_id' => $this->_individualId,
610 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
611 'contribution_status_id' => 1,
612 'note' => 'Super cool and interesting stuff',
1ea0b4ac 613 ) + $this->getCreditCardParams(),
945f423d
EM
614 CRM_Core_Action::ADD);
615 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
616 $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution'));
617 $this->assertEquals($note['note'], 'Super cool and interesting stuff');
618 }
619
55e55e84 620 /**
621 * Test the submit function on the contribution page.
622 */
623 public function testSubmitUpdate() {
624 $form = new CRM_Contribute_Form_Contribution();
625
626 $form->testSubmit(array(
627 'total_amount' => 50,
628 'financial_type_id' => 1,
629 'receive_date' => '04/21/2015',
630 'receive_date_time' => '11:27PM',
631 'contact_id' => $this->_individualId,
632 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
633 'contribution_status_id' => 1,
634 'price_set_id' => 0,
635 ),
636 CRM_Core_Action::ADD);
637 $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
638 $form->testSubmit(array(
639 'total_amount' => 45,
640 'net_amount' => 45,
641 'financial_type_id' => 1,
642 'receive_date' => '04/21/2015',
643 'receive_date_time' => '11:27PM',
644 'contact_id' => $this->_individualId,
645 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
646 'contribution_status_id' => 1,
647 'price_set_id' => 0,
648 'id' => $contribution['id'],
649 ),
650 CRM_Core_Action::UPDATE);
da77cbbd
EM
651 $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
652 $this->assertEquals(45, (int) $contribution['total_amount']);
653
55e55e84 654 $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE));
655 $this->assertEquals(2, $financialTransactions['count']);
656 $this->assertEquals(50, $financialTransactions['values'][0]['total_amount']);
a4ed7706
EM
657 $this->assertEquals(-5, $financialTransactions['values'][1]['total_amount']);
658 $this->assertEquals(-5, $financialTransactions['values'][1]['net_amount']);
55e55e84 659 $lineItem = $this->callAPISuccessGetSingle('LineItem', array());
660 $this->assertEquals(45, $lineItem['line_total']);
661 }
662
945f423d
EM
663 /**
664 * Get parameters for credit card submit calls.
665 *
666 * @return array
667 * Credit card specific parameters.
668 */
1ea0b4ac 669 protected function getCreditCardParams() {
945f423d 670 return array(
22e39333 671 'payment_processor_id' => $this->paymentProcessorID,
945f423d
EM
672 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012),
673 'credit_card_number' => '411111111111111',
674 );
675 }
945f423d 676
2dcbf765 677}