3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test class for Batch API - civicrm_participant_*
15 * @package CiviCRM_APIv3
19 * Class api_v3_ParticipantTest
22 class api_v3_ParticipantTest
extends CiviUnitTestCase
{
24 protected $_apiversion;
26 protected $_contactID;
27 protected $_contactID2;
28 protected $_createdParticipants;
29 protected $_participantID;
31 protected $_individualId;
34 public function setUp() {
35 $this->_apiversion
= 3;
37 $this->_entity
= 'participant';
38 $event = $this->eventCreate(NULL);
39 $this->_eventID
= $event['id'];
41 $this->_contactID
= $this->individualCreate();
43 $this->_createdParticipants
= [];
44 $this->_individualId
= $this->individualCreate();
46 $this->_participantID
= $this->participantCreate([
47 'contact_id' => $this->_contactID
,
48 'event_id' => $this->_eventID
,
50 $this->_contactID2
= $this->individualCreate();
51 $this->_participantID2
= $this->participantCreate([
52 'contact_id' => $this->_contactID2
,
53 'event_id' => $this->_eventID
,
54 'registered_by_id' => $this->_participantID
,
56 $this->_participantID3
= $this->participantCreate([
57 'contact_id' => $this->_contactID2
,
58 'event_id' => $this->_eventID
,
61 'contact_id' => $this->_contactID
,
62 'event_id' => $this->_eventID
,
65 // to ensure it matches later on
66 'register_date' => '2007-07-21 00:00:00',
67 'source' => 'Online Event Registration: API Testing',
71 public function tearDown() {
72 $this->eventDelete($this->_eventID
);
74 'civicrm_custom_group',
75 'civicrm_custom_field',
77 'civicrm_participant',
79 // true tells quickCleanup to drop any tables that might have been created in the test
80 $this->quickCleanup($tablesToTruncate, TRUE);
84 * Check that getCount can count past 25.
86 public function testGetCountLimit() {
89 for ($count = $this->callAPISuccessGetCount('Participant', []); $count < 27; $count++
) {
90 $contactIDs[] = $contactID = $this->individualCreate();
91 $this->participantCreate(['contact_id' => $contactID, 'event_id' => $this->_eventID
]);
93 $this->callAPISuccessGetCount('Participant', [], 27);
95 foreach ($contactIDs as $contactID) {
96 $this->callAPISuccess('Contact', 'delete', ['id' => $contactID]);
101 * Test get participants with role_id.
103 public function testGetParticipantWithRole() {
105 foreach ($roleId as $role) {
106 $this->participantCreate([
107 'contact_id' => $this->individualCreate(),
109 'event_id' => $this->_eventID
,
116 $result = $this->callAPISuccess('participant', 'get', $params);
117 //Assert all the returned participants has a role_id of 2
118 foreach ($result['values'] as $pid => $values) {
119 $this->assertEquals($values['participant_role_id'], 2);
122 $this->participantCreate([
123 'id' => $this->_participantID
,
125 'event_id' => $this->_eventID
,
128 $params['role_id'] = [
131 $result = $this->callAPISuccess('participant', 'get', $params);
132 foreach ($result['values'] as $pid => $values) {
133 $this->assertEquals($values['participant_role_id'], NULL);
139 * Check with complete array + custom field
140 * Note that the test is written on purpose without any
141 * variables specific to participant so it can be replicated into other entities
142 * and / or moved to the automated test suite
144 public function testCreateWithCustom() {
145 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
147 $params = $this->_params
;
148 $params['custom_' . $ids['custom_field_id']] = "custom string";
150 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
152 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
154 $check = $this->callAPISuccess($this->_entity
, 'get', ['id' => $result['id']]);
155 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
157 $this->customFieldDelete($ids['custom_field_id']);
158 $this->customGroupDelete($ids['custom_group_id']);
162 * Check with participant_id.
164 public function testGetParticipantIdOnly() {
166 'participant_id' => $this->_participantID
,
170 'participant_register_date',
171 'participant_source',
174 $result = $this->callAPISuccess('participant', 'get', $params);
175 $this->assertAPISuccess($result, " in line " . __LINE__
);
176 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
177 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
178 $this->assertEquals($result['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
180 'id' => $this->_participantID
,
181 'return' => 'id,participant_register_date,event_id',
184 $result = $this->callAPISuccess('participant', 'get', $params);
185 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
186 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
191 * Test permission for participant get.
193 public function testGetParticipantWithPermission() {
194 $config = CRM_Core_Config
::singleton();
195 $config->userPermissionClass
->permissions
= [];
197 'event_id' => $this->_eventID
,
198 'check_permissions' => TRUE,
202 'participant_register_date',
203 'participant_source',
206 $this->callAPIFailure('participant', 'get', $params);
208 $params['check_permissions'] = FALSE;
209 $result = $this->callAPISuccess('participant', 'get', $params);
210 $this->assertEquals($result['is_error'], 0);
214 * Check with params id.
216 public function testGetParamsAsIdOnly() {
218 'id' => $this->_participantID
,
220 $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__
, __FILE__
);
221 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
222 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
223 $this->assertEquals($result['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
224 $this->assertEquals($result['id'], $result['values'][$this->_participantID
]['id']);
228 * Check with params id.
230 public function testGetNestedEventGet() {
231 //create a second event & add participant to it.
232 $event = $this->eventCreate(NULL);
233 $this->callAPISuccess('participant', 'create', [
234 'event_id' => $event['id'],
235 'contact_id' => $this->_contactID
,
238 $description = "Demonstrates use of nested get to fetch event data with participant records.";
239 $subfile = "NestedEventGet";
241 'id' => $this->_participantID
,
242 'api.event.get' => 1,
244 $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
245 $this->assertEquals($result['values'][$this->_participantID
]['event_id'], $this->_eventID
);
246 $this->assertEquals($result['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
247 $this->assertEquals($result['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
248 $this->assertEquals($this->_eventID
, $result['values'][$this->_participantID
]['api.event.get']['id']);
252 * Check Participant Get respects return properties.
254 public function testGetWithReturnProperties() {
256 'contact_id' => $this->_contactID
,
257 'return.status_id' => 1,
258 'return.participant_status_id' => 1,
259 'options' => ['limit' => 1],
261 $result = $this->callAPISuccess('participant', 'get', $params);
262 $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]);
266 * Check with contact_id.
268 public function testGetContactIdOnly() {
270 'contact_id' => $this->_contactID
,
272 $participant = $this->callAPISuccess('participant', 'get', $params);
274 $this->assertEquals($this->_participantID
, $participant['id']);
275 $this->assertEquals($this->_eventID
, $participant['values'][$participant['id']]['event_id']);
276 $this->assertEquals('2007-02-19 00:00:00', $participant['values'][$participant['id']]['participant_register_date']);
277 $this->assertEquals('Wimbeldon', $participant['values'][$participant['id']]['participant_source']);
278 $this->assertEquals($participant['id'], $participant['values'][$participant['id']]['id']);
282 * Check with event_id.
285 public function testGetMultiMatchReturnFirst() {
287 'event_id' => $this->_eventID
,
291 $participant = $this->callAPISuccess('participant', 'get', $params);
292 $this->assertNotNull($participant['id']);
296 * Check with event_id.
297 * in v3 this should return all participants
299 public function testGetMultiMatchNoReturnFirst() {
301 'event_id' => $this->_eventID
,
303 $participant = $this->callAPISuccess('participant', 'get', $params);
304 $this->assertNotNull($participant['count'], 3);
307 ///////////////// civicrm_participant_get methods
310 * Test civicrm_participant_get with empty params.
311 * In this case all the participant records are returned.
313 public function testSearchEmptyParams() {
314 $result = $this->callAPISuccess('participant', 'get', []);
315 // expecting 3 participant records
316 $this->assertEquals($result['count'], 3);
320 * Check with participant_id.
322 public function testSearchParticipantIdOnly() {
324 'participant_id' => $this->_participantID
,
326 $participant = $this->callAPISuccess('participant', 'get', $params);
327 $this->assertEquals($participant['values'][$this->_participantID
]['event_id'], $this->_eventID
);
328 $this->assertEquals($participant['values'][$this->_participantID
]['participant_register_date'], '2007-02-19 00:00:00');
329 $this->assertEquals($participant['values'][$this->_participantID
]['participant_source'], 'Wimbeldon');
333 * Check with contact_id.
335 public function testSearchContactIdOnly() {
336 // Should get 2 participant records for this contact.
338 'contact_id' => $this->_contactID2
,
340 $participant = $this->callAPISuccess('participant', 'get', $params);
342 $this->assertEquals($participant['count'], 2);
346 * Check with event_id.
348 public function testSearchByEvent() {
349 // Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned.
351 'event_id' => $this->_eventID
,
352 'return.last_name' => 1,
353 'return.event_title' => 1,
355 $participant = $this->callAPISuccess('participant', 'get', $params);
356 if ($participant['count'] < 3) {
357 $this->fail("Event search returned less than expected miniumum of 3 records.");
360 $this->assertEquals($participant['values'][$this->_participantID
]['last_name'], 'Anderson');
361 $this->assertEquals($participant['values'][$this->_participantID
]['event_title'], 'Annual CiviCRM meet');
365 * Check with event_id.
368 public function testSearchByEventWithLimit() {
369 // Should 2 participant records since we're passing rowCount = 2.
371 'event_id' => $this->_eventID
,
374 $participant = $this->callAPISuccess('participant', 'get', $params);
376 $this->assertEquals($participant['count'], 2);
380 * Test search by lead booker (registered by ID)
382 public function testSearchByRegisteredById() {
384 'registered_by_id' => $this->_participantID
,
386 $participant = $this->callAPISuccess('participant', 'get', $params);
388 $this->assertEquals($participant['count'], 1);
389 $this->assertEquals($participant['id'], $this->_participantID2
);
392 ///////////////// civicrm_participant_create methods
395 * Test civicrm_participant_create with empty params.
397 public function testCreateEmptyParams() {
399 $result = $this->callAPIFailure('participant', 'create', $params);
403 * Check with event_id.
405 public function testCreateMissingContactID() {
406 $this->callAPIFailure('participant', 'create', ['event_id' => $this->_eventID
]);
410 * Check with contact_id.
413 public function testCreateMissingEventID() {
414 $this->callAPIFailure('participant', 'create', ['contact_id' => $this->_contactID
]);
418 * Check with contact_id & event_id
420 public function testCreateEventIdOnly() {
422 'contact_id' => $this->_contactID
,
423 'event_id' => $this->_eventID
,
425 $participant = $this->callAPISuccess('participant', 'create', $params);
426 $this->getAndCheck($params, $participant['id'], 'participant');
430 * Check with complete array.
432 public function testCreateAllParams() {
433 $participant = $this->callAPISuccess('participant', 'create', $this->_params
);
434 $this->_participantID
= $participant['id'];
435 $this->assertDBState('CRM_Event_DAO_Participant', $participant['id'], $this->_params
);
439 * Test that an overlong source is handled.
441 public function testLongSource() {
442 $params = array_merge($this->_params
, [
443 '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',
445 $baoCreated = CRM_Event_BAO_Participant
::create($params);
446 $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
);
447 // @todo - currently the api will still reject the long string.
448 //$this->callAPISuccess('participant', 'create', $params);
452 * Test to check if receive date is being changed per CRM-9763
454 public function testCreateUpdateReceiveDate() {
455 $participant = $this->callAPISuccess('participant', 'create', $this->_params
);
457 'id' => $participant['id'],
460 $this->callAPISuccess('participant', 'create', $update);
461 $this->getAndCheck(array_merge($this->_params
, $update), $participant['id'], 'participant');
465 * Test to check if participant fee level is being changed per CRM-9781
467 public function testCreateUpdateParticipantFeeLevel() {
468 $myParams = $this->_params +
['participant_fee_level' => CRM_Core_DAO
::VALUE_SEPARATOR
. "fee" . CRM_Core_DAO
::VALUE_SEPARATOR
];
469 $participant = $this->callAPISuccess('participant', 'create', $myParams);
471 'id' => $participant['id'],
474 $update = $this->callAPISuccess('participant', 'create', $update);
476 $this->assertEquals($participant['values'][$participant['id']]['fee_level'],
477 $update['values'][$participant['id']]['fee_level']
480 $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);
484 * Test the line items for participant fee with multiple price field values.
486 public function testCreateParticipantLineItems() {
487 // Create a price set for this event.
489 $priceset = $this->callAPISuccess('PriceSet', 'create', [
490 'name' => 'my_price_set',
491 'title' => 'My Price Set',
494 'financial_type_id' => 4,
495 // 'entity' => array('civicrm_event' => array($this->_eventID)),
498 // Add the price set to the event with another API call.
499 // I tried to do this at once, but it did not work.
501 $priceset = $this->callAPISuccess('PriceSet', 'create', [
502 'entity_table' => 'civicrm_event',
503 'entity_id' => $this->_eventID
,
504 'id' => $priceset['id'],
507 $pricefield = $this->callAPISuccess('PriceField', 'create', [
508 'price_set_id' => $priceset['id'],
509 'name' => 'mypricefield',
510 'label' => 'My Price Field',
511 'html_type' => 'Text',
513 'is_display_amounts' => 1,
517 $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', [
518 'price_field_id' => $pricefield['id'],
519 'name' => 'pricefieldvalue1',
520 'label' => 'pricefieldvalue1',
523 'financial_type_id' => 4,
526 $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', [
527 'price_field_id' => $pricefield['id'],
528 'name' => 'pricefieldvalue2',
529 'label' => 'pricefieldvalue2',
532 'financial_type_id' => 4,
535 // pay 2 times price field value 1, and 2 times price field value 2.
536 $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
];
537 $participant = $this->callAPISuccess('participant', 'create', $myParams);
539 // expect 2 line items.
540 $lineItems = $this->callAPISuccess('LineItem', 'get', [
541 'entity_id' => $participant['id'],
542 'entity_table' => 'civicrm_participant',
545 $this->assertEquals(2, $lineItems['count']);
547 // Check quantity, label and unit price of lines.
548 // TODO: These assertions depend on the order of the line items, which is
549 // technically incorrect.
551 $lineItem = array_pop($lineItems['values']);
552 $this->assertEquals(2, $lineItem['qty']);
553 $this->assertEquals(5, $lineItem['unit_price']);
554 $this->assertEquals('pricefieldvalue2', $lineItem['label']);
556 $lineItem = array_pop($lineItems['values']);
557 $this->assertEquals(2, $lineItem['qty']);
558 $this->assertEquals(20, $lineItem['unit_price']);
559 $this->assertEquals('pricefieldvalue1', $lineItem['label']);
560 $this->callAPISuccess('PriceFieldValue', 'create', ['id' => $pfv2['id'], 'label' => 'Price FIeld Value 2 Label']);
561 $participantGet = $this->callAPISuccess('Participant', 'get', ['id' => $participant['id']]);
562 $this->assertEquals(["pricefieldvalue1 - 2", "pricefieldvalue2 - 2"], $participantGet['values'][$participant['id']]['participant_fee_level']);
563 $conatactID4 = $this->individualCreate();
564 $myParams['contact_id'] = $conatactID4;
565 $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
;
566 $AdditionalParticipant = $this->callAPISuccess('Participant', 'create', $myParams);
567 $this->assertEquals(["pricefieldvalue1 - 2", "Price FIeld Value 2 Label - 2"], $AdditionalParticipant['values'][$AdditionalParticipant['id']]['fee_level']);
568 $lineItems = $this->callAPISuccess('LineItem', 'get', [
569 'entity_id' => $AdditionalParticipant['id'],
570 'entity_table' => 'civicrm_participant',
572 $this->assertEquals(2, $lineItems['count']);
574 // Check quantity, label and unit price of lines.
575 // TODO: These assertions depend on the order of the line items, which is
576 // technically incorrect.
578 $lineItem = array_pop($lineItems['values']);
579 $this->assertEquals(2, $lineItem['qty']);
580 $this->assertEquals(5, $lineItem['unit_price']);
581 $this->assertEquals('Price FIeld Value 2 Label', $lineItem['label']);
583 $lineItem = array_pop($lineItems['values']);
584 $this->assertEquals(2, $lineItem['qty']);
585 $this->assertEquals(20, $lineItem['unit_price']);
586 $this->assertEquals('pricefieldvalue1', $lineItem['label']);
589 $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);
591 // TODO: I think the price set should be removed, but I don't know how
592 // to decouple it properly from the event. For the moment, I'll just comment
593 // out the lines below.
596 $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv1['id']));
597 $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv2['id']));
598 $this->callAPISuccess('PriceField', 'delete', array('id' => $pricefield['id']));
599 $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceset['id']));
604 * Check with complete array.
606 public function testUpdate() {
607 $participantId = $this->participantCreate([
608 'contactID' => $this->_individualId
,
609 'eventID' => $this->_eventID
,
612 'id' => $participantId,
613 'contact_id' => $this->_individualId
,
614 'event_id' => $this->_eventID
,
617 'register_date' => '2006-01-21',
618 'source' => 'US Open',
620 $participant = $this->callAPISuccess('participant', 'create', $params);
621 $this->getAndCheck($params, $participant['id'], 'participant');
622 $result = $this->participantDelete($params['id']);
626 * Test to check if participant fee level is being changed per CRM-9781
627 * Try again without a custom separater to check that one isn't added
628 * (get & check won't accept an array)
630 public function testUpdateCreateParticipantFeeLevelNoSeparator() {
632 $myParams = $this->_params +
['participant_fee_level' => "fee"];
633 $participant = $this->callAPISuccess('participant', 'create', $myParams);
634 $this->assertAPISuccess($participant);
636 'id' => $participant['id'],
639 $this->callAPISuccess('participant', 'create', $update);
640 $this->assertEquals($participant['values'][$participant['id']]['fee_level'],
641 $myParams['participant_fee_level']
643 $this->getAndCheck($update, $participant['id'], 'participant');
646 ///////////////// civicrm_participant_update methods
649 * Check with empty array.
651 public function testUpdateEmptyParams() {
653 $participant = $this->callAPIFailure('participant', 'create', $params);
654 $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id');
658 * Check without event_id.
660 public function testUpdateWithoutEventId() {
661 $participantId = $this->participantCreate(['contactID' => $this->_individualId
, 'eventID' => $this->_eventID
]);
663 'contact_id' => $this->_individualId
,
666 'register_date' => '2006-01-21',
667 'source' => 'US Open',
668 'event_level' => 'Donation',
670 $participant = $this->callAPIFailure('participant', 'create', $params);
671 $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id');
672 // Cleanup created participant records.
673 $result = $this->participantDelete($participantId);
677 * Check with Invalid participantId.
679 public function testUpdateWithWrongParticipantId() {
684 'register_date' => '2006-01-21',
685 'source' => 'US Open',
686 'event_level' => 'Donation',
688 $participant = $this->callAPIFailure('Participant', 'update', $params);
692 * Check with Invalid ContactId.
694 public function testUpdateWithWrongContactId() {
695 $participantId = $this->participantCreate([
696 'contactID' => $this->_individualId
,
697 'eventID' => $this->_eventID
,
698 ], $this->_apiversion
);
700 'id' => $participantId,
701 'contact_id' => 12345,
704 'register_date' => '2006-01-21',
705 'source' => 'US Open',
706 'event_level' => 'Donation',
708 $participant = $this->callAPIFailure('participant', 'create', $params);
709 $result = $this->participantDelete($participantId);
712 ///////////////// civicrm_participant_delete methods
715 * Test civicrm_participant_delete with empty params.
717 public function testDeleteEmptyParams() {
719 $result = $this->callAPIFailure('participant', 'delete', $params);
723 * Check with participant_id.
725 public function testParticipantDelete() {
727 'id' => $this->_participantID
,
729 $participant = $this->callAPISuccess('participant', 'delete', $params);
730 $this->assertAPISuccess($participant);
731 $this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID
, NULL, TRUE);
735 * Check without participant_id.
737 * This should return an error because required param is missing..
739 public function testParticipantDeleteMissingID() {
741 'event_id' => $this->_eventID
,
743 $participant = $this->callAPIFailure('participant', 'delete', $params);
744 $this->assertNotNull($participant['error_message']);
748 * Delete with a get - a 'criteria delete'
750 public function testNestedDelete() {
751 $description = "Criteria delete by nesting a GET & a DELETE.";
752 $subfile = "NestedDelete";
753 $participants = $this->callAPISuccess('Participant', 'Get', []);
754 $this->assertEquals($participants['count'], 3);
755 $params = ['contact_id' => $this->_contactID2
, 'api.participant.delete' => 1];
756 $this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
757 $check = $this->callAPISuccess('participant', 'getcount', []);
758 $this->assertEquals(1, $check, "only one participant should be left");
762 * Test creation of a participant with an associated contribution.
764 public function testCreateParticipantWithPayment() {
765 $description = "Single function to create contact with partipation & contribution.
766 Note that in the case of 'contribution' the 'create' is implied (api.contribution.create)";
767 $subfile = "CreateParticipantPayment";
769 'contact_type' => 'Individual',
770 'display_name' => 'dlobo',
771 'api.participant' => [
772 'event_id' => $this->_eventID
,
775 'format.only_id' => 1,
777 'api.contribution.create' => [
778 'financial_type_id' => 1,
779 'total_amount' => 100,
780 'format.only_id' => 1,
782 'api.participant_payment.create' => [
783 'contribution_id' => '$value.api.contribution.create',
784 'participant_id' => '$value.api.participant',
788 $result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
789 $this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']);
790 $this->callAPISuccess('contact', 'delete', ['id' => $result['id']]);
794 * Test participant invoke post hook after status update.
796 public function testPostHookForAdditionalParticipant() {
797 $participantID = $this->participantCreate([
798 'contact_id' => $this->_contactID
,
800 'event_id' => $this->_eventID
,
802 $participantID2 = $this->participantCreate([
803 'contact_id' => $this->_contactID2
,
804 'event_id' => $this->_eventID
,
806 'registered_by_id' => $participantID,
809 $this->hookClass
->setHook('civicrm_post', [$this, 'onPost']);
811 'id' => $participantID,
814 $this->callAPISuccess('Participant', 'create', $params);
816 $result = $this->callAPISuccess('Participant', 'get', ['source' => 'Post Hook Update']);
817 $this->assertEquals(2, $result['count']);
819 $expected = [$participantID, $participantID2];
820 $actual = array_keys($result['values']);
821 $this->checkArrayEquals($expected, $actual);