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