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