3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * Class api_v3_EventTest
32 class api_v3_EventTest
extends CiviUnitTestCase
{
34 protected $_apiversion;
37 public function setUp() {
39 $this->_apiversion
= 3;
40 $this->_entity
= 'event';
41 $this->_params
= array(
43 'title' => 'Annual CiviCRM meet',
44 'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now',
45 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
48 'start_date' => 20081021,
49 'end_date' => 20081023,
50 'is_online_registration' => 1,
51 'registration_start_date' => 20080601,
52 'registration_end_date' => '2008-10-15',
53 'max_participants' => 100,
54 'event_full_text' => 'Sorry! We are already full',
57 'is_show_location' => 0,
60 'title' => 'Annual CiviCRM meet 2',
61 'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now',
62 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
65 'start_date' => 20101021,
66 'end_date' => 20101023,
67 'is_online_registration' => 1,
68 'registration_start_date' => 20100601,
69 'registration_end_date' => '2010-10-15',
70 'max_participants' => 100,
71 'event_full_text' => 'Sorry! We are already full',
74 'is_show_location' => 0,
80 'title' => 'Annual CiviCRM meet',
82 'start_date' => 20081021,
85 'title' => 'Annual CiviCRM meet 2',
87 'start_date' => 20101021,
91 $this->events
= array();
92 $this->eventIds
= array();
93 foreach ($params as $event) {
94 $result = $this->callAPISuccess('Event', 'Create', $event);
95 $this->_events
[] = $result;
96 $this->_eventIds
[] = $result['id'];
100 public function tearDown() {
101 foreach ($this->eventIds
as $eventId) {
102 $this->eventDelete($eventId);
104 $tablesToTruncate = array(
105 'civicrm_participant',
108 $this->quickCleanup($tablesToTruncate, TRUE);
112 * civicrm_event_get methods.
114 public function testGetEventById() {
116 'id' => $this->_events
[1]['id'],
118 $result = $this->callAPISuccess('event', 'get', $params);
119 $this->assertEquals($result['values'][$this->_eventIds
[1]]['event_title'], 'Annual CiviCRM meet 2');
123 * Test getLocationEvents() function invokes selectWhereClause() hook
125 public function testGetEventWithPermissionHook() {
126 $address = $this->callAPISuccess('address', 'create', array(
127 'contact_id' => 'null',
128 'location_type_id' => 1,
129 'street_address' => '1234567',
132 'address_id' => $address['id'],
134 $result = $this->callAPISuccess('loc_block', 'create', $params);
136 'id' => $this->_events
[1]['id'],
137 'loc_block_id' => $result['id'],
139 $this->callAPISuccess('Event', 'create', $params);
140 $result = CRM_Event_BAO_Event
::getLocationEvents();
141 $this->assertEquals(1, count($result));
143 $this->hookClass
->setHook('civicrm_selectWhereClause', array($this, 'selectWhereClauseHook'));
144 $result = CRM_Event_BAO_Event
::getLocationEvents();
145 $this->assertEquals(0, count($result));
148 public function testGetEventByEventTitle() {
151 'event_title' => 'Annual CiviCRM meet',
152 'sequential' => TRUE,
155 $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__
, __FILE__
);
156 $this->assertEquals(1, $result['count']);
157 $this->assertEquals($result['values'][0]['id'], $this->_eventIds
[0]);
160 public function testGetEventByWrongTitle() {
162 'title' => 'No event with that title',
164 $result = $this->callAPISuccess('Event', 'Get', $params);
165 $this->assertEquals(0, $result['count']);
168 public function testGetEventByIdSort() {
170 'return.sort' => 'id ASC',
171 'return.max_results' => 1,
173 $result = $this->callAPISuccess('Event', 'Get', $params);
174 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
182 $result = $this->callAPISuccess('Event', 'Get', $params);
183 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
184 $this->assertEquals(2, $result['id'], ' in line ' . __LINE__
);
191 $result = $this->callAPISuccess('Event', 'Get', $params);
192 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
196 * Getting the id back of an event.
197 * Does not work yet, bug in API
201 public function testGetIdOfEventByEventTitle() {
202 $params = array( 'title' => 'Annual CiviCRM meet',
206 $result = $this->callAPISuccess('Event', 'Get', $params);
212 * Test 'is.Current' option. Existing event is 'old' so only current should be returned
214 public function testGetIsCurrent() {
218 $currentEventParams = array(
219 'start_date' => date('Y-m-d', strtotime('+ 1 day')),
220 'end_date' => date('Y-m-d', strtotime('+ 1 week')),
222 $currentEventParams = array_merge($this->_params
[1], $currentEventParams);
223 $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams);
224 $description = "Demonstrates use of is.Current option.";
225 $subfile = "IsCurrentOption";
226 $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
227 $allEvents = $this->callAPISuccess('Event', 'Get', array());
228 $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id']));
229 $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__
);
230 $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__
);
231 $this->assertEquals($currentEvent['id'], $result['id'], '');
235 * There has been a schema change & the api needs to buffer developers from it
237 public function testGetPaymentProcessorId() {
238 $params = $this->_params
[0];
239 $params['payment_processor_id'] = 1;
240 $params['sequential'] = 1;
241 $result = $this->callAPISuccess('event', 'create', $params);
242 $this->assertEquals(1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility");
243 $result = $this->callAPISuccess('event', 'get', $params);
244 $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility");
247 public function testInvalidData() {
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.Current' option. Existing event is 'old' so only current should be returned
258 public function testGetSingleReturnIsFull() {
259 $contactID = $this->individualCreate();
261 'id' => $this->_eventIds
[0],
262 'max_participants' => 1,
264 $result = $this->callAPISuccess('Event', 'Create', $params);
266 $getEventParams = array(
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', array(
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 = array('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', array() +
$contributionTypeArray);
302 $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
303 $this->assertEquals($result['id'], $getresult['id']);
304 $this->callAPISuccess('event', 'delete', array('id' => $result['id']));
308 * Chaining get event and loc block.
310 public function testChainingGetLocBlock() {
311 // create a loc block and an event for that loc block.
312 $eventParams = $this->_params
[0];
313 $eventParams['loc_bloc_id'] = '$value.id';
314 $locBlockParams = array(
316 'street_address' => 'Kipdorp 24',
317 'postal_code' => '2000',
318 'city' => 'Antwerpen',
319 'country_id' => '1020',
320 'location_type_id' => '1',
322 'api.Event.create' => $eventParams,
325 $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams);
326 $locBlockId = $createResult['id'];
327 $eventId = $createResult['values'][0]['api.Event.create']['id'];
329 // request the event with its loc block:
330 $check = $this->callAPISuccess($this->_entity
, 'getsingle', array(
332 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
337 $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__
);
338 $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__
);
339 $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__
);
342 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $eventId));
346 * Chaining get event and non existing loc block.
348 * Even if there is no loc block, at least the event should be returned.
349 * http://forum.civicrm.org/index.php/topic,36113.0.html
351 public function testChainingGetNonExistingLocBlock() {
352 $params = $this->_params
[0];
353 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
355 $check = $this->callAPISuccess($this->_entity
, 'get', array(
356 'id' => $result['id'],
357 // this chaining request should not break things:
358 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
360 $this->assertEquals($result['id'], $check['id']);
362 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
366 * Check with complete array + custom field.
368 * Note that the test is written on purpose without any
369 * variables specific to participant so it can be replicated into other entities
370 * and / or moved to the automated test suite.
372 public function testCreateWithCustom() {
373 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
375 $params = $this->_params
[0];
376 $params['custom_' . $ids['custom_field_id']] = "custom string";
378 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
380 $check = $this->callAPISuccess($this->_entity
, 'get', array(
381 'return.custom_' . $ids['custom_field_id'] => 1,
382 'id' => $result['id'],
384 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
386 $this->customFieldDelete($ids['custom_field_id']);
387 $this->customGroupDelete($ids['custom_group_id']);
388 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
392 * Check searching on custom fields.
394 * https://issues.civicrm.org/jira/browse/CRM-16036
396 public function testSearchCustomField() {
397 // create custom group with custom field on event
398 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
400 // Search for events having CRM-16036 as the value for this custom
401 // field. This should not return anything.
402 $check = $this->callAPISuccess($this->_entity
, 'get', array(
403 'custom_' . $ids['custom_field_id'] => 'CRM-16036',
406 $this->assertEquals(0, $check['count']);
408 $this->customFieldDelete($ids['custom_field_id']);
409 $this->customGroupDelete($ids['custom_group_id']);
413 * Test searching on custom fields returning a contact reference.
415 * https://issues.civicrm.org/jira/browse/CRM-16036
417 public function testEventGetCustomContactRefFieldCRM16036() {
418 // Create some contact.
419 $test_contact_name = 'Contact, Test';
420 $contact_save_result = $this->callAPISuccess('contact', 'create', array(
421 'sort_name' => $test_contact_name,
422 'contact_type' => 'Individual',
423 'display_name' => $test_contact_name,
425 $contact_id = $contact_save_result['id'];
427 // I have no clue what this $subfile is about. I just copied it from another
429 $subfile = 'ContactRefCustomField';
430 $description = "Demonstrates get with Contact Reference Custom Field.";
432 // Create a custom group, and add a custom contact reference field.
433 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
435 'custom_group_id' => $ids['custom_group_id'],
436 'name' => 'Worker_Lookup',
437 'label' => 'Worker Lookup',
438 'html_type' => 'Autocomplete-Select',
439 'data_type' => 'ContactReference',
441 'is_searchable' => 1,
444 $customField = $this->callAPISuccess('custom_field', 'create', $params);
446 // Create an event, and add the contact as custom value.
447 $params = $this->_params
;
448 $params['title'] = "My test event.";
449 $params['start_date'] = "2015-03-14";
450 // Just assume that an event type 1 exists.
451 $params['event_type_id'] = 1;
452 $params['custom_' . $customField['id']] = "$contact_id";
454 $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
456 // Retrieve the activity, search for the contact.
457 $result = $this->callAPIAndDocument($this->_entity
, 'get', array(
458 'return.custom_' . $customField['id'] => 1,
459 'custom_' . $customField['id'] => $contact_id,
460 ), __FUNCTION__
, __FILE__
, $description, $subfile);
462 $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
463 $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__
);
464 // Not sure whether I should test for custom_X_1 and custom_X_1_id as well.
465 // (1 being the id of the record in the custom value table)
467 $this->customFieldDelete($ids['custom_field_id']);
468 $this->customGroupDelete($ids['custom_group_id']);
469 $this->callAPISuccess('contact', 'delete', array(
471 'skip_undelete' => TRUE,
476 * Test searching on custom fields with less than or equal.
480 public function testEventGetCustomFieldLte() {
481 // create custom group with custom field on event
482 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
484 // Create an event, with a custom value.
485 $params = $this->_params
;
486 $params['title'] = "My test event.";
487 $params['start_date'] = "2015-03-14";
488 // Just assume that an event type 1 exists.
489 $params['event_type_id'] = 1;
490 $params['custom_' . $ids['custom_field_id']] = "AAAA";
492 $save_result = $this->callApiSuccess($this->_entity
, 'create', $params);
494 // Retrieve the activity, search for custom field < 'BBBB'
495 $get_result = $this->callAPISuccess($this->_entity
, 'get', array(
496 'return.custom_' . $ids['custom_field_id'] => 1,
497 'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'),
500 // Expect that we find the saved event.
501 $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
503 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $save_result['id']));
507 * Test searching on custom fields with netsted call with id param.
509 * Search for an event on a custom field, and perform a chained call
510 * to retrieve it's (non-existing) loc block, using $value-substitution.
511 * This test just checks whether the event is found, because something
512 * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing
513 * CiviCRM to return 0 results.
514 * Of course, CRM-16168 should also be fixed for this test to pass.
516 public function testEventSearchCustomFieldWithChainedCall() {
517 // Create a custom group, and add a custom contact reference field.
518 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
519 $custom_field_id = $ids['custom_field_id'];
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_' . $custom_field_id] = "12345";
529 $this->callAPISuccess($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
531 // Retrieve the activity, and chain loc block using $value.
532 $result = $this->callAPISuccess($this->_entity
, 'get', array(
533 'custom_' . $custom_field_id => "12345",
534 'api.LocBlock.get' => array("id" => '$value.loc_block_id'),
537 $this->assertEquals(1, $result['count']);
539 $this->customFieldDelete($ids['custom_field_id']);
540 $this->customGroupDelete($ids['custom_group_id']);
541 $this->callAPISuccess('event', 'delete', array(
542 'id' => $result['id'],
543 'skip_undelete' => TRUE,
549 * Test that an event with a price set can be created.
551 public function testCreatePaidEvent() {
552 //@todo alter API so that an integer is converted to an array
553 $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1);
554 $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params
[0], $priceSetParams));
555 $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id'));
556 $this->assertArrayKeyExists('price_set_id', $event);
559 public function testCreateEventParamsNotArray() {
561 $result = $this->callAPIFailure('event', 'create', $params);
564 public function testCreateEventEmptyParams() {
566 $result = $this->callAPIFailure('event', 'create', $params);
569 public function testCreateEventParamsWithoutTitle() {
570 unset($this->_params
['title']);
571 $result = $this->callAPIFailure('event', 'create', $this->_params
);
572 $this->assertAPIFailure($result);
575 public function testCreateEventParamsWithoutEventTypeId() {
576 unset($this->_params
['event_type_id']);
577 $result = $this->callAPIFailure('event', 'create', $this->_params
);
580 public function testCreateEventParamsWithoutStartDate() {
581 unset($this->_params
['start_date']);
582 $result = $this->callAPIFailure('event', 'create', $this->_params
);
585 public function testCreateEventSuccess() {
586 $result = $this->callAPIAndDocument('Event', 'Create', $this->_params
[0], __FUNCTION__
, __FILE__
);
587 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
588 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
589 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
590 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set');
591 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set');
592 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set');
593 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set');
597 * Test that passing in Unique field names works.
599 public function testCreateEventSuccessUniqueFieldNames() {
600 $this->_params
[0]['event_start_date'] = $this->_params
[0]['start_date'];
601 unset($this->_params
[1]['start_date']);
602 $this->_params
[0]['event_title'] = $this->_params
[0]['title'];
603 unset($this->_params
[0]['title']);
604 $result = $this->callAPISuccess('Event', 'Create', $this->_params
[0]);
605 $this->assertAPISuccess($result);
606 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
607 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
608 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
610 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
611 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
612 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
613 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
614 $this->assertEquals($this->_params
[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__
);
617 public function testUpdateEvent() {
618 $result = $this->callAPISuccess('event', 'create', $this->_params
[1]);
621 'id' => $result['id'],
622 'max_participants' => 150,
624 $this->callAPISuccess('Event', 'Create', $params);
625 $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__
, __FILE__
);
626 $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
627 $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
628 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
632 public function testDeleteEmptyParams() {
633 $result = $this->callAPIFailure('Event', 'Delete', array());
636 public function testDelete() {
638 'id' => $this->_eventIds
[0],
640 $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__
, __FILE__
);
644 * Check event_id still supported for delete.
646 public function testDeleteWithEventId() {
648 'event_id' => $this->_eventIds
[0],
650 $result = $this->callAPISuccess('Event', 'Delete', $params);
651 $this->assertAPISuccess($result);
655 * Trying to delete an event with participants should return error.
657 public function testDeleteWithExistingParticipant() {
658 $contactID = $this->individualCreate();
659 $this->participantCreate(
661 'contactID' => $contactID,
662 'eventID' => $this->_eventIds
[0],
665 $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds
[0]));
668 public function testDeleteWithWrongEventId() {
669 $params = array('event_id' => $this->_eventIds
[0]);
670 $result = $this->callAPISuccess('Event', 'Delete', $params);
671 // try to delete again - there's no such event anymore
672 $params = array('event_id' => $this->_eventIds
[0]);
673 $result = $this->callAPIFailure('Event', 'Delete', $params);
677 * Test civicrm_event_search with wrong params type.
679 public function testSearchWrongParamsType() {
680 $params = 'a string';
681 $result = $this->callAPIFailure('event', 'get', $params);
685 * Test civicrm_event_search with empty params.
687 public function testSearchEmptyParams() {
688 $this->callAPISuccess('event', 'create', $this->_params
[1]);
693 $result = $this->callAPISuccess('event', 'get', $getParams);
694 $this->assertEquals($result['count'], 3);
695 $res = $result['values'][0];
696 $this->assertArrayKeyExists('title', $res);
697 $this->assertEquals($res['event_type_id'], $this->_params
[1]['event_type_id']);
701 * Test civicrm_event_search. Success expected.
703 public function testSearch() {
705 'event_type_id' => 1,
708 'return.start_date' => 1,
710 $result = $this->callAPISuccess('event', 'get', $params);
712 $this->assertEquals($result['values'][$this->_eventIds
[0]]['id'], $this->_eventIds
[0]);
713 $this->assertEquals($result['values'][$this->_eventIds
[0]]['title'], 'Annual CiviCRM meet');
717 * Test civicrm_event_search.
721 * return.offset and return.max_results test (CRM-5266)
723 public function testSearchWithOffsetAndMaxResults() {
726 while ($maxEvents > 0) {
728 'title' => 'Test Event' . $maxEvents,
729 'event_type_id' => 2,
730 'start_date' => 20081021,
733 $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
737 'event_type_id' => 2,
740 'return.offset' => 2,
741 'return.max_results' => 2,
743 $result = $this->callAPISuccess('event', 'get', $params);
744 $this->assertAPISuccess($result);
745 $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__
);
748 public function testEventCreationPermissions() {
750 'event_type_id' => 1,
751 'start_date' => '2010-10-03',
752 'title' => 'le cake is a tie',
753 'check_permissions' => TRUE,
755 $config = &CRM_Core_Config
::singleton();
756 $config->userPermissionClass
->permissions
= array('access CiviCRM');
757 $result = $this->callAPIFailure('event', 'create', $params);
758 $this->assertEquals('API permission check failed for Event/create call; insufficient permission: require access CiviCRM and access CiviEvent and edit all events', $result['error_message'], 'lacking permissions should not be enough to create an event');
760 $config->userPermissionClass
->permissions
= array(
765 $result = $this->callAPISuccess('event', 'create', $params);
768 public function testgetfields() {
769 $description = "Demonstrate use of getfields to interrogate api.";
770 $params = array('action' => 'create');
771 $result = $this->callAPISuccess('event', 'getfields', $params);
772 $this->assertEquals(1, $result['values']['is_active']['api.default']);
776 * Test api_action param also works.
778 public function testgetfieldsRest() {
779 $description = "Demonstrate use of getfields to interrogate api.";
780 $params = array('api_action' => 'create');
781 $result = $this->callAPISuccess('event', 'getfields', $params);
782 $this->assertEquals(1, $result['values']['is_active']['api.default']);
785 public function testgetfieldsGet() {
786 $description = "Demonstrate use of getfields to interrogate api.";
787 $params = array('action' => 'get');
788 $result = $this->callAPISuccess('event', 'getfields', $params);
789 $this->assertEquals('title', $result['values']['event_title']['name']);
792 public function testgetfieldsDelete() {
793 $description = "Demonstrate use of getfields to interrogate api.";
794 $params = array('action' => 'delete');
795 $result = $this->callAPISuccess('event', 'getfields', $params);
796 $this->assertEquals(1, $result['values']['id']['api.required']);
799 public function testCreateFromTemplate() {
800 $templateParams = array(
801 'summary' => 'Sign up now to learn the results of this unit test',
802 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
803 'event_type_id' => 1,
805 'end_date' => '2018-06-25 17:00:00',
806 'is_online_registration' => 1,
807 'registration_start_date' => '2017-06-25 17:00:00',
808 'registration_end_date' => '2018-06-25 17:00:00',
809 'max_participants' => 100,
810 'event_full_text' => 'Sorry! We are already full',
812 $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') +
$templateParams);
813 $eventResult = $this->callAPISuccess('Event', 'create', array(
814 'template_id' => $templateResult['id'],
816 'start_date' => '2018-06-25 16:00:00',
818 $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
819 foreach ($templateParams as $param => $value) {
820 $this->assertEquals($value, $eventResult[$param]);