Merge pull request #3196 from JoeMurray/master
[civicrm-core.git] / tests / phpunit / CRM / Core / Payment / BaseIPNTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30 class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
31
32 protected $_contributionTypeId;
33 protected $_contributionParams;
34 protected $_contactId;
35 protected $_contributionId;
36 protected $_participantId;
37 protected $_pledgeId;
38 protected $_eventId;
39 protected $_processorId;
40 protected $_contributionRecurParams;
41 protected $_paymentProcessor;
42 protected $IPN;
43 protected $_recurId;
44 protected $_membershipId;
45 protected $input;
46 protected $ids;
47 protected $objects;
48 public $DBResetRequired = FALSE;
49
50 function get_info() {
51 return array(
52 'name' => 'BaseIPN test',
53 'description' => 'Test BaseIPN methods (via subclass A.net).',
54 'group' => 'Payment Processor Tests',
55 );
56 }
57
58 function setUp() {
59 parent::setUp();
60 $this->input = $this->ids = $this->objects = array();
61 $this->IPN = new CRM_Core_Payment_AuthorizeNetIPN();
62
63 $this->_contactId = $this->individualCreate();
64 $this->ids['contact'] = $this->_contactId;
65 $this->paymentProcessor = new CRM_Financial_BAO_PaymentProcessor();
66
67 $paymentProcessorParams = array(
68 'user_name' => 'user_name',
69 'password' => 'password',
70 'url_recur' => 'url_recur',
71 //@todo - if we used the api then we could pass in 'AuthNet & the api will resolve
72 // (as least it will once the pseudoconstant s in the schema)
73 'payment_processor_type_id' => $this->callAPISuccess('payment_processor_type', 'getvalue', array(
74 'return' => 'id',
75 'name' => 'AuthNet'
76 )),
77 );
78
79 $paymentProcessorParams['domain_id'] = 1;
80 $paymentProcessorParams['is_active'] = 1;
81 $paymentProcessorParams['is_test'] = 1;
82 $paymentProcessorParams['billing_mode'] = 1;
83 $paymentProcessorParams['class_name'] = "Payment_AuthorizeNet";
84 $processorEntity = $this->paymentProcessor->create($paymentProcessorParams);
85
86 $this->_processorId = $processorEntity->id;
87 $this->_contributionTypeId = 1;
88
89 $this->_contributionParams = array(
90 'contact_id' => $this->_contactId,
91 'version' => 3,
92 'financial_type_id' => $this->_contributionTypeId,
93 'recieve_date' => date('Ymd'),
94 'total_amount' => 150.00,
95 'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
96 'currency' => 'USD',
97 'contribution_recur_id' => $this->_recurId,
98 'is_test' => 1,
99 'contribution_status_id' => 2,
100 );
101 $contribution = civicrm_api('contribution', 'create', $this->_contributionParams);
102 $this->assertAPISuccess($contribution, 'line ' . __LINE__ . ' set-up of contribution ');
103 $this->_contributionId = $contribution['id'];
104
105 $contribution = new CRM_Contribute_BAO_Contribution();
106 $contribution->id = $this->_contributionId;
107 $contribution->find(true);
108 $this->objects['contribution'] = $contribution;
109 }
110
111 function tearDown() {
112 $this->quickCleanUpFinancialEntities();
113 CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
114 CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
115 }
116
117 /**
118 * Test the LoadObjects function with recurring membership data
119 *
120 */
121 function testLoadMembershipObjects() {
122 $this->_setUpMembershipObjects();
123 $this->_setUpRecurringContribution();
124 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
125 $this->assertFalse(empty($this->objects['membership']), 'in line ' . __LINE__);
126 $this->assertArrayHasKey($this->_membershipTypeID, $this->objects['membership'], 'in line ' . __LINE__);
127 $this->assertTrue(is_a($this->objects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
128 $this->assertTrue(is_a( $this->objects['contributionType'],'CRM_Financial_BAO_FinancialType'));
129 $this->assertFalse(empty($this->objects['contributionRecur']), __LINE__);
130 $this->assertFalse(empty($this->objects['paymentProcessor']), __LINE__);
131 }
132 /**
133 * Test the LoadObjects function with recurring membership data
134 *
135 */
136 function testLoadMembershipObjectsLoadAll() {
137 $this->_setUpMembershipObjects();
138 $this->_setUpRecurringContribution();
139 unset($this->ids['membership']);
140 $contribution = new CRM_Contribute_BAO_Contribution();
141 $contribution->id = $this->_contributionId;
142 $contribution->find(true);
143 $contribution->loadRelatedObjects($this->input, $this->ids, FALSE, true);
144 $this->assertFalse(empty($contribution->_relatedObjects['membership']), 'in line ' . __LINE__);
145 $this->assertArrayHasKey($this->_membershipTypeID, $contribution->_relatedObjects['membership'], 'in line ' . __LINE__);
146 $this->assertTrue(is_a($contribution->_relatedObjects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
147 $this->assertTrue(is_a($contribution->_relatedObjects['contributionType'], 'CRM_Financial_BAO_FinancialType'));
148 $this->assertFalse(empty($contribution->_relatedObjects['contributionRecur']), __LINE__);
149 $this->assertFalse(empty($contribution->_relatedObjects['paymentProcessor']), __LINE__);
150 }
151 /**
152 * Test the LoadObjects function with recurring membership data
153 *
154 */
155 function testsendMailMembershipObjects() {
156 $this->_setUpMembershipObjects();
157 $values = array();
158 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
159 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
160 $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
161 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
162 $this->assertContains('<p>Please print this confirmation for your records.</p>', $msg['html']);
163 $this->assertContains('Membership Type: General', $msg['body']);
164 }
165
166 /**
167 * Test the LoadObjects function with recurring membership data
168 *
169 */
170 function testsendMailMembershipWithoutLoadObjects() {
171 $this->_setUpMembershipObjects();
172 $values = array();
173 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
174 $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
175 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
176 $this->assertContains('<p>Please print this confirmation for your records.</p>', $msg['html']);
177 $this->assertContains('Membership Type: General', $msg['body']);
178 }
179 /*
180 * Test that loadObjects works with participant values
181 */
182 function testLoadParticipantObjects() {
183 $this->_setUpParticipantObjects();
184 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
185 $this->assertFalse(empty($this->objects['participant']), 'in line ' . __LINE__);
186 $this->assertTrue(is_a($this->objects['participant'], 'CRM_Event_BAO_Participant'));
187 $this->assertTrue(is_a( $this->objects['contributionType'],'CRM_Financial_BAO_FinancialType'));
188 $this->assertFalse(empty($this->objects['event']));
189 $this->assertTrue(is_a($this->objects['event'], 'CRM_Event_BAO_Event'));
190 $this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
191 $this->assertFalse(empty($this->objects['event']->id));
192 }
193
194 /**
195 * Test the LoadObjects function with a participant
196 *
197 */
198 function testComposeMailParticipant() {
199 $this->_setUpParticipantObjects();
200 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
201 $values = array();
202 $this->assertFalse(empty($this->objects['event']));
203 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, False,True);
204 $this->assertContains('registration has been received and your status has been updated to Attended.', $msg['body']);
205 $this->assertContains('Annual CiviCRM meet', $msg['html']);
206 }
207
208 /**
209 *
210 *
211 */
212 function testComposeMailParticipantObjects() {
213 $this->_setUpParticipantObjects();
214 $values = array();
215 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
216 $this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
217 $this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
218 $this->assertContains('<p>Please print this confirmation for your records.</p>', $msg['html']);
219 $this->assertContains('Thank you for your participation', $msg['body']);
220 }
221
222 /**
223 * Test the LoadObjects function with recurring membership data
224 *
225 */
226 function testsendMailParticipantObjectsCheckLog() {
227 $this->_setUpParticipantObjects();
228 $values = array();
229 require_once 'CiviTest/CiviMailUtils.php';
230 $mut = new CiviMailUtils( $this, true );
231 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
232 $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
233 $mut->checkMailLog(array(
234 'Thank you for your participation',
235 'Annual CiviCRM meet',
236 'Mr. Anthony Anderson II')
237 );
238 $mut->stop();
239 }
240 /**
241 * Test the LoadObjects function with recurring membership data
242 *
243 */
244 function testsendMailParticipantObjectsNoMail() {
245 $this->_setUpParticipantObjects();
246 $event = new CRM_Event_BAO_Event();
247 $event->id = $this->_eventId;
248 $event->is_email_confirm = FALSE;
249 $event->save();
250 $values = array();
251 $tablesToTruncate = array(
252 'civicrm_mailing_spool',
253 );
254 $this->quickCleanup($tablesToTruncate, FALSE);
255 require_once 'CiviTest/CiviMailUtils.php';
256 $mut = new CiviMailUtils( $this, true );
257 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
258 $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
259 $mut->assertMailLogEmpty('no mail should have been send as event set to no confirm');
260 $mut->stop();
261 }
262
263 /*
264 * Test that loadObjects works with participant values
265 */
266 function testLoadPledgeObjects() {
267 $this->_setUpPledgeObjects();
268 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
269 $this->assertFalse(empty($this->objects['pledge_payment'][0]), 'in line ' . __LINE__);
270 $this->assertTrue(is_a( $this->objects['contributionType'],'CRM_Financial_BAO_FinancialType'));
271 $this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
272 $this->assertTrue(is_a($this->objects['pledge_payment'][0], 'CRM_Pledge_BAO_PledgePayment'));
273 $this->assertFalse(empty($this->objects['pledge_payment'][0]->id));
274 $this->assertEquals($this->_contributionTypeId, $this->objects['contributionType']->id);
275 $this->assertEquals($this->_processorId, $this->objects['paymentProcessor']['id']);
276 $this->assertEquals($this->_contributionId, $this->objects['contribution']->id);
277 $this->assertEquals($this->_contactId, $this->objects['contact']->id);
278 $this->assertEquals($this->_pledgeId, $this->objects['pledge_payment'][0]->pledge_id);
279 }
280
281 /*
282 * Test that loadObjects works with participant values
283 */
284 function testLoadPledgeObjectsInvalidPledgeID() {
285 $this->_setUpPledgeObjects();
286 $this->ids['pledge_payment'][0] = 0;
287 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
288 $this->assertArrayHasKey('error_message', $result);
289 $this->assertArrayNotHasKey('pledge_payment', $this->objects);
290 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
291 $this->ids['pledge_payment'][0] = NULL;
292 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
293 $this->assertArrayHasKey('error_message', $result);
294 $this->assertArrayNotHasKey('pledge_payment', $this->objects);
295 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
296 $this->ids['pledge_payment'][0] = '';
297 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
298 $this->assertArrayHasKey('error_message', $result);
299 $this->assertArrayNotHasKey('pledge_payment', $this->objects);
300 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
301
302
303 $this->ids['pledge_payment'][0] = 999;
304 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, array('return_error' => 1));
305 $this->assertArrayHasKey('error_message', $result);
306 $this->assertEquals('Could not find pledge payment record: 999', $result['error_message']);
307 }
308
309 /**
310 * Test the LoadObjects function with a pledge
311 *
312 */
313 function testsendMailPledge() {
314 $this->_setUpPledgeObjects();
315 $values = array();
316 $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL);
317 $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
318 $this->assertContains('Contribution Information', $msg['html']);
319 }
320
321 /**
322 * Test that an error is returned if required set & no contribution page
323 *
324 */
325 function testRequiredWithoutProcessorID() {
326 $this->_setUpPledgeObjects();
327 $values = array();
328 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
329 $this->assertArrayHasKey('error_message', $result);
330 $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
331 // error is only returned if $required set to True
332 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1));
333 $this->assertFalse(is_array($result));
334 //check that error is not returned if error checking not set
335 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1));
336 $this->assertFalse(is_array($result));
337 }
338
339 /**
340 *
341 * Test that an error is not if required set & no processor ID
342 */
343 function testRequiredWithContributionPage() {
344 $this->_setUpContributionObjects(TRUE);
345
346 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
347 $this->assertFalse(is_array($result), $result['error_message']);
348 }
349
350 /**
351 * Test that an error is returned if required set & contribution page exists
352 *
353 */
354 function testRequiredWithContributionPageError() {
355 $this->_setUpContributionObjects();
356 $values = array();
357 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
358 $this->assertArrayHasKey('error_message', $result);
359 $this->assertEquals('Could not find contribution page for contribution record: 1', $result['error_message']);
360 // error is only returned if $required set to True
361 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1));
362 $this->assertFalse(is_array($result));
363 //check that error is not returned if error checking not set
364 $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1));
365 $this->assertFalse(is_array($result));
366 }
367
368 /*
369 * Test calls main functions in sequence per 'main' - I had hoped to test the functions more
370 * fully but the calls to the POST happen in more than one function
371 * keeping this as good example of data to bring back to life later
372
373 function testMainFunctionActions(){
374 $ids = $objects = array( );
375 $input['component'] = 'Contribute';
376 $postedParams = array(
377 'x_response_code' => 1,
378 'x_response_reason_code' => 1,
379 'x_response_reason_text' => 'This transaction has been approved.',
380 'x_avs_code' => 'Y',
381 'x_auth_code' => 140454,
382 'x_trans_id' => 4353599599,
383 'x_method' => 'CC',
384 'x_card_type' => 'American Express',
385 'x_account_number' => 'XXXX2701',
386 'x_first_name' => 'Arthur',
387 'x_last_name' => 'Jacobs',
388 'x_company' => null,
389 'x_address' => '866 2166th St SN',
390 'x_city' => 'Edwardstown',
391 'x_state' => 'WA',
392 'x_zip' => 98026,
393 'x_country' => 'US',
394 'x_phone' => null,
395 'x_fax' => null,
396 'x_email' => null,
397 'x_invoice_num' => 'a9fb56c24576lk4c9490f6',
398 'x_description' => 'my desc',
399 'x_type' => 'auth_capture',
400 'x_cust_id' => 5191,
401 'x_ship_to_first_name' => null,
402 'x_ship_to_last_name' => null,
403 'x_ship_to_company' => null,
404 'x_ship_to_address' => null,
405 'x_ship_to_city' => null,
406 'x_ship_to_state' => null,
407 'x_ship_to_zip' => null,
408 'x_ship_to_country' => null,
409 'x_amount' => 60.00,
410 'x_tax' => 0.00,
411 'x_duty' => 0.00,
412 'x_freight' => 0.00,
413 'x_tax_exempt' => FALSE,
414 'x_po_num' => null,
415 'x_MD5_Hash' => '069ECAD13C8E15AC205CDF92B8B58CC7',
416 'x_cvv2_resp_code' => null,
417 'x_cavv_response' => null,
418 'x_test_request' => false,
419 'description' => 'my description'
420 );
421 $this->IPN->getInput( $input, $ids );
422 $this->IPN->getIDs( $ids, $input );
423
424 CRM_Core_Error::debug_var( '$ids', $ids );
425 CRM_Core_Error::debug_var( '$input', $input );
426
427 $paymentProcessorID = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_PaymentProcessorType',
428 'AuthNet', 'id', 'name' );
429
430 if ( ! $this->IPN->validateData( $input, $ids, $objects, true, $paymentProcessorID ) ) {
431 return false;
432 }
433
434 if ( $component == 'contribute' && $ids['contributionRecur'] ) {
435 // check if first contribution is completed, else complete first contribution
436 $first = true;
437 if ( $objects['contribution']->contribution_status_id == 1 ) {
438 $first = false;
439 }
440 return $this->IPN->recur( $input, $ids, $objects, $first );
441 }
442 }
443
444 /*
445 * Prepare for contribution Test - involving only contribution objects
446 */
447 function _setUpContributionObjects($contributionPage = FALSE) {
448
449
450 $contribution = new CRM_Contribute_BAO_Contribution();
451 $contribution->id = $this->_contributionId;
452 $contribution->find(TRUE);
453 $contributionPageID = NULL;
454 if (!empty($contributionPage)) {
455 $dao = new CRM_Core_DAO();
456 $contribution_page = $dao->createTestObject('CRM_Contribute_DAO_ContributionPage');
457 $contribution->contribution_page_id = $contributionPageID = $contribution_page->id;
458 //for unknown reasons trying to do a find & save on a contribution with a receive_date set
459 // doesn't work. This seems of minimal relevance to this test so ignoring
460 // note that in tests it worked sometimes & not others - dependent on which other tests run.
461 // running all CRM_Core tests caused failure as did just the single failing test. But running
462 // just this class succeeds - because it actually doesn't do a mysql update on the following save
463 // (unknown reason)
464 unset($contribution->receive_date);
465 $contribution->save();
466 }
467
468 $this->objects['contribution'] = $contribution;
469 $this->input = array(
470 'component' => 'contribute',
471 'contribution_page_id' => $contributionPageID,
472 'total_amount' => 110.00,
473 'invoiceID' => "c8acb91e080ad7777a2adc119c192885",
474 'contactID' => $this->_contactId,
475 'contributionID' => $this->objects['contribution']->id,
476 );
477 }
478
479 /*
480 * Prepare for membership test
481 */
482 function _setUpMembershipObjects() {
483 try {
484 $this->_membershipTypeID = $this->membershipTypeCreate();
485 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
486 }
487 catch(Exception$e) {
488 echo $e->getMessage();
489 }
490 CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE);
491 CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
492 $this->_membershipParams = array(
493 'contact_id' => $this->_contactId,
494 'membership_type_id' => $this->_membershipTypeID,
495 'join_date' => '2009-01-21',
496 'start_date' => '2009-01-21',
497 'end_date' => '2009-12-21',
498 'source' => 'Payment',
499 'is_override' => 1,
500 'status_id' => $this->_membershipStatusID,
501 'version' => 3,
502 );
503
504 $membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams);
505
506 $this->_membershipId = $membership['id'];
507 //we'll create membership payment here because to make setup more re-usable
508 civicrm_api('membership_payment', 'create', array(
509 'version' => 3,
510 'contribution_id' => $this->_contributionId,
511 'membership_id' => $this->_membershipId,
512 ));
513
514 $contribution = new CRM_Contribute_BAO_Contribution();
515 $contribution->id = $this->_contributionId;
516 $contribution->find();
517 $this->objects['contribution'] = $contribution;
518 $this->input = array(
519 'component' => 'contribute',
520 'total_amount' => 150.00,
521 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
522 'contactID' => $this->_contactId,
523 'contributionID' => $this->objects['contribution']->id,
524 'membershipID' => $this->_membershipId,
525 );
526
527 $this->ids['membership'] = $this->_membershipId;
528 }
529
530 function _setUpRecurringContribution() {
531 $this->_contributionRecurParams = array(
532 'contact_id' => $this->_contactId,
533 'amount' => 150.00,
534 'currency' => 'USD',
535 'frequency_unit' => 'week',
536 'frequency_interval' => 1,
537 'installments' => 2,
538 'start_date' => date('Ymd'),
539 'create_date' => date('Ymd'),
540 'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
541 'contribution_status_id' => 2,
542 'is_test' => 1,
543 'financial_type_id' => $this->_contributionTypeId,
544 'version' => 3,
545 'payment_processor_id' => $this->_processorId,
546 );
547 $this->_recurId = civicrm_api('contribution_recur', 'create', $this->_contributionRecurParams);
548 $this->assertAPISuccess($this->_recurId, 'line ' . __LINE__ . ' set-up of recurring contrib');
549 $this->_recurId = $this->_recurId['id'];
550 $this->input['contributionRecurId'] = $this->_recurId;
551 $this->ids['contributionRecur'] = $this->_recurId;
552 }
553
554 /*
555 * Set up participant requirements for test
556 */
557 function _setUpParticipantObjects() {
558 $event = $this->eventCreate(array('is_email_confirm' => 1));
559 $this->assertAPISuccess($event, 'line ' . __LINE__ . ' set-up of event');
560 $this->_eventId = $event['id'];
561 $this->_participantId = $this->participantCreate(array(
562 'event_id' => $this->_eventId,
563 'contact_id' => $this->_contactId,
564 ));
565 //we'll create membership payment here because to make setup more re-usable
566 $participantPayment = civicrm_api('participant_payment', 'create', array(
567 'version' => 3,
568 'contribution_id' => $this->_contributionId,
569 'participant_id' => $this->_participantId,
570 ));
571 $this->assertAPISuccess($participantPayment, 'line ' . __LINE__ . ' set-up of event');
572 $contribution = new CRM_Contribute_BAO_Contribution();
573 $contribution->id = $this->_contributionId;
574 $contribution->find();
575 $this->objects['contribution'] = $contribution;
576 $this->input = array(
577 'component' => 'event',
578 'total_amount' => 150.00,
579 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
580 'contactID' => $this->_contactId,
581 'contributionID' => $contribution->id,
582 'participantID' => $this->_participantId,
583 );
584
585 $this->ids['participant'] = $this->_participantId;
586 $this->ids['event'] = $this->_eventId;
587 }
588
589 /*
590 * Set up participant requirements for test
591 */
592 function _setUpPledgeObjects() {
593 $this->_pledgeId = $this->pledgeCreate($this->_contactId);
594 //we'll create membership payment here because to make setup more re-usable
595 $pledgePayment = civicrm_api('pledge_payment', 'create', array(
596 'version' => 3,
597 'pledge_id' => $this->_pledgeId,
598 'contribution_id' => $this->_contributionId,
599 'status_id' => 1,
600 'actual_amount' => 50,
601 ));
602 $this->assertAPISuccess($pledgePayment, 'line ' . __LINE__ . ' set-up of pledge payment');
603 $this->input = array(
604 'component' => 'contribute',
605 'total_amount' => 150.00,
606 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
607 'contactID' => $this->_contactId,
608 'contributionID' => $this->_contributionId,
609 'pledgeID' => $this->_pledgeId,
610 );
611
612 $this->ids['pledge_payment'][] = $pledgePayment['id'];
613 }
614 }
615
616