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