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