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