tests/ - Remove get_info()
[civicrm-core.git] / tests / phpunit / api / v3 / ParticipantTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Test class for Batch API - civicrm_participant_*
32 *
33 * @package CiviCRM_APIv3
34 */
35 require_once 'CRM/Utils/DeprecatedUtils.php';
36 require_once 'CiviTest/CiviUnitTestCase.php';
37
38 /**
39 * Class api_v3_ParticipantTest
40 */
41 class api_v3_ParticipantTest extends CiviUnitTestCase {
42
43 protected $_apiversion;
44 protected $_entity;
45 protected $_contactID;
46 protected $_contactID2;
47 protected $_createdParticipants;
48 protected $_participantID;
49 protected $_eventID;
50 protected $_individualId;
51 protected $_params;
52
53 function setUp() {
54 $this->_apiversion = 3;
55 parent::setUp();
56 $this->_entity = 'participant';
57 $event = $this->eventCreate(NULL);
58 $this->_eventID = $event['id'];
59
60 $this->_contactID = $this->individualCreate();
61
62 $this->_createdParticipants = array();
63 $this->_individualId = $this->individualCreate();
64
65 $this->_participantID = $this->participantCreate(array('contact_id' => $this->_contactID, 'event_id' => $this->_eventID));
66 $this->_contactID2 = $this->individualCreate();
67 $this->_participantID2 = $this->participantCreate(array('contact_id' => $this->_contactID2, 'event_id' => $this->_eventID));
68 $this->_participantID3 = $this->participantCreate(array('contact_id' => $this->_contactID2, 'event_id' => $this->_eventID));
69 $this->_params = array(
70 'contact_id' => $this->_contactID,
71 'event_id' => $this->_eventID,
72 'status_id' => 1,
73 'role_id' => 1,
74 // to ensure it matches later on
75 'register_date' => '2007-07-21 00:00:00',
76 'source' => 'Online Event Registration: API Testing',
77 );
78 }
79
80 function tearDown() {
81 $this->eventDelete($this->_eventID);
82 $tablesToTruncate = array(
83 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_contact', 'civicrm_participant'
84 );
85 // true tells quickCleanup to drop any tables that might have been created in the test
86 $this->quickCleanup($tablesToTruncate, TRUE);
87 }
88
89 /**
90 * Check with complete array + custom field
91 * Note that the test is written on purpose without any
92 * variables specific to participant so it can be replicated into other entities
93 * and / or moved to the automated test suite
94 */
95 function testCreateWithCustom() {
96 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
97
98 $params = $this->_params;
99 $params['custom_' . $ids['custom_field_id']] = "custom string";
100
101 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
102
103 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
104
105 $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id']));
106 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
107
108 $this->customFieldDelete($ids['custom_field_id']);
109 $this->customGroupDelete($ids['custom_group_id']);
110 }
111
112
113 ///////////////// civicrm_participant_get methods
114
115 /**
116 * Check with wrong params type
117 */
118 function testGetWrongParamsType() {
119 $params = 'a string';
120 $result = $this->callAPIFailure('participant', 'get', $params);
121 }
122
123 /**
124 * Test civicrm_participant_get with empty params
125 */
126 function testGetEmptyParams() {
127 $this->callAPISuccess('participant', 'get', array());
128 }
129
130 /**
131 * Check with participant_id
132 */
133 function testGetParticipantIdOnly() {
134 $params = array(
135 'participant_id' => $this->_participantID,
136 'return' => array(
137 'participant_id',
138 'event_id',
139 'participant_register_date',
140 'participant_source',
141 )
142 );
143 $result = $this->callAPISuccess('participant', 'get', $params);
144 $this->assertAPISuccess($result, " in line " . __LINE__);
145 $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID, "in line " . __LINE__);
146 $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00', "in line " . __LINE__);
147 $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon', "in line " . __LINE__);
148 $params = array(
149 'id' => $this->_participantID,
150 'return' => 'id,participant_register_date,event_id',
151
152 );
153 $result = $this->callAPISuccess('participant', 'get', $params);
154 $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
155 $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
156
157 }
158
159 /**
160 * Check with params id
161 */
162 function testGetParamsAsIdOnly() {
163 $params = array(
164 'id' => $this->_participantID,
165 );
166 $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__);
167 $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
168 $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
169 $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon');
170 $this->assertEquals($result['id'], $result['values'][$this->_participantID]['id']);
171 }
172
173 /**
174 * Check with params id
175 */
176 function testGetNestedEventGet() {
177 //create a second event & add participant to it.
178 $event = $this->eventCreate(NULL);
179 $this->callAPISuccess('participant', 'create', array('event_id' => $event['id'], 'contact_id' => $this->_contactID));
180
181
182 $description = "use nested get to get an event";
183 $subfile = "NestedEventGet";
184 $params = array(
185 'id' => $this->_participantID,
186 'api.event.get' => 1,
187 );
188 $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
189 $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
190 $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
191 $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon');
192 $this->assertEquals($this->_eventID, $result['values'][$this->_participantID]['api.event.get']['id']);
193 }
194
195 /**
196 * Check Participant Get respects return properties
197 */
198 function testGetWithReturnProperties() {
199 $params = array(
200 'contact_id' => $this->_contactID, 'return.status_id' => 1,
201 'return.participant_status_id' => 1,
202 'options' => array('limit' => 1)
203 );
204 $result = $this->callAPISuccess('participant', 'get', $params);
205 $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]);
206 }
207
208 /**
209 * Check with contact_id
210 */
211 function testGetContactIdOnly() {
212 $params = array(
213 'contact_id' => $this->_contactID, );
214 $participant = $this->callAPISuccess('participant', 'get', $params);
215
216 $this->assertEquals($this->_participantID, $participant['id'],
217 "In line " . __LINE__
218 );
219 $this->assertEquals($this->_eventID, $participant['values'][$participant['id']]['event_id'],
220 "In line " . __LINE__
221 );
222 $this->assertEquals('2007-02-19 00:00:00', $participant['values'][$participant['id']]['participant_register_date'],
223 "In line " . __LINE__
224 );
225 $this->assertEquals('Wimbeldon', $participant['values'][$participant['id']]['participant_source'],
226 "In line " . __LINE__
227 );
228 $this->assertEquals($participant['id'], $participant['values'][$participant['id']]['id'],
229 "In line " . __LINE__
230 );
231 }
232
233 /**
234 * Check with event_id
235 * fetch first record
236 */
237 function testGetMultiMatchReturnFirst() {
238 $params = array(
239 'event_id' => $this->_eventID,
240 'rowCount' => 1, );
241
242 $participant = $this->callAPISuccess('participant', 'get', $params);
243 $this->assertNotNull($participant['id']);
244 }
245
246 /**
247 * Check with event_id
248 * in v3 this should return all participants
249 */
250 function testGetMultiMatchNoReturnFirst() {
251 $params = array(
252 'event_id' => $this->_eventID,
253 );
254 $participant = $this->callAPISuccess('participant', 'get', $params);
255 $this->assertNotNull($participant['count'], 3);
256 }
257
258 ///////////////// civicrm_participant_get methods
259
260 /**
261 * Test civicrm_participant_get with empty params
262 * In this case all the participant records are returned.
263 */
264 function testSearchEmptyParams() {
265 $result = $this->callAPISuccess('participant', 'get', array());
266 // expecting 3 participant records
267 $this->assertEquals($result['count'], 3);
268 }
269
270 /**
271 * Check with participant_id
272 */
273 function testSearchParticipantIdOnly() {
274 $params = array(
275 'participant_id' => $this->_participantID,
276 );
277 $participant = $this->callAPISuccess('participant', 'get', $params);
278 $this->assertEquals($participant['values'][$this->_participantID]['event_id'], $this->_eventID);
279 $this->assertEquals($participant['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
280 $this->assertEquals($participant['values'][$this->_participantID]['participant_source'], 'Wimbeldon');
281 }
282
283 /**
284 * Check with contact_id
285 */
286 function testSearchContactIdOnly() {
287 // Should get 2 participant records for this contact.
288 $params = array(
289 'contact_id' => $this->_contactID2,
290 );
291 $participant = $this->callAPISuccess('participant', 'get', $params);
292
293 $this->assertEquals($participant['count'], 2);
294 }
295
296 /**
297 * Check with event_id
298 */
299 function testSearchByEvent() {
300 // Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned.
301 $params = array(
302 'event_id' => $this->_eventID,
303 'return.last_name' => 1,
304 'return.event_title' => 1,
305 );
306 $participant = $this->callAPISuccess('participant', 'get', $params);
307 if ($participant['count'] < 3) {
308 $this->fail("Event search returned less than expected miniumum of 3 records.");
309 }
310
311 $this->assertEquals($participant['values'][$this->_participantID]['last_name'], 'Anderson');
312 $this->assertEquals($participant['values'][$this->_participantID]['event_title'], 'Annual CiviCRM meet');
313 }
314
315 /**
316 * Check with event_id
317 * fetch with limit
318 */
319 function testSearchByEventWithLimit() {
320 // Should 2 participant records since we're passing rowCount = 2.
321 $params = array(
322 'event_id' => $this->_eventID,
323 'rowCount' => 2,
324 );
325 $participant = $this->callAPISuccess('participant', 'get', $params);
326
327 $this->assertEquals($participant['count'], 2, 'in line ' . __LINE__);
328 }
329
330 ///////////////// civicrm_participant_create methods
331
332 /**
333 * Test civicrm_participant_create with empty params
334 */
335 function testCreateEmptyParams() {
336 $params = array();
337 $result = $this->callAPIFailure('participant', 'create', $params);
338 }
339
340 /**
341 * Check with event_id
342 */
343 function testCreateMissingContactID() {
344 $params = array(
345 'event_id' => $this->_eventID,
346 );
347 $participant = $this->callAPIFailure('participant', 'create', $params);
348 }
349
350 /**
351 * Check with contact_id
352 * without event_id
353 */
354 function testCreateMissingEventID() {
355 $params = array(
356 'contact_id' => $this->_contactID,
357 );
358 $participant = $this->callAPIFailure('participant', 'create', $params);
359 }
360
361 /**
362 * Check with contact_id & event_id
363 */
364 function testCreateEventIdOnly() {
365 $params = array(
366 'contact_id' => $this->_contactID,
367 'event_id' => $this->_eventID,
368 );
369 $participant = $this->callAPISuccess('participant', 'create', $params);
370 $this->getAndCheck($params, $participant['id'], 'participant');
371 }
372
373 /**
374 * Check with complete array
375 */
376 function testCreateAllParams() {
377 $params = $this->_params;
378
379 $participant = $this->callAPISuccess('participant', 'create', $params);
380 $this->_participantID = $participant['id'];
381 // assertDBState compares expected values in $match to actual values in the DB
382 $this->assertDBState('CRM_Event_DAO_Participant', $participant['id'], $params);
383 }
384
385 /**
386 * Test to check if receive date is being changed per CRM-9763
387 */
388 function testCreateUpdateReceiveDate() {
389 $participant = $this->callAPISuccess('participant', 'create', $this->_params);
390 $update = array(
391 'id' => $participant['id'],
392 'status_id' => 2,
393 );
394 $this->callAPISuccess('participant', 'create', $update);
395 $this->getAndCheck(array_merge($this->_params, $update), $participant['id'], 'participant');
396 }
397
398 /**
399 * Test to check if participant fee level is being changed per CRM-9781
400 */
401 function testCreateUpdateParticipantFeeLevel() {
402 $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR);
403 $participant = $this->callAPISuccess('participant', 'create', $myParams);
404 $update = array(
405 'id' => $participant['id'],
406 'status_id' => 2,
407 );
408 $update = $this->callAPISuccess('participant', 'create', $update);
409
410 $this->assertEquals($participant['values'][$participant['id']]['fee_level'],
411 $update['values'][$participant['id']]['fee_level']
412 );
413
414 $this->callAPISuccess('participant', 'delete', array('id' => $participant['id']));
415 }
416
417 /**
418 * Test the line items for participant fee with multiple price field values.
419 */
420 function testCreateParticipantLineItems() {
421 // Create a price set for this event.
422
423 $priceset = $this->callAPISuccess('PriceSet', 'create', array(
424 'name' => 'my_price_set',
425 'title' => 'My Price Set',
426 'is_active' => 1,
427 'extends' => 1,
428 'financial_type_id' => 4,
429 // 'entity' => array('civicrm_event' => array($this->_eventID)),
430 ));
431
432 // Add the price set to the event with another API call.
433 // I tried to do this at once, but it did not work.
434
435 $priceset = $this->callAPISuccess('PriceSet', 'create', array(
436 'entity_table' => 'civicrm_event',
437 'entity_id' => $this->_eventID,
438 'id' => $priceset['id'],
439 ));
440
441 $pricefield = $this->callAPISuccess('PriceField', 'create', array(
442 'price_set_id' => $priceset['id'],
443 'name' => 'mypricefield',
444 'label' => 'My Price Field',
445 'html_type' => 'Text',
446 'is_enter_qty' => 1,
447 'is_display_amounts' => 1,
448 'is_active' => 1,
449 ));
450
451 $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', array(
452 'price_field_id' => $pricefield['id'],
453 'name' => 'pricefieldvalue1',
454 'label' => 'pricefieldvalue1',
455 'amount' => 20,
456 'is_active' => 1,
457 'financial_type_id' => 4,
458 ));
459
460 $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', array(
461 'price_field_id' => $pricefield['id'],
462 'name' => 'pricefieldvalue2',
463 'label' => 'pricefieldvalue2',
464 'amount' => 5,
465 'is_active' => 1,
466 'financial_type_id' => 4,
467 ));
468
469 // pay 2 times price field value 1, and 2 times price field value 2.
470 $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR);
471 $participant = $this->callAPISuccess('participant', 'create', $myParams);
472
473 // expect 2 line items.
474 $lineItems = $this->callAPISuccess('LineItem', 'get', array(
475 'entity_id' => $participant['id'],
476 'entity_table' => 'civicrm_participant',
477 ));
478
479 $this->assertEquals(2, $lineItems['count']);
480
481 // Check quantity, label and unit price of lines.
482 // TODO: These assertions depend on the order of the line items, which is
483 // technically incorrect.
484
485 $lineItem = array_pop($lineItems['values']);
486 $this->assertEquals(2, $lineItem['qty']);
487 $this->assertEquals(5, $lineItem['unit_price']);
488 $this->assertEquals('pricefieldvalue2', $lineItem['label']);
489
490 $lineItem = array_pop($lineItems['values']);
491 $this->assertEquals(2, $lineItem['qty']);
492 $this->assertEquals(20, $lineItem['unit_price']);
493 $this->assertEquals('pricefieldvalue1', $lineItem['label']);
494
495 // Cleanup
496 $this->callAPISuccess('participant', 'delete', array('id' => $participant['id']));
497
498 // TODO: I think the price set should be removed, but I don't know how
499 // to decouple it properly from the event. For the moment, I'll just comment
500 // out the lines below.
501
502 /*
503 $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv1['id']));
504 $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv2['id']));
505 $this->callAPISuccess('PriceField', 'delete', array('id' => $pricefield['id']));
506 $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceset['id']));
507 */
508 }
509
510 /**
511 * Check with complete array
512 */
513 function testUpdate() {
514 $participantId = $this->participantCreate(array(
515 'contactID' => $this->_individualId,
516 'eventID' => $this->_eventID
517 ));
518 $params = array(
519 'id' => $participantId,
520 'contact_id' => $this->_individualId,
521 'event_id' => $this->_eventID,
522 'status_id' => 3,
523 'role_id' => 3,
524 'register_date' => '2006-01-21',
525 'source' => 'US Open',
526 );
527 $participant = $this->callAPISuccess('participant', 'create', $params);
528 $this->getAndCheck($params, $participant['id'], 'participant');
529 $result = $this->participantDelete($params['id']);
530 }
531
532 /**
533 * Test to check if participant fee level is being changed per CRM-9781
534 * Try again without a custom separater to check that one isn't added
535 * (get & check won't accept an array)
536 */
537 function testUpdateCreateParticipantFeeLevelNoSeparator() {
538
539 $myParams = $this->_params + array('participant_fee_level' => "fee");
540 $participant = $this->callAPISuccess('participant', 'create', $myParams);
541 $this->assertAPISuccess($participant);
542 $update = array(
543 'id' => $participant['id'],
544 'status_id' => 2,
545 );
546 $this->callAPISuccess('participant', 'create', $update);
547 $this->assertEquals($participant['values'][$participant['id']]['fee_level'],
548 $myParams['participant_fee_level']
549 );
550 $this->getAndCheck($update, $participant['id'], 'participant');
551 }
552 ///////////////// civicrm_participant_update methods
553
554 /**
555 * Test civicrm_participant_update with wrong params type
556 */
557 function testUpdateWrongParamsType() {
558 $params = 'a string';
559 $result = $this->callAPIFailure('participant', 'create', $params);
560 $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__);
561 }
562
563 /**
564 * Check with empty array
565 */
566 function testUpdateEmptyParams() {
567 $params = array();
568 $participant = $this->callAPIFailure('participant', 'create', $params);
569 $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id');
570 }
571
572 /**
573 * Check without event_id
574 */
575 function testUpdateWithoutEventId() {
576 $participantId = $this->participantCreate(array('contactID' => $this->_individualId, 'eventID' => $this->_eventID));
577 $params = array(
578 'contact_id' => $this->_individualId,
579 'status_id' => 3,
580 'role_id' => 3,
581 'register_date' => '2006-01-21',
582 'source' => 'US Open',
583 'event_level' => 'Donation', );
584 $participant = $this->callAPIFailure('participant', 'create', $params);
585 $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id');
586 // Cleanup created participant records.
587 $result = $this->participantDelete($participantId);
588 }
589
590 /**
591 * Check with Invalid participantId
592 */
593 function testUpdateWithWrongParticipantId() {
594 $params = array(
595 'id' => 1234,
596 'status_id' => 3,
597 'role_id' => 3,
598 'register_date' => '2006-01-21',
599 'source' => 'US Open',
600 'event_level' => 'Donation', );
601 $participant = $this->callAPIFailure('Participant', 'update', $params);
602 }
603
604 /**
605 * Check with Invalid ContactId
606 */
607 function testUpdateWithWrongContactId() {
608 $participantId = $this->participantCreate(array(
609 'contactID' => $this->_individualId,
610 'eventID' => $this->_eventID,
611 ), $this->_apiversion);
612 $params = array(
613 'id' => $participantId,
614 'contact_id' => 12345,
615 'status_id' => 3,
616 'role_id' => 3,
617 'register_date' => '2006-01-21',
618 'source' => 'US Open',
619 'event_level' => 'Donation', );
620 $participant = $this->callAPIFailure('participant', 'create', $params);
621 $result = $this->participantDelete($participantId);
622 }
623
624 ///////////////// civicrm_participant_delete methods
625
626 /**
627 * Test civicrm_participant_delete with wrong params type
628 */
629 function testDeleteWrongParamsType() {
630 $params = 'a string';
631 $result = $this->callAPIFailure('participant', 'delete', $params);
632 }
633
634 /**
635 * Test civicrm_participant_delete with empty params
636 */
637 function testDeleteEmptyParams() {
638 $params = array();
639 $result = $this->callAPIFailure('participant', 'delete', $params);
640 }
641
642 /**
643 * Check with participant_id
644 */
645 function testParticipantDelete() {
646 $params = array(
647 'id' => $this->_participantID, );
648 $participant = $this->callAPISuccess('participant', 'delete', $params);
649 $this->assertAPISuccess($participant);
650 $this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID, NULL, TRUE);
651 }
652
653 /**
654 * Check without participant_id
655 * and with event_id
656 * This should return an error because required param is missing..
657 */
658 function testParticipantDeleteMissingID() {
659 $params = array(
660 'event_id' => $this->_eventID, );
661 $participant = $this->callAPIFailure('participant', 'delete', $params);
662 $this->assertNotNull($participant['error_message']);
663 }
664
665 /**
666 * Delete with a get - a 'criteria delete'
667 */
668 function testNestedDelete() {
669 $description = "Criteria delete by nesting a GET & a DELETE";
670 $subfile = "NestedDelete";
671 $participants = $this->callAPISuccess('Participant', 'Get', array());
672 $this->assertEquals($participants['count'], 3);
673 $params = array('contact_id' => $this->_contactID2, 'api.participant.delete' => 1);
674 $participants = $this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile, 'Get');
675 $check = $this->callAPISuccess('participant', 'getcount', array());
676 $this->assertEquals(1, $check,"only one participant should be left. line " . __LINE__);
677 }
678
679 /**
680 * Test creation of a participant with an associated contribution
681 */
682 function testCreateParticipantWithPayment() {
683 $description = "single function to create contact w partipation & contribution. Note that in the
684 case of 'contribution' the 'create' is implied (api.contribution.create)";
685 $subfile = "CreateParticipantPayment";
686 $params = array(
687 'contact_type' => 'Individual',
688 'display_name' => 'dlobo',
689 'api.participant' => array(
690 'event_id' => $this->_eventID,
691 'status_id' => 1,
692 'role_id' => 1,
693 'format.only_id' => 1,
694 ),
695 'api.contribution.create' => array(
696 'financial_type_id' => 1,
697 'total_amount' => 100,
698 'format.only_id' => 1,
699 ),
700 'api.participant_payment.create' => array(
701 'contribution_id' => '$value.api.contribution.create',
702 'participant_id' => '$value.api.participant',
703 ),
704 );
705
706 $result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
707 $this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']);
708 $this->callAPISuccess('contact', 'delete', array('id' => $result['id']));
709 }
710 }
711