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() {
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() {
85 foreach ($this->eventIds
as $eventId) {
86 $this->eventDelete($eventId);
89 'civicrm_participant',
92 $this->quickCleanup($tablesToTruncate, TRUE);
96 * civicrm_event_get methods.
98 public function testGetEventById() {
100 'id' => $this->_events
[1]['id'],
102 $result = $this->callAPISuccess('event', 'get', $params);
103 $this->assertEquals($result['values'][$this->_eventIds
[1]]['event_title'], 'Annual CiviCRM meet 2');
107 * Test getLocationEvents() function invokes selectWhereClause() hook
109 public function testGetEventWithPermissionHook() {
110 $address = $this->callAPISuccess('address', 'create', [
111 'contact_id' => 'null',
112 'location_type_id' => 1,
113 'street_address' => '1234567',
116 'address_id' => $address['id'],
118 $result = $this->callAPISuccess('loc_block', 'create', $params);
120 'id' => $this->_events
[1]['id'],
121 'loc_block_id' => $result['id'],
123 $this->callAPISuccess('Event', 'create', $params);
124 $result = CRM_Event_BAO_Event
::getLocationEvents();
125 $this->assertEquals(1, count($result));
127 $this->hookClass
->setHook('civicrm_selectWhereClause', [$this, 'selectWhereClauseHook']);
128 $result = CRM_Event_BAO_Event
::getLocationEvents();
129 $this->assertEquals(0, count($result));
132 public function testGetEventByEventTitle() {
135 'event_title' => 'Annual CiviCRM meet',
136 'sequential' => TRUE,
139 $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__
, __FILE__
);
140 $this->assertEquals(1, $result['count']);
141 $this->assertEquals($result['values'][0]['id'], $this->_eventIds
[0]);
145 * @param int $version
146 * @dataProvider versionThreeAndFour
148 public function testGetEventByWrongTitle($version) {
149 $this->_apiversion
= $version;
151 'title' => 'No event with that title',
153 $result = $this->callAPISuccess('Event', 'Get', $params);
154 $this->assertEquals(0, $result['count']);
158 * Skip api4 - this api uses deprecated query syntax
160 public function testGetEventByIdSort() {
162 'return.sort' => 'id ASC',
163 'return.max_results' => 1,
165 $result = $this->callAPISuccess('Event', 'Get', $params);
166 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
174 $result = $this->callAPISuccess('Event', 'Get', $params);
175 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
176 $this->assertEquals(2, $result['id'], ' in line ' . __LINE__
);
183 $result = $this->callAPISuccess('Event', 'Get', $params);
184 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
189 * Getting the id back of an event.
190 * Does not work yet, bug in API
194 public function testGetIdOfEventByEventTitle() {
195 $params = array( 'title' => 'Annual CiviCRM meet',
199 $result = $this->callAPISuccess('Event', 'Get', $params);
204 * Test 'is.Current' option. Existing event is 'old' so only current should be returned
207 public function testGetIsCurrent() {
211 $currentEventParams = [
212 'start_date' => date('Y-m-d', strtotime('+ 1 day')),
213 'end_date' => date('Y-m-d', strtotime('+ 1 week')),
215 $currentEventParams = array_merge($this->_params
[1], $currentEventParams);
216 $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams);
217 $description = "Demonstrates use of is.Current option.";
218 $subfile = "IsCurrentOption";
219 $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
220 $allEvents = $this->callAPISuccess('Event', 'Get', []);
221 $this->callAPISuccess('Event', 'Delete', ['id' => $currentEvent['id']]);
222 $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__
);
223 $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__
);
224 $this->assertEquals($currentEvent['id'], $result['id'], '');
228 * There has been a schema change & the api needs to buffer developers from it
231 public function testGetPaymentProcessorId() {
232 $params = $this->_params
[0];
233 $params['payment_processor_id'] = 1;
234 $params['sequential'] = 1;
235 $result = $this->callAPISuccess('event', 'create', $params);
236 $this->assertEquals(1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility");
237 $result = $this->callAPISuccess('event', 'get', $params);
238 $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility");
242 * @param int $version
243 * @dataProvider versionThreeAndFour
245 public function testInvalidData($version) {
246 $this->_apiversion
= $version;
247 $params = $this->_params
[0];
248 $params['sequential'] = 1;
249 $params['loc_block_id'] = 100;
250 $result = $this->callAPIFailure('event', 'create', $params);
255 * Test 'is_full' option.
258 public function testGetSingleReturnIsFull() {
259 $contactID = $this->individualCreate();
261 'id' => $this->_eventIds
[0],
262 'max_participants' => 1,
264 $result = $this->callAPISuccess('Event', 'Create', $params);
267 'id' => $this->_eventIds
[0],
268 'return.is_full' => 1,
271 $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams);
272 $description = "Demonstrates use of return is_full .";
273 $subfile = "IsFullOption";
274 $this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
275 $this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
276 $participant = $this->callAPISuccess('Participant', 'create', [
277 'participant_status' => 1,
279 'contact_id' => $contactID,
280 'event_id' => $this->_eventIds
[0],
282 $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__
, __FILE__
, $description, $subfile);
283 $this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
284 $this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
286 $this->contactDelete($contactID);
290 * Legacy support for Contribution Type ID.
292 * We need to ensure this is supported as an alias for financial_type_id.
294 public function testCreateGetEventLegacyContributionTypeID() {
295 $contributionTypeArray = ['contribution_type_id' => 3];
296 if (isset($this->_params
[0]['financial_type_id'])) {
297 //in case someone edits $this->_params & invalidates this test :-)
298 unset($this->_params
[0]['financial_type_id']);
300 $result = $this->callAPISuccess('event', 'create', $this->_params
[0] +
$contributionTypeArray);
301 $getresult = $this->callAPISuccess('event', 'get', [] +
$contributionTypeArray);
302 $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
303 $this->assertEquals($result['id'], $getresult['id']);
304 $this->callAPISuccess('event', 'delete', ['id' => $result['id']]);
308 * Chaining get event and loc block.
309 * @param int $version
310 * @dataProvider versionThreeAndFour
312 public function testChainingGetLocBlock($version) {
313 $this->_apiversion
= $version;
314 // create a loc block and an event for that loc block.
315 $eventParams = $this->_params
[0];
316 $eventParams['loc_bloc_id'] = '$value.id';
319 'street_address' => 'Kipdorp 24',
320 'postal_code' => '2000',
321 'city' => 'Antwerpen',
322 'country_id' => '1020',
323 'location_type_id' => '1',
325 'api.Event.create' => $eventParams,
328 $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams);
329 $locBlockId = $createResult['id'];
330 $eventId = $createResult['values'][0]['api.Event.create']['id'];
332 // request the event with its loc block:
333 $check = $this->callAPISuccess($this->_entity
, 'getsingle', [
335 'api.LocBlock.get' => ['id' => '$value.loc_block_id'],
340 $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__
);
341 $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__
);
342 $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__
);
345 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $eventId]);
349 * Chaining get event and non existing loc block.
351 * Even if there is no loc block, at least the event should be returned.
352 * http://forum.civicrm.org/index.php/topic,36113.0.html
354 public function testChainingGetNonExistingLocBlock() {
355 $params = $this->_params
[0];
356 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
358 $check = $this->callAPISuccess($this->_entity
, 'get', [
359 'id' => $result['id'],
360 // this chaining request should not break things:
361 'api.LocBlock.get' => ['id' => '$value.loc_block_id'],
363 $this->assertEquals($result['id'], $check['id']);
365 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
369 * Check with complete array + custom field.
371 * Note that the test is written on purpose without any
372 * variables specific to participant so it can be replicated into other entities
373 * and / or moved to the automated test suite.
374 * @param int $version
375 * @dataProvider versionThreeAndFour
377 public function testCreateWithCustom($version) {
378 $this->_apiversion
= $version;
379 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
381 $params = $this->_params
[0];
382 $params['custom_' . $ids['custom_field_id']] = "custom string";
384 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
386 $check = $this->callAPISuccess($this->_entity
, 'get', [
387 'return.custom_' . $ids['custom_field_id'] => 1,
388 'id' => $result['id'],
390 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
392 $this->customFieldDelete($ids['custom_field_id']);
393 $this->customGroupDelete($ids['custom_group_id']);
394 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
398 * Check searching on custom fields.
400 * https://issues.civicrm.org/jira/browse/CRM-16036
401 * @param int $version
402 * @dataProvider versionThreeAndFour
404 public function testSearchCustomField($version) {
405 $this->_apiversion
= $version;
406 // create custom group with custom field on event
407 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
409 // Search for events having CRM-16036 as the value for this custom
410 // field. This should not return anything.
411 $check = $this->callAPISuccess($this->_entity
, 'get', [
412 'custom_' . $ids['custom_field_id'] => 'CRM-16036',
415 $this->assertEquals(0, $check['count']);
417 $this->customFieldDelete($ids['custom_field_id']);
418 $this->customGroupDelete($ids['custom_group_id']);
422 * Check searching on custom fields with IS NULL.
424 * https://issues.civicrm.org/jira/browse/CRM-20740
425 * @param int $version
426 * @dataProvider versionThreeAndFour
428 public function testSearchCustomFieldIsNull($version) {
429 $this->_apiversion
= $version;
430 // create custom group with custom field on event
431 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
433 // Search for events having NULL as the value for this custom
434 // field. This should return all events created in setUp.
435 $check = $this->callAPISuccess($this->_entity
, 'get', [
436 'custom_' . $ids['custom_field_id'] => ['IS NULL' => 1],
439 $this->assertGreaterThan(0, $check['count']);
441 $this->customFieldDelete($ids['custom_field_id']);
442 $this->customGroupDelete($ids['custom_group_id']);
446 * Test searching on custom fields returning a contact reference.
448 * https://issues.civicrm.org/jira/browse/CRM-16036
451 public function testEventGetCustomContactRefFieldCRM16036() {
452 // Create some contact.
453 $test_contact_name = 'Contact, Test';
454 $contact_save_result = $this->callAPISuccess('contact', 'create', [
455 'sort_name' => $test_contact_name,
456 'contact_type' => 'Individual',
457 'display_name' => $test_contact_name,
459 $contact_id = $contact_save_result['id'];
461 // I have no clue what this $subfile is about. I just copied it from another
463 $subfile = 'ContactRefCustomField';
464 $description = "Demonstrates get with Contact Reference Custom Field.";
466 // Create a custom group, and add a custom contact reference field.
467 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
469 'custom_group_id' => $ids['custom_group_id'],
470 'name' => 'Worker_Lookup',
471 'label' => 'Worker Lookup',
472 'html_type' => 'Autocomplete-Select',
473 'data_type' => 'ContactReference',
475 'is_searchable' => 1,
478 $customField = $this->callAPISuccess('custom_field', 'create', $params);
480 // Create an event, and add the contact as custom value.
481 $params = $this->_params
;
482 $params['title'] = "My test event.";
483 $params['start_date'] = "2015-03-14";
484 // Just assume that an event type 1 exists.
485 $params['event_type_id'] = 1;
486 $params['custom_' . $customField['id']] = "$contact_id";
488 $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
490 // Retrieve the activity, search for the contact.
491 $result = $this->callAPIAndDocument($this->_entity
, 'get', [
492 'return.custom_' . $customField['id'] => 1,
493 'custom_' . $customField['id'] => $contact_id,
494 ], __FUNCTION__
, __FILE__
, $description, $subfile);
496 $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
497 $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__
);
498 // Not sure whether I should test for custom_X_1 and custom_X_1_id as well.
499 // (1 being the id of the record in the custom value table)
501 $this->customFieldDelete($ids['custom_field_id']);
502 $this->customGroupDelete($ids['custom_group_id']);
503 $this->callAPISuccess('contact', 'delete', [
505 'skip_undelete' => TRUE,
510 * Test searching on custom fields with less than or equal.
513 * @param int $version
514 * @dataProvider versionThreeAndFour
516 public function testEventGetCustomFieldLte($version) {
517 $this->_apiversion
= $version;
518 // create custom group with custom field on event
519 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
521 // Create an event, with a custom value.
522 $params = $this->_params
;
523 $params['title'] = "My test event.";
524 $params['start_date'] = "2015-03-14";
525 // Just assume that an event type 1 exists.
526 $params['event_type_id'] = 1;
527 $params['custom_' . $ids['custom_field_id']] = "AAAA";
529 $save_result = $this->callApiSuccess($this->_entity
, 'create', $params);
531 // Retrieve the activity, search for custom field < 'BBBB'
532 $get_result = $this->callAPISuccess($this->_entity
, 'get', [
533 'return.custom_' . $ids['custom_field_id'] => 1,
534 'custom_' . $ids['custom_field_id'] => ['<=' => 'BBBB'],
537 // Expect that we find the saved event.
538 $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
540 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $save_result['id']]);
544 * Test searching on custom fields with netsted call with id param.
546 * Search for an event on a custom field, and perform a chained call
547 * to retrieve it's (non-existing) loc block, using $value-substitution.
548 * This test just checks whether the event is found, because something
549 * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing
550 * CiviCRM to return 0 results.
551 * Of course, CRM-16168 should also be fixed for this test to pass.
553 public function testEventSearchCustomFieldWithChainedCall() {
554 // Create a custom group, and add a custom contact reference field.
555 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
556 $custom_field_id = $ids['custom_field_id'];
558 // Create an event with a custom value.
559 $params = $this->_params
;
560 $params['title'] = "My test event.";
561 $params['start_date'] = "2015-03-14";
562 // Just assume that an event type 1 exists.
563 $params['event_type_id'] = 1;
564 $params['custom_' . $custom_field_id] = "12345";
566 $this->callAPISuccess($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
568 // Retrieve the activity, and chain loc block using $value.
569 $result = $this->callAPISuccess($this->_entity
, 'get', [
570 'custom_' . $custom_field_id => "12345",
571 'api.LocBlock.get' => ["id" => '$value.loc_block_id'],
574 $this->assertEquals(1, $result['count']);
576 $this->customFieldDelete($ids['custom_field_id']);
577 $this->customGroupDelete($ids['custom_group_id']);
578 $this->callAPISuccess('event', 'delete', [
579 'id' => $result['id'],
580 'skip_undelete' => TRUE,
585 * Test that an event with a price set can be created.
588 public function testCreatePaidEvent() {
589 //@todo alter API so that an integer is converted to an array
590 $priceSetParams = ['price_set_id' => (array) 1, 'is_monetary' => 1];
591 $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params
[0], $priceSetParams));
592 $event = $this->callAPISuccess('Event', 'getsingle', ['id' => $result['id'], 'return' => 'price_set_id']);
593 $this->assertArrayKeyExists('price_set_id', $event);
597 * @param int $version
598 * @dataProvider versionThreeAndFour
600 public function testCreateEventEmptyParams($version) {
601 $this->_apiversion
= $version;
603 $result = $this->callAPIFailure('event', 'create', $params);
607 * @param int $version
608 * @dataProvider versionThreeAndFour
610 public function testCreateEventParamsWithoutTitle($version) {
611 $this->_apiversion
= $version;
612 unset($this->_params
['title']);
613 $result = $this->callAPIFailure('event', 'create', $this->_params
);
614 $this->assertAPIFailure($result);
618 * @param int $version
619 * @dataProvider versionThreeAndFour
621 public function testCreateEventParamsWithoutEventTypeId($version) {
622 $this->_apiversion
= $version;
623 unset($this->_params
['event_type_id']);
624 $result = $this->callAPIFailure('event', 'create', $this->_params
);
628 * @param int $version
629 * @dataProvider versionThreeAndFour
631 public function testCreateEventParamsWithoutStartDate($version) {
632 $this->_apiversion
= $version;
633 unset($this->_params
['start_date']);
634 $result = $this->callAPIFailure('event', 'create', $this->_params
, 'start_date');
638 * @param int $version
639 * @dataProvider versionThreeAndFour
641 public function testCreateEventSuccess($version) {
642 $this->_apiversion
= $version;
643 $result = $this->callAPIAndDocument('Event', 'Create', $this->_params
[0], __FUNCTION__
, __FILE__
);
644 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
645 $result = $this->callAPISuccess($this->_entity
, 'Get', ['id' => $result['id']]);
646 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
647 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set');
648 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set');
649 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set');
650 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set');
654 * Test that passing in Unique field names works.
655 * Skip api4 which doesn't use unique names
657 public function testCreateEventSuccessUniqueFieldNames() {
658 $this->_params
[0]['event_start_date'] = $this->_params
[0]['start_date'];
659 unset($this->_params
[1]['start_date']);
660 $this->_params
[0]['event_title'] = $this->_params
[0]['title'];
661 unset($this->_params
[0]['title']);
662 $result = $this->callAPISuccess('Event', 'Create', $this->_params
[0]);
663 $this->assertAPISuccess($result);
664 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
665 $result = $this->callAPISuccess($this->_entity
, 'Get', ['id' => $result['id']]);
666 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
668 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
669 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
670 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
671 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
672 $this->assertEquals($this->_params
[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__
);
676 * @param int $version
677 * @dataProvider versionThreeAndFour
679 public function testUpdateEvent($version) {
680 $this->_apiversion
= $version;
681 $result = $this->callAPISuccess('event', 'create', $this->_params
[1]);
684 'id' => $result['id'],
685 'max_participants' => 150,
687 $this->callAPISuccess('Event', 'Create', $params);
688 $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__
, __FILE__
);
689 $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
690 $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
691 $this->callAPISuccess($this->_entity
, 'Delete', ['id' => $result['id']]);
695 * @param int $version
696 * @dataProvider versionThreeAndFour
698 public function testDeleteEmptyParams($version) {
699 $this->_apiversion
= $version;
700 $result = $this->callAPIFailure('Event', 'Delete', []);
704 * @param int $version
705 * @dataProvider versionThreeAndFour
707 public function testDelete($version) {
708 $this->_apiversion
= $version;
710 'id' => $this->_eventIds
[0],
712 $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__
, __FILE__
);
716 * Check event_id still supported for delete.
717 * @param int $version
718 * @dataProvider versionThreeAndFour
720 public function testDeleteWithEventId($version) {
721 $this->_apiversion
= $version;
723 'event_id' => $this->_eventIds
[0],
725 $result = $this->callAPISuccess('Event', 'Delete', $params);
726 $this->assertAPISuccess($result);
730 * Trying to delete an event with participants should return error.
731 * @param int $version
732 * @dataProvider versionThreeAndFour
734 public function testDeleteWithExistingParticipant($version) {
735 $this->_apiversion
= $version;
736 $contactID = $this->individualCreate();
737 $this->participantCreate(
739 'contactID' => $contactID,
740 'eventID' => $this->_eventIds
[0],
743 $this->callAPISuccess('Event', 'Delete', ['id' => $this->_eventIds
[0]]);
747 * @param int $version
748 * @dataProvider versionThreeAndFour
750 public function testDeleteWithWrongEventId($version) {
751 $this->_apiversion
= $version;
752 $params = ['event_id' => $this->_eventIds
[0]];
753 $result = $this->callAPISuccess('Event', 'Delete', $params);
754 // try to delete again - there's no such event anymore
755 $params = ['event_id' => $this->_eventIds
[0]];
756 $result = $this->callAPIFailure('Event', 'Delete', $params);
760 * Test civicrm_event_search with empty params.
761 * @param int $version
762 * @dataProvider versionThreeAndFour
764 public function testSearchEmptyParams($version) {
765 $this->_apiversion
= $version;
766 $this->callAPISuccess('event', 'create', $this->_params
[1]);
771 $result = $this->callAPISuccess('event', 'get', $getParams);
772 $this->assertEquals($result['count'], 3);
773 $res = $result['values'][0];
774 $this->assertArrayKeyExists('title', $res);
775 $this->assertEquals($res['event_type_id'], $this->_params
[1]['event_type_id']);
779 * Test civicrm_event_search. Success expected.
780 * @param int $version
781 * @dataProvider versionThreeAndFour
783 public function testSearch($version) {
784 $this->_apiversion
= $version;
786 'event_type_id' => 1,
789 'return.start_date' => 1,
791 $result = $this->callAPISuccess('event', 'get', $params);
793 $this->assertEquals($result['values'][$this->_eventIds
[0]]['id'], $this->_eventIds
[0]);
794 $this->assertEquals($result['values'][$this->_eventIds
[0]]['title'], 'Annual CiviCRM meet');
798 * Test civicrm_event_search.
802 * return.offset and return.max_results test (CRM-5266)
804 public function testSearchWithOffsetAndMaxResults() {
807 while ($maxEvents > 0) {
809 'title' => 'Test Event' . $maxEvents,
810 'event_type_id' => 2,
811 'start_date' => 20081021,
814 $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
818 'event_type_id' => 2,
821 'return.offset' => 2,
822 'return.max_results' => 2,
824 $result = $this->callAPISuccess('event', 'get', $params);
825 $this->assertAPISuccess($result);
826 $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__
);
830 * @param int $version
831 * @dataProvider versionThreeAndFour
833 public function testEventCreationPermissions($version) {
834 $this->_apiversion
= $version;
836 'event_type_id' => 1,
837 'start_date' => '2010-10-03',
838 'title' => 'le cake is a tie',
839 'check_permissions' => TRUE,
841 $config = CRM_Core_Config
::singleton();
842 $config->userPermissionClass
->permissions
= ['access CiviCRM'];
843 $result = $this->callAPIFailure('event', 'create', $params, 'failed');
845 $config->userPermissionClass
->permissions
= [
850 $result = $this->callAPISuccess('event', 'create', $params);
854 * @param int $version
855 * @dataProvider versionThreeAndFour
857 public function testgetfields($version) {
858 $this->_apiversion
= $version;
859 $description = "Demonstrate use of getfields to interrogate api.";
860 $params = ['action' => 'create'];
861 $result = $this->callAPISuccess('event', 'getfields', $params);
862 $this->assertEquals('is_active', $result['values']['is_active']['name']);
866 * Test api_action param also works.
868 public function testgetfieldsRest() {
869 $description = "Demonstrate use of getfields to interrogate api.";
870 $params = ['api_action' => 'create'];
871 $result = $this->callAPISuccess('event', 'getfields', $params);
872 $this->assertEquals(1, $result['values']['is_active']['api.default']);
876 * Skip api4 - output is different
878 public function testgetfieldsGet() {
879 $description = "Demonstrate use of getfields to interrogate api.";
880 $params = ['action' => 'get'];
881 $result = $this->callAPISuccess('event', 'getfields', $params);
882 $this->assertEquals('title', $result['values']['event_title']['name']);
886 * Skip api4 - output is different
888 public function testgetfieldsDelete() {
889 $description = "Demonstrate use of getfields to interrogate api.";
890 $params = ['action' => 'delete'];
891 $result = $this->callAPISuccess('event', 'getfields', $params);
892 $this->assertEquals(1, $result['values']['id']['api.required']);
896 * @param int $version
897 * @dataProvider versionThreeAndFour
899 public function testCreateFromTemplate($version) {
900 $this->_apiversion
= $version;
902 'summary' => 'Sign up now to learn the results of this unit test',
903 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
904 'event_type_id' => 1,
906 'end_date' => '2018-06-25 17:00:00',
907 'is_online_registration' => 1,
908 'registration_start_date' => '2017-06-25 17:00:00',
909 'registration_end_date' => '2018-06-25 17:00:00',
910 'max_participants' => 100,
911 'event_full_text' => 'Sorry! We are already full',
913 $templateResult = $this->callAPISuccess('Event', 'create', ['is_template' => 1, 'template_title' => 'Test tpl'] +
$templateParams);
914 $eventResult = $this->callAPISuccess('Event', 'create', [
915 'template_id' => $templateResult['id'],
917 'start_date' => '2018-06-25 16:00:00',
919 $eventResult = $this->callAPISuccess('Event', 'getsingle', ['id' => $eventResult['id']]);
920 foreach ($templateParams as $param => $value) {
921 $this->assertEquals($value, $eventResult[$param], print_r($eventResult, 1));