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 * Class api_v3_EventTest
16 class api_v3_EventTest
extends CiviUnitTestCase
{
18 protected $_apiversion;
21 public function setUp(): void
{
23 $this->_apiversion
= 3;
24 $this->_entity
= 'event';
27 'title' => 'Annual CiviCRM meet',
28 'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now',
29 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
32 'start_date' => 20081021,
33 'end_date' => 20081023,
34 'is_online_registration' => 1,
35 'registration_start_date' => 20080601,
36 'registration_end_date' => '2008-10-15',
37 'max_participants' => 100,
38 'event_full_text' => 'Sorry! We are already full',
41 'is_show_location' => 0,
44 'title' => 'Annual CiviCRM meet 2',
45 'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now',
46 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
49 'start_date' => 20101021,
50 'end_date' => 20101023,
51 'is_online_registration' => 1,
52 'registration_start_date' => 20100601,
53 'registration_end_date' => '2010-10-15',
54 'max_participants' => 100,
55 'event_full_text' => 'Sorry! We are already full',
58 'is_show_location' => 0,
64 'title' => 'Annual CiviCRM meet',
66 'start_date' => 20081021,
69 'title' => 'Annual CiviCRM meet 2',
71 'start_date' => 20101021,
77 foreach ($params as $event) {
78 $result = $this->callAPISuccess('Event', 'Create', $event);
79 $this->_events
[] = $result;
80 $this->_eventIds
[] = $result['id'];
84 public function tearDown(): void
{
85 foreach ($this->eventIds
as $eventId) {
86 $this->eventDelete($eventId);
89 'civicrm_participant',
92 $this->quickCleanup($tablesToTruncate, TRUE);
97 * civicrm_event_get methods.
99 public function testGetEventById() {
101 'id' => $this->_events
[1]['id'],
103 $result = $this->callAPISuccess('event', 'get', $params);
104 $this->assertEquals($result['values'][$this->_eventIds
[1]]['event_title'], 'Annual CiviCRM meet 2');
108 * Test getLocationEvents() function invokes selectWhereClause() hook
110 public function testGetEventWithPermissionHook() {
111 $address = $this->callAPISuccess('address', 'create', [
112 'contact_id' => 'null',
113 'location_type_id' => 1,
114 'street_address' => '1234567',
117 'address_id' => $address['id'],
119 $result = $this->callAPISuccess('loc_block', 'create', $params);
121 'id' => $this->_events
[1]['id'],
122 'loc_block_id' => $result['id'],
124 $this->callAPISuccess('Event', 'create', $params);
125 $result = CRM_Event_BAO_Event
::getLocationEvents();
126 $this->assertEquals(1, count($result));
128 $this->hookClass
->setHook('civicrm_selectWhereClause', [$this, 'selectWhereClauseHook']);
129 $result = CRM_Event_BAO_Event
::getLocationEvents();
130 $this->assertEquals(0, count($result));
133 public function testGetEventByEventTitle() {
136 'event_title' => 'Annual CiviCRM meet',
137 'sequential' => TRUE,
140 $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__
, __FILE__
);
141 $this->assertEquals(1, $result['count']);
142 $this->assertEquals($result['values'][0]['id'], $this->_eventIds
[0]);
146 * @param int $version
147 * @dataProvider versionThreeAndFour
149 public function testGetEventByWrongTitle($version) {
150 $this->_apiversion
= $version;
152 'title' => 'No event with that title',
154 $result = $this->callAPISuccess('Event', 'Get', $params);
155 $this->assertEquals(0, $result['count']);
159 * Skip api4 - this api uses deprecated query syntax
161 public function testGetEventByIdSort() {
163 'return.sort' => 'id ASC',
164 'return.max_results' => 1,
166 $result = $this->callAPISuccess('Event', 'Get', $params);
167 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
175 $result = $this->callAPISuccess('Event', 'Get', $params);
176 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
177 $this->assertEquals(2, $result['id'], ' in line ' . __LINE__
);
184 $result = $this->callAPISuccess('Event', 'Get', $params);
185 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
190 * Getting the id back of an event.
191 * Does not work yet, bug in API
195 public function testGetIdOfEventByEventTitle() {
196 $params = array( 'title' => 'Annual CiviCRM meet',
200 $result = $this->callAPISuccess('Event', 'Get', $params);
205 * Test 'is.Current' option. Existing event is 'old' so only current should be returned
208 public function testGetIsCurrent() {
212 $currentEventParams = [
213 'start_date' => date('Y-m-d', strtotime('+ 1 day')),
214 'end_date' => date('Y-m-d', strtotime('+ 1 week')),
216 $currentEventParams = array_merge($this->_params
[1], $currentEventParams);
217 $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams);
218 $description = "Demonstrates use of is.Current option.";
219 $subfile = "IsCurrentOption";
220 $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
221 $allEvents = $this->callAPISuccess('Event', 'Get', []);
222 $this->callAPISuccess('Event', 'Delete', ['id' => $currentEvent['id']]);
223 $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__
);
224 $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__
);
225 $this->assertEquals($currentEvent['id'], $result['id'], '');
229 * There has been a schema change & the api needs to buffer developers from it
232 public function testGetPaymentProcessorId() {
233 $params = $this->_params
[0];
234 $params['payment_processor_id'] = 1;
235 $params['sequential'] = 1;
236 $result = $this->callAPISuccess('event', 'create', $params);
237 $this->assertEquals(1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility");
238 $result = $this->callAPISuccess('event', 'get', $params);
239 $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility");
243 * @param int $version
244 * @dataProvider versionThreeAndFour
246 public function testInvalidData($version) {
247 $this->_apiversion
= $version;
248 $params = $this->_params
[0];
249 $params['sequential'] = 1;
250 $params['loc_block_id'] = 100;
251 $result = $this->callAPIFailure('event', 'create', $params);
256 * Test 'is_full' option.
259 public function testGetSingleReturnIsFull() {
260 $contactID = $this->individualCreate();
262 'id' => $this->_eventIds
[0],
263 'max_participants' => 1,
265 $result = $this->callAPISuccess('Event', 'Create', $params);
268 'id' => $this->_eventIds
[0],
269 'return.is_full' => 1,
272 $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams);
273 $description = "Demonstrates use of return is_full .";
274 $subfile = "IsFullOption";
275 $this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
276 $this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
277 $participant = $this->callAPISuccess('Participant', 'create', [
278 'participant_status' => 1,
280 'contact_id' => $contactID,
281 'event_id' => $this->_eventIds
[0],
283 $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__
, __FILE__
, $description, $subfile);
284 $this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
285 $this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
287 $this->contactDelete($contactID);
291 * Legacy support for Contribution Type ID.
293 * We need to ensure this is supported as an alias for financial_type_id.
295 public function testCreateGetEventLegacyContributionTypeID() {
296 $contributionTypeArray = ['contribution_type_id' => 3];
297 if (isset($this->_params
[0]['financial_type_id'])) {
298 //in case someone edits $this->_params & invalidates this test :-)
299 unset($this->_params
[0]['financial_type_id']);
301 $result = $this->callAPISuccess('event', 'create', $this->_params
[0] +
$contributionTypeArray);
302 $getresult = $this->callAPISuccess('event', 'get', [] +
$contributionTypeArray);
303 $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
304 $this->assertEquals($result['id'], $getresult['id']);
305 $this->callAPISuccess('event', 'delete', ['id' => $result['id']]);
309 * Chaining get event and loc block.
310 * @param int $version
311 * @dataProvider versionThreeAndFour
313 public function testChainingGetLocBlock($version) {
314 $this->_apiversion
= $version;
315 // create a loc block and an event for that loc block.
316 $eventParams = $this->_params
[0];
317 $eventParams['loc_bloc_id'] = '$value.id';
320 'street_address' => 'Kipdorp 24',
321 'postal_code' => '2000',
322 'city' => 'Antwerpen',
323 'country_id' => '1020',
324 'location_type_id' => '1',
326 'api.Event.create' => $eventParams,
329 $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams);
330 $locBlockId = $createResult['id'];
331 $eventId = $createResult['values'][0]['api.Event.create']['id'];
333 // request the event with its loc block:
334 $check = $this->callAPISuccess($this->_entity
, 'getsingle', [
336 'api.LocBlock.get' => ['id' => '$value.loc_block_id'],
341 $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__
);
342 $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__
);
343 $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__
);
346 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $eventId]);
350 * Chaining get event and non existing loc block.
352 * Even if there is no loc block, at least the event should be returned.
353 * http://forum.civicrm.org/index.php/topic,36113.0.html
355 public function testChainingGetNonExistingLocBlock() {
356 $params = $this->_params
[0];
357 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
359 $check = $this->callAPISuccess($this->_entity
, 'get', [
360 'id' => $result['id'],
361 // this chaining request should not break things:
362 'api.LocBlock.get' => ['id' => '$value.loc_block_id'],
364 $this->assertEquals($result['id'], $check['id']);
366 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
370 * Check with complete array + custom field.
372 * Note that the test is written on purpose without any
373 * variables specific to participant so it can be replicated into other entities
374 * and / or moved to the automated test suite.
375 * @param int $version
376 * @dataProvider versionThreeAndFour
378 public function testCreateWithCustom($version) {
379 $this->_apiversion
= $version;
380 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
382 $params = $this->_params
[0];
383 $params['custom_' . $ids['custom_field_id']] = "custom string";
385 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
387 $check = $this->callAPISuccess($this->_entity
, 'get', [
388 'return.custom_' . $ids['custom_field_id'] => 1,
389 'id' => $result['id'],
391 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
393 $this->customFieldDelete($ids['custom_field_id']);
394 $this->customGroupDelete($ids['custom_group_id']);
395 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
399 * Check searching on custom fields.
401 * https://issues.civicrm.org/jira/browse/CRM-16036
402 * @param int $version
403 * @dataProvider versionThreeAndFour
405 public function testSearchCustomField($version) {
406 $this->_apiversion
= $version;
407 // create custom group with custom field on event
408 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
410 // Search for events having CRM-16036 as the value for this custom
411 // field. This should not return anything.
412 $check = $this->callAPISuccess($this->_entity
, 'get', [
413 'custom_' . $ids['custom_field_id'] => 'CRM-16036',
416 $this->assertEquals(0, $check['count']);
418 $this->customFieldDelete($ids['custom_field_id']);
419 $this->customGroupDelete($ids['custom_group_id']);
423 * Check searching on custom fields with IS NULL.
425 * https://issues.civicrm.org/jira/browse/CRM-20740
426 * @param int $version
427 * @dataProvider versionThreeAndFour
429 public function testSearchCustomFieldIsNull($version) {
430 $this->_apiversion
= $version;
431 // create custom group with custom field on event
432 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
434 // Search for events having NULL as the value for this custom
435 // field. This should return all events created in setUp.
436 $check = $this->callAPISuccess($this->_entity
, 'get', [
437 'custom_' . $ids['custom_field_id'] => ['IS NULL' => 1],
440 $this->assertGreaterThan(0, $check['count']);
442 $this->customFieldDelete($ids['custom_field_id']);
443 $this->customGroupDelete($ids['custom_group_id']);
447 * Test searching on custom fields returning a contact reference.
449 * https://issues.civicrm.org/jira/browse/CRM-16036
452 public function testEventGetCustomContactRefFieldCRM16036() {
453 // Create some contact.
454 $test_contact_name = 'Contact, Test';
455 $contact_save_result = $this->callAPISuccess('contact', 'create', [
456 'sort_name' => $test_contact_name,
457 'contact_type' => 'Individual',
458 'display_name' => $test_contact_name,
460 $contact_id = $contact_save_result['id'];
462 // I have no clue what this $subfile is about. I just copied it from another
464 $subfile = 'ContactRefCustomField';
465 $description = "Demonstrates get with Contact Reference Custom Field.";
467 // Create a custom group, and add a custom contact reference field.
468 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
470 'custom_group_id' => $ids['custom_group_id'],
471 'name' => 'Worker_Lookup',
472 'label' => 'Worker Lookup',
473 'html_type' => 'Autocomplete-Select',
474 'data_type' => 'ContactReference',
476 'is_searchable' => 1,
479 $customField = $this->callAPISuccess('custom_field', 'create', $params);
481 // Create an event, and add the contact as custom value.
482 $params = $this->_params
;
483 $params['title'] = "My test event.";
484 $params['start_date'] = "2015-03-14";
485 // Just assume that an event type 1 exists.
486 $params['event_type_id'] = 1;
487 $params['custom_' . $customField['id']] = "$contact_id";
489 $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
491 // Retrieve the activity, search for the contact.
492 $result = $this->callAPIAndDocument($this->_entity
, 'get', [
493 'return.custom_' . $customField['id'] => 1,
494 'custom_' . $customField['id'] => $contact_id,
495 ], __FUNCTION__
, __FILE__
, $description, $subfile);
497 $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
498 $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__
);
499 // Not sure whether I should test for custom_X_1 and custom_X_1_id as well.
500 // (1 being the id of the record in the custom value table)
502 $this->customFieldDelete($ids['custom_field_id']);
503 $this->customGroupDelete($ids['custom_group_id']);
504 $this->callAPISuccess('contact', 'delete', [
506 'skip_undelete' => TRUE,
511 * Test searching on custom fields with less than or equal.
514 * @param int $version
515 * @dataProvider versionThreeAndFour
517 public function testEventGetCustomFieldLte($version) {
518 $this->_apiversion
= $version;
519 // create custom group with custom field on event
520 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
522 // Create an event, with a custom value.
523 $params = $this->_params
;
524 $params['title'] = "My test event.";
525 $params['start_date'] = "2015-03-14";
526 // Just assume that an event type 1 exists.
527 $params['event_type_id'] = 1;
528 $params['custom_' . $ids['custom_field_id']] = "AAAA";
530 $save_result = $this->callApiSuccess($this->_entity
, 'create', $params);
532 // Retrieve the activity, search for custom field < 'BBBB'
533 $get_result = $this->callAPISuccess($this->_entity
, 'get', [
534 'return.custom_' . $ids['custom_field_id'] => 1,
535 'custom_' . $ids['custom_field_id'] => ['<=' => 'BBBB'],
538 // Expect that we find the saved event.
539 $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
541 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $save_result['id']]);
545 * Test searching on custom fields with netsted call with id param.
547 * Search for an event on a custom field, and perform a chained call
548 * to retrieve it's (non-existing) loc block, using $value-substitution.
549 * This test just checks whether the event is found, because something
550 * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing
551 * CiviCRM to return 0 results.
552 * Of course, CRM-16168 should also be fixed for this test to pass.
554 public function testEventSearchCustomFieldWithChainedCall() {
555 // Create a custom group, and add a custom contact reference field.
556 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
557 $custom_field_id = $ids['custom_field_id'];
559 // Create an event with a custom value.
560 $params = $this->_params
;
561 $params['title'] = "My test event.";
562 $params['start_date'] = "2015-03-14";
563 // Just assume that an event type 1 exists.
564 $params['event_type_id'] = 1;
565 $params['custom_' . $custom_field_id] = "12345";
567 $this->callAPISuccess($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
569 // Retrieve the activity, and chain loc block using $value.
570 $result = $this->callAPISuccess($this->_entity
, 'get', [
571 'custom_' . $custom_field_id => "12345",
572 'api.LocBlock.get' => ["id" => '$value.loc_block_id'],
575 $this->assertEquals(1, $result['count']);
577 $this->customFieldDelete($ids['custom_field_id']);
578 $this->customGroupDelete($ids['custom_group_id']);
579 $this->callAPISuccess('event', 'delete', [
580 'id' => $result['id'],
581 'skip_undelete' => TRUE,
586 * Test that an event with a price set can be created.
589 public function testCreatePaidEvent() {
590 //@todo alter API so that an integer is converted to an array
591 $priceSetParams = ['price_set_id' => (array) 1, 'is_monetary' => 1];
592 $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params
[0], $priceSetParams));
593 $event = $this->callAPISuccess('Event', 'getsingle', ['id' => $result['id'], 'return' => 'price_set_id']);
594 $this->assertArrayKeyExists('price_set_id', $event);
598 * @param int $version
599 * @dataProvider versionThreeAndFour
601 public function testCreateEventEmptyParams($version) {
602 $this->_apiversion
= $version;
604 $result = $this->callAPIFailure('event', 'create', $params);
608 * @param int $version
609 * @dataProvider versionThreeAndFour
611 public function testCreateEventParamsWithoutTitle($version) {
612 $this->_apiversion
= $version;
613 unset($this->_params
['title']);
614 $result = $this->callAPIFailure('event', 'create', $this->_params
);
615 $this->assertAPIFailure($result);
619 * @param int $version
620 * @dataProvider versionThreeAndFour
622 public function testCreateEventParamsWithoutEventTypeId($version) {
623 $this->_apiversion
= $version;
624 unset($this->_params
['event_type_id']);
625 $result = $this->callAPIFailure('event', 'create', $this->_params
);
629 * @param int $version
630 * @dataProvider versionThreeAndFour
632 public function testCreateEventParamsWithoutStartDate($version) {
633 $this->_apiversion
= $version;
634 unset($this->_params
['start_date']);
635 $result = $this->callAPIFailure('event', 'create', $this->_params
, 'start_date');
639 * @param int $version
640 * @dataProvider versionThreeAndFour
642 public function testCreateEventSuccess($version) {
643 $this->_apiversion
= $version;
644 $result = $this->callAPIAndDocument('Event', 'Create', $this->_params
[0], __FUNCTION__
, __FILE__
);
645 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
646 $result = $this->callAPISuccess($this->_entity
, 'Get', ['id' => $result['id']]);
647 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
648 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set');
649 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set');
650 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set');
651 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set');
655 * Test that passing in Unique field names works.
656 * Skip api4 which doesn't use unique names
658 public function testCreateEventSuccessUniqueFieldNames() {
659 $this->_params
[0]['event_start_date'] = $this->_params
[0]['start_date'];
660 unset($this->_params
[1]['start_date']);
661 $this->_params
[0]['event_title'] = $this->_params
[0]['title'];
662 unset($this->_params
[0]['title']);
663 $result = $this->callAPISuccess('Event', 'Create', $this->_params
[0]);
664 $this->assertAPISuccess($result);
665 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
666 $result = $this->callAPISuccess($this->_entity
, 'Get', ['id' => $result['id']]);
667 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
669 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
670 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
671 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
672 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
673 $this->assertEquals($this->_params
[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__
);
677 * @param int $version
678 * @dataProvider versionThreeAndFour
680 public function testUpdateEvent($version) {
681 $this->_apiversion
= $version;
682 $result = $this->callAPISuccess('event', 'create', $this->_params
[1]);
685 'id' => $result['id'],
686 'max_participants' => 150,
688 $this->callAPISuccess('Event', 'Create', $params);
689 $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__
, __FILE__
);
690 $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
691 $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
692 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
696 * @param int $version
697 * @dataProvider versionThreeAndFour
699 public function testDeleteEmptyParams($version) {
700 $this->_apiversion
= $version;
701 $result = $this->callAPIFailure('Event', 'Delete', []);
705 * @param int $version
706 * @dataProvider versionThreeAndFour
708 public function testDelete($version) {
709 $this->_apiversion
= $version;
711 'id' => $this->_eventIds
[0],
713 $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__
, __FILE__
);
717 * Check event_id still supported for delete.
718 * @param int $version
719 * @dataProvider versionThreeAndFour
721 public function testDeleteWithEventId($version) {
722 $this->_apiversion
= $version;
724 'event_id' => $this->_eventIds
[0],
726 $result = $this->callAPISuccess('Event', 'Delete', $params);
727 $this->assertAPISuccess($result);
731 * Trying to delete an event with participants should return error.
732 * @param int $version
733 * @dataProvider versionThreeAndFour
735 public function testDeleteWithExistingParticipant($version) {
736 $this->_apiversion
= $version;
737 $contactID = $this->individualCreate();
738 $this->participantCreate(
740 'contactID' => $contactID,
741 'eventID' => $this->_eventIds
[0],
744 $this->callAPISuccess('Event', 'Delete', ['id' => $this->_eventIds
[0]]);
748 * @param int $version
749 * @dataProvider versionThreeAndFour
751 public function testDeleteWithWrongEventId($version) {
752 $this->_apiversion
= $version;
753 $params = ['event_id' => $this->_eventIds
[0]];
754 $result = $this->callAPISuccess('Event', 'Delete', $params);
755 // try to delete again - there's no such event anymore
756 $params = ['event_id' => $this->_eventIds
[0]];
757 $result = $this->callAPIFailure('Event', 'Delete', $params);
761 * Test civicrm_event_search with empty params.
762 * @param int $version
763 * @dataProvider versionThreeAndFour
765 public function testSearchEmptyParams($version) {
766 $this->_apiversion
= $version;
767 $this->callAPISuccess('event', 'create', $this->_params
[1]);
772 $result = $this->callAPISuccess('event', 'get', $getParams);
773 $this->assertEquals($result['count'], 3);
774 $res = $result['values'][0];
775 $this->assertArrayKeyExists('title', $res);
776 $this->assertEquals($res['event_type_id'], $this->_params
[1]['event_type_id']);
780 * Test civicrm_event_search. Success expected.
781 * @param int $version
782 * @dataProvider versionThreeAndFour
784 public function testSearch($version) {
785 $this->_apiversion
= $version;
787 'event_type_id' => 1,
790 'return.start_date' => 1,
792 $result = $this->callAPISuccess('event', 'get', $params);
794 $this->assertEquals($result['values'][$this->_eventIds
[0]]['id'], $this->_eventIds
[0]);
795 $this->assertEquals($result['values'][$this->_eventIds
[0]]['title'], 'Annual CiviCRM meet');
799 * Test civicrm_event_search.
803 * return.offset and return.max_results test (CRM-5266)
805 public function testSearchWithOffsetAndMaxResults() {
808 while ($maxEvents > 0) {
810 'title' => 'Test Event' . $maxEvents,
811 'event_type_id' => 2,
812 'start_date' => 20081021,
815 $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
819 'event_type_id' => 2,
822 'return.offset' => 2,
823 'return.max_results' => 2,
825 $result = $this->callAPISuccess('event', 'get', $params);
826 $this->assertAPISuccess($result);
827 $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__
);
831 * @param int $version
832 * @dataProvider versionThreeAndFour
834 public function testEventCreationPermissions($version) {
835 $this->_apiversion
= $version;
837 'event_type_id' => 1,
838 'start_date' => '2010-10-03',
839 'title' => 'le cake is a tie',
840 'check_permissions' => TRUE,
842 $config = CRM_Core_Config
::singleton();
843 $config->userPermissionClass
->permissions
= ['access CiviCRM'];
844 $result = $this->callAPIFailure('event', 'create', $params, 'failed');
846 $config->userPermissionClass
->permissions
= [
851 $result = $this->callAPISuccess('event', 'create', $params);
855 * @param int $version
856 * @dataProvider versionThreeAndFour
858 public function testgetfields($version) {
859 $this->_apiversion
= $version;
860 $description = "Demonstrate use of getfields to interrogate api.";
861 $params = ['action' => 'create'];
862 $result = $this->callAPISuccess('event', 'getfields', $params);
863 $this->assertEquals('is_active', $result['values']['is_active']['name']);
867 * Test api_action param also works.
869 public function testgetfieldsRest() {
870 $description = "Demonstrate use of getfields to interrogate api.";
871 $params = ['api_action' => 'create'];
872 $result = $this->callAPISuccess('event', 'getfields', $params);
873 $this->assertEquals(1, $result['values']['is_active']['api.default']);
877 * Skip api4 - output is different
879 public function testgetfieldsGet() {
880 $description = "Demonstrate use of getfields to interrogate api.";
881 $params = ['action' => 'get'];
882 $result = $this->callAPISuccess('event', 'getfields', $params);
883 $this->assertEquals('title', $result['values']['event_title']['name']);
887 * Skip api4 - output is different
889 public function testgetfieldsDelete() {
890 $description = "Demonstrate use of getfields to interrogate api.";
891 $params = ['action' => 'delete'];
892 $result = $this->callAPISuccess('event', 'getfields', $params);
893 $this->assertEquals(1, $result['values']['id']['api.required']);
897 * @param int $version
898 * @dataProvider versionThreeAndFour
900 public function testCreateFromTemplate($version) {
901 $this->_apiversion
= $version;
903 'summary' => 'Sign up now to learn the results of this unit test',
904 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
905 'event_type_id' => 1,
907 'end_date' => '2018-06-25 17:00:00',
908 'is_online_registration' => 1,
909 'registration_start_date' => '2017-06-25 17:00:00',
910 'registration_end_date' => '2018-06-25 17:00:00',
911 'max_participants' => 100,
912 'event_full_text' => 'Sorry! We are already full',
914 $templateResult = $this->callAPISuccess('Event', 'create', ['is_template' => 1, 'template_title' => 'Test tpl'] +
$templateParams);
915 $eventResult = $this->callAPISuccess('Event', 'create', [
916 'template_id' => $templateResult['id'],
918 'start_date' => '2018-06-25 16:00:00',
920 $eventResult = $this->callAPISuccess('Event', 'getsingle', ['id' => $eventResult['id']]);
921 foreach ($templateParams as $param => $value) {
922 $this->assertEquals($value, $eventResult[$param], print_r($eventResult, 1));