3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test class for Batch API - civicrm_participant_*
31 * @package CiviCRM_APIv3
35 * Class api_v3_ParticipantTest
38 class api_v3_ParticipantTest
extends CiviUnitTestCase
{
40 protected $_apiversion;
42 protected $_contactID;
43 protected $_contactID2;
44 protected $_createdParticipants;
45 protected $_participantID;
47 protected $_individualId;
50 public function setUp() {
51 $this->_apiversion
= 3;
53 $this->_entity
= 'participant';
54 $event = $this->eventCreate(NULL);
55 $this->_eventID
= $event['id'];
57 $this->_contactID
= $this->individualCreate();
59 $this->_createdParticipants
= [];
60 $this->_individualId
= $this->individualCreate();
62 $this->_participantID
= $this->participantCreate([
63 'contact_id' => $this->_contactID
,
64 'event_id' => $this->_eventID
,
66 $this->_contactID2
= $this->individualCreate();
67 $this->_participantID2
= $this->participantCreate([
68 'contact_id' => $this->_contactID2
,
69 'event_id' => $this->_eventID
,
70 'registered_by_id' => $this->_participantID
,
72 $this->_participantID3
= $this->participantCreate([
73 'contact_id' => $this->_contactID2
,
74 'event_id' => $this->_eventID
,
77 'contact_id' => $this->_contactID
,
78 'event_id' => $this->_eventID
,
81 // to ensure it matches later on
82 'register_date' => '2007-07-21 00:00:00',
83 'source' => 'Online Event Registration: API Testing',
87 public function tearDown() {
88 $this->eventDelete($this->_eventID
);
90 'civicrm_custom_group',
91 'civicrm_custom_field',
93 'civicrm_participant',
95 // true tells quickCleanup to drop any tables that might have been created in the test
96 $this->quickCleanup($tablesToTruncate, TRUE);
100 * Check that getCount can count past 25.
102 public function testGetCountLimit() {
105 for ($count = $this->callAPISuccessGetCount('Participant', []); $count < 27; $count++
) {
106 $contactIDs[] = $contactID = $this->individualCreate();
107 $this->participantCreate(['contact_id' => $contactID, 'event_id' => $this->_eventID
]);
109 $this->callAPISuccessGetCount('Participant', [], 27);
111 foreach ($contactIDs as $contactID) {
112 $this->callAPISuccess('Contact', 'delete', ['id' => $contactID]);
117 * Test get participants with role_id.
119 public function testGetParticipantWithRole() {
121 foreach ($roleId as $role) {
122 $this->participantCreate([
123 'contact_id' => $this->individualCreate(),
125 'event_id' => $this->_eventID
,
132 $result = $this->callAPISuccess('participant', 'get', $params);
133 //Assert all the returned participants has a role_id of 2
134 foreach ($result['values'] as $pid => $values) {
135 $this->assertEquals($values['participant_role_id'], 2);
138 $this->participantCreate([
139 'id' => $this->_participantID
,
141 'event_id' => $this->_eventID
,
144 $params['role_id'] = [
147 $result = $this->callAPISuccess('participant', 'get', $params);
148 foreach ($result['values'] as $pid => $values) {
149 $this->assertEquals($values['participant_role_id'], NULL);
155 * Check with complete array + custom field
156 * Note that the test is written on purpose without any
157 * variables specific to participant so it can be replicated into other entities
158 * and / or moved to the automated test suite
160 public function testCreateWithCustom() {
161 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
163 $params = $this->_params
;
164 $params['custom_' . $ids['custom_field_id']] = "custom string";
166 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
168 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
170 $check = $this->callAPISuccess($this->_entity
, 'get', ['id' => $result['id']]);
171 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
173 $this->customFieldDelete($ids['custom_field_id']);
174 $this->customGroupDelete($ids['custom_group_id']);
178 * Check with participant_id.
180 public function testGetParticipantIdOnly() {
182 'participant_id' => $this->_participantID
,
186 'participant_register_date',
187 'participant_source',
190 $result = $this->callAPISuccess('participant', 'get', $params);
191 $this->assertAPISuccess($result, " in line " . __LINE__
);
192 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
193 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
194 $this->assertEquals($result['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
196 'id' => $this->_participantID
,
197 'return' => 'id,participant_register_date,event_id',
200 $result = $this->callAPISuccess('participant', 'get', $params);
201 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
202 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
207 * Test permission for participant get.
209 public function testGetParticipantWithPermission() {
210 $config = CRM_Core_Config
::singleton();
211 $config->userPermissionClass
->permissions
= [];
213 'event_id' => $this->_eventID
,
214 'check_permissions' => TRUE,
218 'participant_register_date',
219 'participant_source',
222 $this->callAPIFailure('participant', 'get', $params);
224 $params['check_permissions'] = FALSE;
225 $result = $this->callAPISuccess('participant', 'get', $params);
226 $this->assertEquals($result['is_error'], 0);
230 * Check with params id.
232 public function testGetParamsAsIdOnly() {
234 'id' => $this->_participantID
,
236 $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__
, __FILE__
);
237 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
238 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
239 $this->assertEquals($result['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
240 $this->assertEquals($result['id'], $result['values'][$this->_participantID
]['id']);
244 * Check with params id.
246 public function testGetNestedEventGet() {
247 //create a second event & add participant to it.
248 $event = $this->eventCreate(NULL);
249 $this->callAPISuccess('participant', 'create', [
250 'event_id' => $event['id'],
251 'contact_id' => $this->_contactID
,
254 $description = "Demonstrates use of nested get to fetch event data with participant records.";
255 $subfile = "NestedEventGet";
257 'id' => $this->_participantID
,
258 'api.event.get' => 1,
260 $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
261 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
262 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
263 $this->assertEquals($result['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
264 $this->assertEquals($this->_eventID
, $result['values'][$this->_participantID
]['api.event.get']['id']);
268 * Check Participant Get respects return properties.
270 public function testGetWithReturnProperties() {
272 'contact_id' => $this->_contactID
,
273 'return.status_id' => 1,
274 'return.participant_status_id' => 1,
275 'options' => ['limit' => 1],
277 $result = $this->callAPISuccess('participant', 'get', $params);
278 $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]);
282 * Check with contact_id.
284 public function testGetContactIdOnly() {
286 'contact_id' => $this->_contactID
,
288 $participant = $this->callAPISuccess('participant', 'get', $params);
290 $this->assertEquals($this->_participantID
, $participant['id']);
291 $this->assertEquals($this->_eventID
, $participant['values'][$participant['id']]['event_id']);
292 $this->assertEquals('2007-02-19 00:00:00', $participant['values'][$participant['id']]['participant_register_date']);
293 $this->assertEquals('Wimbeldon', $participant['values'][$participant['id']]['participant_source']);
294 $this->assertEquals($participant['id'], $participant['values'][$participant['id']]['id']);
298 * Check with event_id.
301 public function testGetMultiMatchReturnFirst() {
303 'event_id' => $this->_eventID
,
307 $participant = $this->callAPISuccess('participant', 'get', $params);
308 $this->assertNotNull($participant['id']);
312 * Check with event_id.
313 * in v3 this should return all participants
315 public function testGetMultiMatchNoReturnFirst() {
317 'event_id' => $this->_eventID
,
319 $participant = $this->callAPISuccess('participant', 'get', $params);
320 $this->assertNotNull($participant['count'], 3);
323 ///////////////// civicrm_participant_get methods
326 * Test civicrm_participant_get with empty params.
327 * In this case all the participant records are returned.
329 public function testSearchEmptyParams() {
330 $result = $this->callAPISuccess('participant', 'get', []);
331 // expecting 3 participant records
332 $this->assertEquals($result['count'], 3);
336 * Check with participant_id.
338 public function testSearchParticipantIdOnly() {
340 'participant_id' => $this->_participantID
,
342 $participant = $this->callAPISuccess('participant', 'get', $params);
343 $this->assertEquals($participant['values'][$this->_participantID
]['event_id'], $this->_eventID
);
344 $this->assertEquals($participant['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
345 $this->assertEquals($participant['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
349 * Check with contact_id.
351 public function testSearchContactIdOnly() {
352 // Should get 2 participant records for this contact.
354 'contact_id' => $this->_contactID2
,
356 $participant = $this->callAPISuccess('participant', 'get', $params);
358 $this->assertEquals($participant['count'], 2);
362 * Check with event_id.
364 public function testSearchByEvent() {
365 // Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned.
367 'event_id' => $this->_eventID
,
368 'return.last_name' => 1,
369 'return.event_title' => 1,
371 $participant = $this->callAPISuccess('participant', 'get', $params);
372 if ($participant['count'] < 3) {
373 $this->fail("Event search returned less than expected miniumum of 3 records.");
376 $this->assertEquals($participant['values'][$this->_participantID
]['last_name'], 'Anderson');
377 $this->assertEquals($participant['values'][$this->_participantID
]['event_title'], 'Annual CiviCRM meet');
381 * Check with event_id.
384 public function testSearchByEventWithLimit() {
385 // Should 2 participant records since we're passing rowCount = 2.
387 'event_id' => $this->_eventID
,
390 $participant = $this->callAPISuccess('participant', 'get', $params);
392 $this->assertEquals($participant['count'], 2);
396 * Test search by lead booker (registered by ID)
398 public function testSearchByRegisteredById() {
400 'registered_by_id' => $this->_participantID
,
402 $participant = $this->callAPISuccess('participant', 'get', $params);
404 $this->assertEquals($participant['count'], 1);
405 $this->assertEquals($participant['id'], $this->_participantID2
);
408 ///////////////// civicrm_participant_create methods
411 * Test civicrm_participant_create with empty params.
413 public function testCreateEmptyParams() {
415 $result = $this->callAPIFailure('participant', 'create', $params);
419 * Check with event_id.
421 public function testCreateMissingContactID() {
422 $this->callAPIFailure('participant', 'create', ['event_id' => $this->_eventID
]);
426 * Check with contact_id.
429 public function testCreateMissingEventID() {
430 $this->callAPIFailure('participant', 'create', ['contact_id' => $this->_contactID
]);
434 * Check with contact_id & event_id
436 public function testCreateEventIdOnly() {
438 'contact_id' => $this->_contactID
,
439 'event_id' => $this->_eventID
,
441 $participant = $this->callAPISuccess('participant', 'create', $params);
442 $this->getAndCheck($params, $participant['id'], 'participant');
446 * Check with complete array.
448 public function testCreateAllParams() {
449 $participant = $this->callAPISuccess('participant', 'create', $this->_params
);
450 $this->_participantID
= $participant['id'];
451 $this->assertDBState('CRM_Event_DAO_Participant', $participant['id'], $this->_params
);
455 * Test that an overlong source is handled.
457 public function testLongSource() {
458 $params = array_merge($this->_params
, [
459 'source' => 'a string that is even longer than the 128 character limit that is allowed for this field because sometimes you want, you know, an essay',
461 $baoCreated = CRM_Event_BAO_Participant
::create($params);
462 $this->assertEquals('a string that is even longer than the 128 character limit that is allowed for this field because sometimes you want, you know...', $baoCreated->source
);
463 // @todo - currently the api will still reject the long string.
464 //$this->callAPISuccess('participant', 'create', $params);
468 * Test to check if receive date is being changed per CRM-9763
470 public function testCreateUpdateReceiveDate() {
471 $participant = $this->callAPISuccess('participant', 'create', $this->_params
);
473 'id' => $participant['id'],
476 $this->callAPISuccess('participant', 'create', $update);
477 $this->getAndCheck(array_merge($this->_params
, $update), $participant['id'], 'participant');
481 * Test to check if participant fee level is being changed per CRM-9781
483 public function testCreateUpdateParticipantFeeLevel() {
484 $myParams = $this->_params +
['participant_fee_level' => CRM_Core_DAO
::VALUE_SEPARATOR
. "fee" . CRM_Core_DAO
::VALUE_SEPARATOR
];
485 $participant = $this->callAPISuccess('participant', 'create', $myParams);
487 'id' => $participant['id'],
490 $update = $this->callAPISuccess('participant', 'create', $update);
492 $this->assertEquals($participant['values'][$participant['id']]['fee_level'],
493 $update['values'][$participant['id']]['fee_level']
496 $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);
500 * Test the line items for participant fee with multiple price field values.
502 public function testCreateParticipantLineItems() {
503 // Create a price set for this event.
505 $priceset = $this->callAPISuccess('PriceSet', 'create', [
506 'name' => 'my_price_set',
507 'title' => 'My Price Set',
510 'financial_type_id' => 4,
511 // 'entity' => array('civicrm_event' => array($this->_eventID)),
514 // Add the price set to the event with another API call.
515 // I tried to do this at once, but it did not work.
517 $priceset = $this->callAPISuccess('PriceSet', 'create', [
518 'entity_table' => 'civicrm_event',
519 'entity_id' => $this->_eventID
,
520 'id' => $priceset['id'],
523 $pricefield = $this->callAPISuccess('PriceField', 'create', [
524 'price_set_id' => $priceset['id'],
525 'name' => 'mypricefield',
526 'label' => 'My Price Field',
527 'html_type' => 'Text',
529 'is_display_amounts' => 1,
533 $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', [
534 'price_field_id' => $pricefield['id'],
535 'name' => 'pricefieldvalue1',
536 'label' => 'pricefieldvalue1',
539 'financial_type_id' => 4,
542 $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', [
543 'price_field_id' => $pricefield['id'],
544 'name' => 'pricefieldvalue2',
545 'label' => 'pricefieldvalue2',
548 'financial_type_id' => 4,
551 // pay 2 times price field value 1, and 2 times price field value 2.
552 $myParams = $this->_params +
['participant_fee_level' => CRM_Core_DAO
::VALUE_SEPARATOR
. "pricefieldvalue1 - 2" . CRM_Core_DAO
::VALUE_SEPARATOR
. "pricefieldvalue2 - 2" . CRM_Core_DAO
::VALUE_SEPARATOR
];
553 $participant = $this->callAPISuccess('participant', 'create', $myParams);
555 // expect 2 line items.
556 $lineItems = $this->callAPISuccess('LineItem', 'get', [
557 'entity_id' => $participant['id'],
558 'entity_table' => 'civicrm_participant',
561 $this->assertEquals(2, $lineItems['count']);
563 // Check quantity, label and unit price of lines.
564 // TODO: These assertions depend on the order of the line items, which is
565 // technically incorrect.
567 $lineItem = array_pop($lineItems['values']);
568 $this->assertEquals(2, $lineItem['qty']);
569 $this->assertEquals(5, $lineItem['unit_price']);
570 $this->assertEquals('pricefieldvalue2', $lineItem['label']);
572 $lineItem = array_pop($lineItems['values']);
573 $this->assertEquals(2, $lineItem['qty']);
574 $this->assertEquals(20, $lineItem['unit_price']);
575 $this->assertEquals('pricefieldvalue1', $lineItem['label']);
576 $this->callAPISuccess('PriceFieldValue', 'create', ['id' => $pfv2['id'], 'label' => 'Price FIeld Value 2 Label']);
577 $participantGet = $this->callAPISuccess('Participant', 'get', ['id' => $participant['id']]);
578 $this->assertEquals(["pricefieldvalue1 - 2", "pricefieldvalue2 - 2"], $participantGet['values'][$participant['id']]['participant_fee_level']);
579 $conatactID4 = $this->individualCreate();
580 $myParams['contact_id'] = $conatactID4;
581 $myParams['participant_fee_level'] = CRM_Core_DAO
::VALUE_SEPARATOR
. "pricefieldvalue1 - 2" . CRM_Core_DAO
::VALUE_SEPARATOR
. "Price FIeld Value 2 Label - 2" . CRM_Core_DAO
::VALUE_SEPARATOR
;
582 $AdditionalParticipant = $this->callAPISuccess('Participant', 'create', $myParams);
583 $this->assertEquals(["pricefieldvalue1 - 2", "Price FIeld Value 2 Label - 2"], $AdditionalParticipant['values'][$AdditionalParticipant['id']]['fee_level']);
584 $lineItems = $this->callAPISuccess('LineItem', 'get', [
585 'entity_id' => $AdditionalParticipant['id'],
586 'entity_table' => 'civicrm_participant',
588 $this->assertEquals(2, $lineItems['count']);
590 // Check quantity, label and unit price of lines.
591 // TODO: These assertions depend on the order of the line items, which is
592 // technically incorrect.
594 $lineItem = array_pop($lineItems['values']);
595 $this->assertEquals(2, $lineItem['qty']);
596 $this->assertEquals(5, $lineItem['unit_price']);
597 $this->assertEquals('Price FIeld Value 2 Label', $lineItem['label']);
599 $lineItem = array_pop($lineItems['values']);
600 $this->assertEquals(2, $lineItem['qty']);
601 $this->assertEquals(20, $lineItem['unit_price']);
602 $this->assertEquals('pricefieldvalue1', $lineItem['label']);
605 $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);
607 // TODO: I think the price set should be removed, but I don't know how
608 // to decouple it properly from the event. For the moment, I'll just comment
609 // out the lines below.
612 $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv1['id']));
613 $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv2['id']));
614 $this->callAPISuccess('PriceField', 'delete', array('id' => $pricefield['id']));
615 $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceset['id']));
620 * Check with complete array.
622 public function testUpdate() {
623 $participantId = $this->participantCreate([
624 'contactID' => $this->_individualId
,
625 'eventID' => $this->_eventID
,
628 'id' => $participantId,
629 'contact_id' => $this->_individualId
,
630 'event_id' => $this->_eventID
,
633 'register_date' => '2006-01-21',
634 'source' => 'US Open',
636 $participant = $this->callAPISuccess('participant', 'create', $params);
637 $this->getAndCheck($params, $participant['id'], 'participant');
638 $result = $this->participantDelete($params['id']);
642 * Test to check if participant fee level is being changed per CRM-9781
643 * Try again without a custom separater to check that one isn't added
644 * (get & check won't accept an array)
646 public function testUpdateCreateParticipantFeeLevelNoSeparator() {
648 $myParams = $this->_params +
['participant_fee_level' => "fee"];
649 $participant = $this->callAPISuccess('participant', 'create', $myParams);
650 $this->assertAPISuccess($participant);
652 'id' => $participant['id'],
655 $this->callAPISuccess('participant', 'create', $update);
656 $this->assertEquals($participant['values'][$participant['id']]['fee_level'],
657 $myParams['participant_fee_level']
659 $this->getAndCheck($update, $participant['id'], 'participant');
662 ///////////////// civicrm_participant_update methods
665 * Test civicrm_participant_update with wrong params type.
667 public function testUpdateWrongParamsType() {
668 $params = 'a string';
669 $result = $this->callAPIFailure('participant', 'create', $params);
670 $this->assertEquals('Input variable `params` is not an array', $result['error_message']);
674 * Check with empty array.
676 public function testUpdateEmptyParams() {
678 $participant = $this->callAPIFailure('participant', 'create', $params);
679 $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id');
683 * Check without event_id.
685 public function testUpdateWithoutEventId() {
686 $participantId = $this->participantCreate(['contactID' => $this->_individualId
, 'eventID' => $this->_eventID
]);
688 'contact_id' => $this->_individualId
,
691 'register_date' => '2006-01-21',
692 'source' => 'US Open',
693 'event_level' => 'Donation',
695 $participant = $this->callAPIFailure('participant', 'create', $params);
696 $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id');
697 // Cleanup created participant records.
698 $result = $this->participantDelete($participantId);
702 * Check with Invalid participantId.
704 public function testUpdateWithWrongParticipantId() {
709 'register_date' => '2006-01-21',
710 'source' => 'US Open',
711 'event_level' => 'Donation',
713 $participant = $this->callAPIFailure('Participant', 'update', $params);
717 * Check with Invalid ContactId.
719 public function testUpdateWithWrongContactId() {
720 $participantId = $this->participantCreate([
721 'contactID' => $this->_individualId
,
722 'eventID' => $this->_eventID
,
723 ], $this->_apiversion
);
725 'id' => $participantId,
726 'contact_id' => 12345,
729 'register_date' => '2006-01-21',
730 'source' => 'US Open',
731 'event_level' => 'Donation',
733 $participant = $this->callAPIFailure('participant', 'create', $params);
734 $result = $this->participantDelete($participantId);
737 ///////////////// civicrm_participant_delete methods
740 * Test civicrm_participant_delete with wrong params type.
742 public function testDeleteWrongParamsType() {
743 $params = 'a string';
744 $result = $this->callAPIFailure('participant', 'delete', $params);
748 * Test civicrm_participant_delete with empty params.
750 public function testDeleteEmptyParams() {
752 $result = $this->callAPIFailure('participant', 'delete', $params);
756 * Check with participant_id.
758 public function testParticipantDelete() {
760 'id' => $this->_participantID
,
762 $participant = $this->callAPISuccess('participant', 'delete', $params);
763 $this->assertAPISuccess($participant);
764 $this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID
, NULL, TRUE);
768 * Check without participant_id.
770 * This should return an error because required param is missing..
772 public function testParticipantDeleteMissingID() {
774 'event_id' => $this->_eventID
,
776 $participant = $this->callAPIFailure('participant', 'delete', $params);
777 $this->assertNotNull($participant['error_message']);
781 * Delete with a get - a 'criteria delete'
783 public function testNestedDelete() {
784 $description = "Criteria delete by nesting a GET & a DELETE.";
785 $subfile = "NestedDelete";
786 $participants = $this->callAPISuccess('Participant', 'Get', []);
787 $this->assertEquals($participants['count'], 3);
788 $params = ['contact_id' => $this->_contactID2
, 'api.participant.delete' => 1];
789 $this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
790 $check = $this->callAPISuccess('participant', 'getcount', []);
791 $this->assertEquals(1, $check, "only one participant should be left");
795 * Test creation of a participant with an associated contribution.
797 public function testCreateParticipantWithPayment() {
798 $description = "Single function to create contact with partipation & contribution.
799 Note that in the case of 'contribution' the 'create' is implied (api.contribution.create)";
800 $subfile = "CreateParticipantPayment";
802 'contact_type' => 'Individual',
803 'display_name' => 'dlobo',
804 'api.participant' => [
805 'event_id' => $this->_eventID
,
808 'format.only_id' => 1,
810 'api.contribution.create' => [
811 'financial_type_id' => 1,
812 'total_amount' => 100,
813 'format.only_id' => 1,
815 'api.participant_payment.create' => [
816 'contribution_id' => '$value.api.contribution.create',
817 'participant_id' => '$value.api.participant',
821 $result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
822 $this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']);
823 $this->callAPISuccess('contact', 'delete', ['id' => $result['id']]);
827 * Test participant invoke post hook after status update.
829 public function testPostHookForAdditionalParticipant() {
830 $participantID = $this->participantCreate([
831 'contact_id' => $this->_contactID
,
833 'event_id' => $this->_eventID
,
835 $participantID2 = $this->participantCreate([
836 'contact_id' => $this->_contactID2
,
837 'event_id' => $this->_eventID
,
839 'registered_by_id' => $participantID,
842 $this->hookClass
->setHook('civicrm_post', [$this, 'onPost']);
844 'id' => $participantID,
847 $this->callAPISuccess('Participant', 'create', $params);
849 $result = $this->callAPISuccess('Participant', 'get', ['source' => 'Post Hook Update']);
850 $this->assertEquals(2, $result['count']);
852 $expected = [$participantID, $participantID2];
853 $actual = array_keys($result['values']);
854 $this->checkArrayEquals($expected, $actual);