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