3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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->callAPIAndDocument('LocBlock', 'create', $locBlockParams, __FUNCTION__
, __FILE__
);
300 $locBlockId = $createResult['id'];
301 $addressId = $createResult['values'][0]['address_id'];
302 $eventId = $createResult['values'][0]['api.Event.create']['id'];
304 // request the event with its loc block:
305 $check = $this->callAPISuccess($this->_entity
, 'getsingle', array(
307 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
312 $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__
);
313 $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__
);
314 $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__
);
317 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $eventId));
321 * Chaining get event and non existing loc block.
323 * Even if there is no loc block, at least the event should be returned.
324 * http://forum.civicrm.org/index.php/topic,36113.0.html
326 public function testChainingGetNonExistingLocBlock() {
327 $params = $this->_params
[0];
328 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
330 $check = $this->callAPISuccess($this->_entity
, 'get', array(
331 'id' => $result['id'],
332 // this chaining request should not break things:
333 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
335 $this->assertEquals($result['id'], $check['id']);
337 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
341 * Check with complete array + custom field.
343 * Note that the test is written on purpose without any
344 * variables specific to participant so it can be replicated into other entities
345 * and / or moved to the automated test suite.
347 public function testCreateWithCustom() {
348 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
350 $params = $this->_params
[0];
351 $params['custom_' . $ids['custom_field_id']] = "custom string";
353 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
355 $check = $this->callAPISuccess($this->_entity
, 'get', array(
356 'return.custom_' . $ids['custom_field_id'] => 1,
357 'id' => $result['id'],
359 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
361 $this->customFieldDelete($ids['custom_field_id']);
362 $this->customGroupDelete($ids['custom_group_id']);
363 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
367 * Check searching on custom fields.
369 * https://issues.civicrm.org/jira/browse/CRM-16036
371 public function testSearchCustomField() {
372 // create custom group with custom field on event
373 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
375 // Search for events having CRM-16036 as the value for this custom
376 // field. This should not return anything.
377 $check = $this->callAPISuccess($this->_entity
, 'get', array(
378 'custom_' . $ids['custom_field_id'] => 'CRM-16036',
381 $this->assertEquals(0, $check['count']);
383 $this->customFieldDelete($ids['custom_field_id']);
384 $this->customGroupDelete($ids['custom_group_id']);
388 * Test searching on custom fields returning a contact reference.
390 * https://issues.civicrm.org/jira/browse/CRM-16036
392 public function testEventGetCustomContactRefFieldCRM16036() {
393 // Create some contact.
394 $test_contact_name = 'Contact, Test';
395 $contact_save_result = $this->callAPISuccess('contact', 'create', array(
396 'sort_name' => $test_contact_name,
397 'contact_type' => 'Individual',
398 'display_name' => $test_contact_name,
400 $contact_id = $contact_save_result['id'];
402 // I have no clue what this $subfile is about. I just copied it from another
404 $subfile = 'ContactRefCustomField';
405 $description = "Demonstrates get with Contact Reference Custom Field.";
407 // Create a custom group, and add a custom contact reference field.
408 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
410 'custom_group_id' => $ids['custom_group_id'],
411 'name' => 'Worker_Lookup',
412 'label' => 'Worker Lookup',
413 'html_type' => 'Autocomplete-Select',
414 'data_type' => 'ContactReference',
416 'is_searchable' => 1,
419 $customField = $this->callAPISuccess('custom_field', 'create', $params);
421 // Create an event, and add the contact as custom value.
422 $params = $this->_params
;
423 $params['title'] = "My test event.";
424 $params['start_date'] = "2015-03-14";
425 // Just assume that an event type 1 exists.
426 $params['event_type_id'] = 1;
427 $params['custom_' . $customField['id']] = "$contact_id";
429 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
431 // Retrieve the activity, search for the contact.
432 $result = $this->callAPIAndDocument($this->_entity
, 'get', array(
433 'return.custom_' . $customField['id'] => 1,
434 'custom_' . $customField['id'] => $contact_id,
435 ), __FUNCTION__
, __FILE__
, $description, $subfile);
437 $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
438 $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__
);
439 // Not sure whether I should test for custom_X_1 and custom_X_1_id as well.
440 // (1 being the id of the record in the custom value table)
442 $this->customFieldDelete($ids['custom_field_id']);
443 $this->customGroupDelete($ids['custom_group_id']);
444 $this->callAPISuccess('contact', 'delete', array(
446 'skip_undelete' => TRUE,
451 * Test searching on custom fields with less than or equal.
455 public function testEventGetCustomFieldLte() {
456 // create custom group with custom field on event
457 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
459 // Create an event, with a custom value.
460 $params = $this->_params
;
461 $params['title'] = "My test event.";
462 $params['start_date'] = "2015-03-14";
463 // Just assume that an event type 1 exists.
464 $params['event_type_id'] = 1;
465 $params['custom_' . $ids['custom_field_id']] = "AAAA";
467 $save_result = $this->callApiSuccess($this->_entity
, 'create', $params);
469 // Retrieve the activity, search for custom field < 'BBBB'
470 $get_result = $this->callAPISuccess($this->_entity
, 'get', array(
471 'return.custom_' . $ids['custom_field_id'] => 1,
472 'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'),
475 // Expect that we find the saved event.
476 $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
478 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $save_result['id']));
482 * Test searching on custom fields with netsted call with id param.
484 * Search for an event on a custom field, and perform a chained call
485 * to retrieve it's (non-existing) loc block, using $value-substitution.
486 * This test just checks whether the event is found, because something
487 * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing
488 * CiviCRM to return 0 results.
489 * Of course, CRM-16168 should also be fixed for this test to pass.
491 public function testEventSearchCustomFieldWithChainedCall() {
492 // Create a custom group, and add a custom contact reference field.
493 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
494 $custom_field_id = $ids['custom_field_id'];
496 // Create an event with a custom value.
497 $params = $this->_params
;
498 $params['title'] = "My test event.";
499 $params['start_date'] = "2015-03-14";
500 // Just assume that an event type 1 exists.
501 $params['event_type_id'] = 1;
502 $params['custom_' . $custom_field_id] = "12345";
504 $this->callAPISuccess($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
506 // Retrieve the activity, and chain loc block using $value.
507 $result = $this->callAPISuccess($this->_entity
, 'get', array(
508 'custom_' . $custom_field_id => "12345",
509 'api.LocBlock.get' => array("id" => '$value.loc_block_id'),
512 $this->assertEquals(1, $result['count']);
514 $this->customFieldDelete($ids['custom_field_id']);
515 $this->customGroupDelete($ids['custom_group_id']);
516 $this->callAPISuccess('event', 'delete', array(
517 'id' => $result['id'],
518 'skip_undelete' => TRUE,
524 * Test that an event with a price set can be created.
526 public function testCreatePaidEvent() {
527 //@todo alter API so that an integer is converted to an array
528 $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1);
529 $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params
[0], $priceSetParams));
530 $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id'));
531 $this->assertArrayKeyExists('price_set_id', $event);
534 public function testCreateEventParamsNotArray() {
536 $result = $this->callAPIFailure('event', 'create', $params);
539 public function testCreateEventEmptyParams() {
541 $result = $this->callAPIFailure('event', 'create', $params);
544 public function testCreateEventParamsWithoutTitle() {
545 unset($this->_params
['title']);
546 $result = $this->callAPIFailure('event', 'create', $this->_params
);
547 $this->assertAPIFailure($result);
550 public function testCreateEventParamsWithoutEventTypeId() {
551 unset($this->_params
['event_type_id']);
552 $result = $this->callAPIFailure('event', 'create', $this->_params
);
555 public function testCreateEventParamsWithoutStartDate() {
556 unset($this->_params
['start_date']);
557 $result = $this->callAPIFailure('event', 'create', $this->_params
);
560 public function testCreateEventSuccess() {
561 $result = $this->callAPIAndDocument('Event', 'Create', $this->_params
[0], __FUNCTION__
, __FILE__
);
562 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
563 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
564 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
565 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
566 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
567 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
568 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
572 * Test that passing in Unique field names works.
574 public function testCreateEventSuccessUniqueFieldNames() {
575 $this->_params
[0]['event_start_date'] = $this->_params
[0]['start_date'];
576 unset($this->_params
[1]['start_date']);
577 $this->_params
[0]['event_title'] = $this->_params
[0]['title'];
578 unset($this->_params
[0]['title']);
579 $result = $this->callAPISuccess('Event', 'Create', $this->_params
[0]);
580 $this->assertAPISuccess($result);
581 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
582 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
583 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
585 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
586 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
587 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
588 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
589 $this->assertEquals($this->_params
[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__
);
592 public function testUpdateEvent() {
593 $result = $this->callAPISuccess('event', 'create', $this->_params
[1]);
596 'id' => $result['id'],
597 'max_participants' => 150,
599 $this->callAPISuccess('Event', 'Create', $params);
600 $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__
, __FILE__
);
601 $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
602 $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
603 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
607 public function testDeleteEmptyParams() {
608 $result = $this->callAPIFailure('Event', 'Delete', array());
611 public function testDelete() {
613 'id' => $this->_eventIds
[0],
615 $result = $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__
, __FILE__
);
619 * Check event_id still supported for delete.
621 public function testDeleteWithEventId() {
623 'event_id' => $this->_eventIds
[0],
625 $result = $this->callAPISuccess('Event', 'Delete', $params);
626 $this->assertAPISuccess($result);
630 * Trying to delete an event with participants should return error.
632 public function testDeleteWithExistingParticipant() {
633 $contactID = $this->individualCreate();
634 $participantID = $this->participantCreate(
636 'contactID' => $contactID,
637 'eventID' => $this->_eventIds
[0],
640 $result = $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds
[0]));
643 public function testDeleteWithWrongEventId() {
644 $params = array('event_id' => $this->_eventIds
[0]);
645 $result = $this->callAPISuccess('Event', 'Delete', $params);
646 // try to delete again - there's no such event anymore
647 $params = array('event_id' => $this->_eventIds
[0]);
648 $result = $this->callAPIFailure('Event', 'Delete', $params);
651 ///////////////// civicrm_event_search methods
654 * Test civicrm_event_search with wrong params type.
656 public function testSearchWrongParamsType() {
657 $params = 'a string';
658 $result = $this->callAPIFailure('event', 'get', $params);
662 * Test civicrm_event_search with empty params.
664 public function testSearchEmptyParams() {
665 $this->callAPISuccess('event', 'create', $this->_params
[1]);
670 $result = $this->callAPISuccess('event', 'get', $getParams);
671 $this->assertEquals($result['count'], 3);
672 $res = $result['values'][0];
673 $this->assertArrayKeyExists('title', $res);
674 $this->assertEquals($res['event_type_id'], $this->_params
[1]['event_type_id']);
678 * Test civicrm_event_search. Success expected.
680 public function testSearch() {
682 'event_type_id' => 1,
685 'return.start_date' => 1,
687 $result = $this->callAPISuccess('event', 'get', $params);
689 $this->assertEquals($result['values'][$this->_eventIds
[0]]['id'], $this->_eventIds
[0]);
690 $this->assertEquals($result['values'][$this->_eventIds
[0]]['title'], 'Annual CiviCRM meet');
694 * Test civicrm_event_search.
698 * return.offset and return.max_results test (CRM-5266)
700 public function testSearchWithOffsetAndMaxResults() {
703 while ($maxEvents > 0) {
705 'title' => 'Test Event' . $maxEvents,
706 'event_type_id' => 2,
707 'start_date' => 20081021,
710 $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
714 'event_type_id' => 2,
717 'return.offset' => 2,
718 'return.max_results' => 2,
720 $result = $this->callAPISuccess('event', 'get', $params);
721 $this->assertAPISuccess($result);
722 $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__
);
725 public function testEventCreationPermissions() {
727 'event_type_id' => 1,
728 'start_date' => '2010-10-03',
729 'title' => 'le cake is a tie',
730 'check_permissions' => TRUE,
732 $config = &CRM_Core_Config
::singleton();
733 $config->userPermissionClass
->permissions
= array('access CiviCRM');
734 $result = $this->callAPIFailure('event', 'create', $params);
735 $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');
737 $config->userPermissionClass
->permissions
= array(
742 $result = $this->callAPISuccess('event', 'create', $params);
745 public function testgetfields() {
746 $description = "Demonstrate use of getfields to interrogate api.";
747 $params = array('action' => 'create');
748 $result = $this->callAPISuccess('event', 'getfields', $params);
749 $this->assertEquals(1, $result['values']['is_active']['api.default']);
753 * Test api_action param also works.
755 public function testgetfieldsRest() {
756 $description = "Demonstrate use of getfields to interrogate api.";
757 $params = array('api_action' => 'create');
758 $result = $this->callAPISuccess('event', 'getfields', $params);
759 $this->assertEquals(1, $result['values']['is_active']['api.default']);
762 public function testgetfieldsGet() {
763 $description = "Demonstrate use of getfields to interrogate api.";
764 $params = array('action' => 'get');
765 $result = $this->callAPISuccess('event', 'getfields', $params);
766 $this->assertEquals('title', $result['values']['event_title']['name']);
769 public function testgetfieldsDelete() {
770 $description = "Demonstrate use of getfields to interrogate api.";
771 $params = array('action' => 'delete');
772 $result = $this->callAPISuccess('event', 'getfields', $params);
773 $this->assertEquals(1, $result['values']['id']['api.required']);
776 public function testCreateFromTemplate() {
777 $templateParams = array(
778 'summary' => 'Sign up now to learn the results of this unit test',
779 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
780 'event_type_id' => 1,
782 'end_date' => '2018-06-25 17:00:00',
783 'is_online_registration' => 1,
784 'registration_start_date' => '2017-06-25 17:00:00',
785 'registration_end_date' => '2018-06-25 17:00:00',
786 'max_participants' => 100,
787 'event_full_text' => 'Sorry! We are already full',
789 $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') +
$templateParams);
790 $eventResult = $this->callAPISuccess('Event', 'create', array(
791 'template_id' => $templateResult['id'],
793 'start_date' => '2018-06-25 16:00:00',
795 $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
796 foreach ($templateParams as $param => $value) {
797 $this->assertEquals($value, $eventResult[$param]);