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