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');
122 public function testGetEventByEventTitle() {
125 'event_title' => 'Annual CiviCRM meet',
126 'sequential' => TRUE,
129 $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__
, __FILE__
);
130 $this->assertEquals(1, $result['count']);
131 $this->assertEquals($result['values'][0]['id'], $this->_eventIds
[0]);
134 public function testGetEventByWrongTitle() {
136 'title' => 'No event with that title',
138 $result = $this->callAPISuccess('Event', 'Get', $params);
139 $this->assertEquals(0, $result['count']);
142 public function testGetEventByIdSort() {
144 'return.sort' => 'id ASC',
145 'return.max_results' => 1,
147 $result = $this->callAPISuccess('Event', 'Get', $params);
148 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
156 $result = $this->callAPISuccess('Event', 'Get', $params);
157 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
158 $this->assertEquals(2, $result['id'], ' in line ' . __LINE__
);
165 $result = $this->callAPISuccess('Event', 'Get', $params);
166 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
170 * Getting the id back of an event.
171 * Does not work yet, bug in API
175 public function testGetIdOfEventByEventTitle() {
176 $params = array( 'title' => 'Annual CiviCRM meet',
180 $result = $this->callAPISuccess('Event', 'Get', $params);
186 * Test 'is.Current' option. Existing event is 'old' so only current should be returned
188 public function testGetIsCurrent() {
192 $currentEventParams = array(
193 'start_date' => date('Y-m-d', strtotime('+ 1 day')),
194 'end_date' => date('Y-m-d', strtotime('+ 1 week')),
196 $currentEventParams = array_merge($this->_params
[1], $currentEventParams);
197 $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams);
198 $description = "Demonstrates use of is.Current option.";
199 $subfile = "IsCurrentOption";
200 $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
201 $allEvents = $this->callAPISuccess('Event', 'Get', array());
202 $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id']));
203 $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__
);
204 $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__
);
205 $this->assertEquals($currentEvent['id'], $result['id'], '');
209 * There has been a schema change & the api needs to buffer developers from it
211 public function testGetPaymentProcessorId() {
212 $params = $this->_params
[0];
213 $params['payment_processor_id'] = 1;
214 $params['sequential'] = 1;
215 $result = $this->callAPISuccess('event', 'create', $params);
216 $this->assertEquals(1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility");
217 $result = $this->callAPISuccess('event', 'get', $params);
218 $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility");
221 public function testInvalidData() {
222 $params = $this->_params
[0];
223 $params['sequential'] = 1;
224 $params['loc_block_id'] = 100;
225 $result = $this->callAPIFailure('event', 'create', $params);
230 * Test 'is.Current' option. Existing event is 'old' so only current should be returned
232 public function testGetSingleReturnIsFull() {
233 $contactID = $this->individualCreate();
235 'id' => $this->_eventIds
[0],
236 'max_participants' => 1,
238 $result = $this->callAPISuccess('Event', 'Create', $params);
240 $getEventParams = array(
241 'id' => $this->_eventIds
[0],
242 'return.is_full' => 1,
245 $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams);
246 $description = "Demonstrates use of return is_full .";
247 $subfile = "IsFullOption";
248 $this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
249 $this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
250 $participant = $this->callAPISuccess('Participant', 'create', array(
251 'participant_status' => 1,
253 'contact_id' => $contactID,
254 'event_id' => $this->_eventIds
[0],
256 $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__
, __FILE__
, $description, $subfile);
257 $this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
258 $this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
260 $this->contactDelete($contactID);
264 * Legacy support for Contribution Type ID.
266 * We need to ensure this is supported as an alias for financial_type_id.
268 public function testCreateGetEventLegacyContributionTypeID() {
269 $contributionTypeArray = array('contribution_type_id' => 3);
270 if (isset($this->_params
[0]['financial_type_id'])) {
271 //in case someone edits $this->_params & invalidates this test :-)
272 unset($this->_params
[0]['financial_type_id']);
274 $result = $this->callAPISuccess('event', 'create', $this->_params
[0] +
$contributionTypeArray);
275 $getresult = $this->callAPISuccess('event', 'get', array() +
$contributionTypeArray);
276 $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
277 $this->assertEquals($result['id'], $getresult['id']);
278 $this->callAPISuccess('event', 'delete', array('id' => $result['id']));
282 * Chaining get event and loc block.
284 public function testChainingGetLocBlock() {
285 // create a loc block and an event for that loc block.
286 $eventParams = $this->_params
[0];
287 $eventParams['loc_bloc_id'] = '$value.id';
288 $locBlockParams = array(
290 'street_address' => 'Kipdorp 24',
291 'postal_code' => '2000',
292 'city' => 'Antwerpen',
293 'country_id' => '1020',
294 'location_type_id' => '1',
296 'api.Event.create' => $eventParams,
299 $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams);
300 $locBlockId = $createResult['id'];
301 $eventId = $createResult['values'][0]['api.Event.create']['id'];
303 // request the event with its loc block:
304 $check = $this->callAPISuccess($this->_entity
, 'getsingle', array(
306 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
311 $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__
);
312 $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__
);
313 $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__
);
316 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $eventId));
320 * Chaining get event and non existing loc block.
322 * Even if there is no loc block, at least the event should be returned.
323 * http://forum.civicrm.org/index.php/topic,36113.0.html
325 public function testChainingGetNonExistingLocBlock() {
326 $params = $this->_params
[0];
327 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
329 $check = $this->callAPISuccess($this->_entity
, 'get', array(
330 'id' => $result['id'],
331 // this chaining request should not break things:
332 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
334 $this->assertEquals($result['id'], $check['id']);
336 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
340 * Check with complete array + custom field.
342 * Note that the test is written on purpose without any
343 * variables specific to participant so it can be replicated into other entities
344 * and / or moved to the automated test suite.
346 public function testCreateWithCustom() {
347 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
349 $params = $this->_params
[0];
350 $params['custom_' . $ids['custom_field_id']] = "custom string";
352 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
354 $check = $this->callAPISuccess($this->_entity
, 'get', array(
355 'return.custom_' . $ids['custom_field_id'] => 1,
356 'id' => $result['id'],
358 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
360 $this->customFieldDelete($ids['custom_field_id']);
361 $this->customGroupDelete($ids['custom_group_id']);
362 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
366 * Check searching on custom fields.
368 * https://issues.civicrm.org/jira/browse/CRM-16036
370 public function testSearchCustomField() {
371 // create custom group with custom field on event
372 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
374 // Search for events having CRM-16036 as the value for this custom
375 // field. This should not return anything.
376 $check = $this->callAPISuccess($this->_entity
, 'get', array(
377 'custom_' . $ids['custom_field_id'] => 'CRM-16036',
380 $this->assertEquals(0, $check['count']);
382 $this->customFieldDelete($ids['custom_field_id']);
383 $this->customGroupDelete($ids['custom_group_id']);
387 * Test searching on custom fields returning a contact reference.
389 * https://issues.civicrm.org/jira/browse/CRM-16036
391 public function testEventGetCustomContactRefFieldCRM16036() {
392 // Create some contact.
393 $test_contact_name = 'Contact, Test';
394 $contact_save_result = $this->callAPISuccess('contact', 'create', array(
395 'sort_name' => $test_contact_name,
396 'contact_type' => 'Individual',
397 'display_name' => $test_contact_name,
399 $contact_id = $contact_save_result['id'];
401 // I have no clue what this $subfile is about. I just copied it from another
403 $subfile = 'ContactRefCustomField';
404 $description = "Demonstrates get with Contact Reference Custom Field.";
406 // Create a custom group, and add a custom contact reference field.
407 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
409 'custom_group_id' => $ids['custom_group_id'],
410 'name' => 'Worker_Lookup',
411 'label' => 'Worker Lookup',
412 'html_type' => 'Autocomplete-Select',
413 'data_type' => 'ContactReference',
415 'is_searchable' => 1,
418 $customField = $this->callAPISuccess('custom_field', 'create', $params);
420 // Create an event, and add the contact as custom value.
421 $params = $this->_params
;
422 $params['title'] = "My test event.";
423 $params['start_date'] = "2015-03-14";
424 // Just assume that an event type 1 exists.
425 $params['event_type_id'] = 1;
426 $params['custom_' . $customField['id']] = "$contact_id";
428 $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
430 // Retrieve the activity, search for the contact.
431 $result = $this->callAPIAndDocument($this->_entity
, 'get', array(
432 'return.custom_' . $customField['id'] => 1,
433 'custom_' . $customField['id'] => $contact_id,
434 ), __FUNCTION__
, __FILE__
, $description, $subfile);
436 $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
437 $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__
);
438 // Not sure whether I should test for custom_X_1 and custom_X_1_id as well.
439 // (1 being the id of the record in the custom value table)
441 $this->customFieldDelete($ids['custom_field_id']);
442 $this->customGroupDelete($ids['custom_group_id']);
443 $this->callAPISuccess('contact', 'delete', array(
445 'skip_undelete' => TRUE,
450 * Test searching on custom fields with less than or equal.
454 public function testEventGetCustomFieldLte() {
455 // create custom group with custom field on event
456 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
458 // Create an event, with a custom value.
459 $params = $this->_params
;
460 $params['title'] = "My test event.";
461 $params['start_date'] = "2015-03-14";
462 // Just assume that an event type 1 exists.
463 $params['event_type_id'] = 1;
464 $params['custom_' . $ids['custom_field_id']] = "AAAA";
466 $save_result = $this->callApiSuccess($this->_entity
, 'create', $params);
468 // Retrieve the activity, search for custom field < 'BBBB'
469 $get_result = $this->callAPISuccess($this->_entity
, 'get', array(
470 'return.custom_' . $ids['custom_field_id'] => 1,
471 'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'),
474 // Expect that we find the saved event.
475 $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
477 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $save_result['id']));
481 * Test searching on custom fields with netsted call with id param.
483 * Search for an event on a custom field, and perform a chained call
484 * to retrieve it's (non-existing) loc block, using $value-substitution.
485 * This test just checks whether the event is found, because something
486 * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing
487 * CiviCRM to return 0 results.
488 * Of course, CRM-16168 should also be fixed for this test to pass.
490 public function testEventSearchCustomFieldWithChainedCall() {
491 // Create a custom group, and add a custom contact reference field.
492 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
493 $custom_field_id = $ids['custom_field_id'];
495 // Create an event with a custom value.
496 $params = $this->_params
;
497 $params['title'] = "My test event.";
498 $params['start_date'] = "2015-03-14";
499 // Just assume that an event type 1 exists.
500 $params['event_type_id'] = 1;
501 $params['custom_' . $custom_field_id] = "12345";
503 $this->callAPISuccess($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
505 // Retrieve the activity, and chain loc block using $value.
506 $result = $this->callAPISuccess($this->_entity
, 'get', array(
507 'custom_' . $custom_field_id => "12345",
508 'api.LocBlock.get' => array("id" => '$value.loc_block_id'),
511 $this->assertEquals(1, $result['count']);
513 $this->customFieldDelete($ids['custom_field_id']);
514 $this->customGroupDelete($ids['custom_group_id']);
515 $this->callAPISuccess('event', 'delete', array(
516 'id' => $result['id'],
517 'skip_undelete' => TRUE,
523 * Test that an event with a price set can be created.
525 public function testCreatePaidEvent() {
526 //@todo alter API so that an integer is converted to an array
527 $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1);
528 $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params
[0], $priceSetParams));
529 $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id'));
530 $this->assertArrayKeyExists('price_set_id', $event);
533 public function testCreateEventParamsNotArray() {
535 $result = $this->callAPIFailure('event', 'create', $params);
538 public function testCreateEventEmptyParams() {
540 $result = $this->callAPIFailure('event', 'create', $params);
543 public function testCreateEventParamsWithoutTitle() {
544 unset($this->_params
['title']);
545 $result = $this->callAPIFailure('event', 'create', $this->_params
);
546 $this->assertAPIFailure($result);
549 public function testCreateEventParamsWithoutEventTypeId() {
550 unset($this->_params
['event_type_id']);
551 $result = $this->callAPIFailure('event', 'create', $this->_params
);
554 public function testCreateEventParamsWithoutStartDate() {
555 unset($this->_params
['start_date']);
556 $result = $this->callAPIFailure('event', 'create', $this->_params
);
559 public function testCreateEventSuccess() {
560 $result = $this->callAPIAndDocument('Event', 'Create', $this->_params
[0], __FUNCTION__
, __FILE__
);
561 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
562 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
563 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
564 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set');
565 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set');
566 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set');
567 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set');
571 * Test that passing in Unique field names works.
573 public function testCreateEventSuccessUniqueFieldNames() {
574 $this->_params
[0]['event_start_date'] = $this->_params
[0]['start_date'];
575 unset($this->_params
[1]['start_date']);
576 $this->_params
[0]['event_title'] = $this->_params
[0]['title'];
577 unset($this->_params
[0]['title']);
578 $result = $this->callAPISuccess('Event', 'Create', $this->_params
[0]);
579 $this->assertAPISuccess($result);
580 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
581 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
582 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
584 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
585 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
586 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
587 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
588 $this->assertEquals($this->_params
[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__
);
591 public function testUpdateEvent() {
592 $result = $this->callAPISuccess('event', 'create', $this->_params
[1]);
595 'id' => $result['id'],
596 'max_participants' => 150,
598 $this->callAPISuccess('Event', 'Create', $params);
599 $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__
, __FILE__
);
600 $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
601 $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
602 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
606 public function testDeleteEmptyParams() {
607 $result = $this->callAPIFailure('Event', 'Delete', array());
610 public function testDelete() {
612 'id' => $this->_eventIds
[0],
614 $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__
, __FILE__
);
618 * Check event_id still supported for delete.
620 public function testDeleteWithEventId() {
622 'event_id' => $this->_eventIds
[0],
624 $result = $this->callAPISuccess('Event', 'Delete', $params);
625 $this->assertAPISuccess($result);
629 * Trying to delete an event with participants should return error.
631 public function testDeleteWithExistingParticipant() {
632 $contactID = $this->individualCreate();
633 $this->participantCreate(
635 'contactID' => $contactID,
636 'eventID' => $this->_eventIds
[0],
639 $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds
[0]));
642 public function testDeleteWithWrongEventId() {
643 $params = array('event_id' => $this->_eventIds
[0]);
644 $result = $this->callAPISuccess('Event', 'Delete', $params);
645 // try to delete again - there's no such event anymore
646 $params = array('event_id' => $this->_eventIds
[0]);
647 $result = $this->callAPIFailure('Event', 'Delete', $params);
651 * Test civicrm_event_search with wrong params type.
653 public function testSearchWrongParamsType() {
654 $params = 'a string';
655 $result = $this->callAPIFailure('event', 'get', $params);
659 * Test civicrm_event_search with empty params.
661 public function testSearchEmptyParams() {
662 $this->callAPISuccess('event', 'create', $this->_params
[1]);
667 $result = $this->callAPISuccess('event', 'get', $getParams);
668 $this->assertEquals($result['count'], 3);
669 $res = $result['values'][0];
670 $this->assertArrayKeyExists('title', $res);
671 $this->assertEquals($res['event_type_id'], $this->_params
[1]['event_type_id']);
675 * Test civicrm_event_search. Success expected.
677 public function testSearch() {
679 'event_type_id' => 1,
682 'return.start_date' => 1,
684 $result = $this->callAPISuccess('event', 'get', $params);
686 $this->assertEquals($result['values'][$this->_eventIds
[0]]['id'], $this->_eventIds
[0]);
687 $this->assertEquals($result['values'][$this->_eventIds
[0]]['title'], 'Annual CiviCRM meet');
691 * Test civicrm_event_search.
695 * return.offset and return.max_results test (CRM-5266)
697 public function testSearchWithOffsetAndMaxResults() {
700 while ($maxEvents > 0) {
702 'title' => 'Test Event' . $maxEvents,
703 'event_type_id' => 2,
704 'start_date' => 20081021,
707 $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
711 'event_type_id' => 2,
714 'return.offset' => 2,
715 'return.max_results' => 2,
717 $result = $this->callAPISuccess('event', 'get', $params);
718 $this->assertAPISuccess($result);
719 $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__
);
722 public function testEventCreationPermissions() {
724 'event_type_id' => 1,
725 'start_date' => '2010-10-03',
726 'title' => 'le cake is a tie',
727 'check_permissions' => TRUE,
729 $config = &CRM_Core_Config
::singleton();
730 $config->userPermissionClass
->permissions
= array('access CiviCRM');
731 $result = $this->callAPIFailure('event', 'create', $params);
732 $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');
734 $config->userPermissionClass
->permissions
= array(
739 $result = $this->callAPISuccess('event', 'create', $params);
742 public function testgetfields() {
743 $description = "Demonstrate use of getfields to interrogate api.";
744 $params = array('action' => 'create');
745 $result = $this->callAPISuccess('event', 'getfields', $params);
746 $this->assertEquals(1, $result['values']['is_active']['api.default']);
750 * Test api_action param also works.
752 public function testgetfieldsRest() {
753 $description = "Demonstrate use of getfields to interrogate api.";
754 $params = array('api_action' => 'create');
755 $result = $this->callAPISuccess('event', 'getfields', $params);
756 $this->assertEquals(1, $result['values']['is_active']['api.default']);
759 public function testgetfieldsGet() {
760 $description = "Demonstrate use of getfields to interrogate api.";
761 $params = array('action' => 'get');
762 $result = $this->callAPISuccess('event', 'getfields', $params);
763 $this->assertEquals('title', $result['values']['event_title']['name']);
766 public function testgetfieldsDelete() {
767 $description = "Demonstrate use of getfields to interrogate api.";
768 $params = array('action' => 'delete');
769 $result = $this->callAPISuccess('event', 'getfields', $params);
770 $this->assertEquals(1, $result['values']['id']['api.required']);
773 public function testCreateFromTemplate() {
774 $templateParams = array(
775 'summary' => 'Sign up now to learn the results of this unit test',
776 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
777 'event_type_id' => 1,
779 'end_date' => '2018-06-25 17:00:00',
780 'is_online_registration' => 1,
781 'registration_start_date' => '2017-06-25 17:00:00',
782 'registration_end_date' => '2018-06-25 17:00:00',
783 'max_participants' => 100,
784 'event_full_text' => 'Sorry! We are already full',
786 $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') +
$templateParams);
787 $eventResult = $this->callAPISuccess('Event', 'create', array(
788 'template_id' => $templateResult['id'],
790 'start_date' => '2018-06-25 16:00:00',
792 $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
793 foreach ($templateParams as $param => $value) {
794 $this->assertEquals($value, $eventResult[$param]);