3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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]);
161 * @param int $version
162 * @dataProvider versionThreeAndFour
164 public function testGetEventByWrongTitle($version) {
165 $this->_apiversion
= $version;
167 'title' => 'No event with that title',
169 $result = $this->callAPISuccess('Event', 'Get', $params);
170 $this->assertEquals(0, $result['count']);
174 * Skip api4 - this api uses deprecated query syntax
176 public function testGetEventByIdSort() {
178 'return.sort' => 'id ASC',
179 'return.max_results' => 1,
181 $result = $this->callAPISuccess('Event', 'Get', $params);
182 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
190 $result = $this->callAPISuccess('Event', 'Get', $params);
191 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
192 $this->assertEquals(2, $result['id'], ' in line ' . __LINE__
);
199 $result = $this->callAPISuccess('Event', 'Get', $params);
200 $this->assertEquals(1, $result['id'], ' in line ' . __LINE__
);
205 * Getting the id back of an event.
206 * Does not work yet, bug in API
210 public function testGetIdOfEventByEventTitle() {
211 $params = array( 'title' => 'Annual CiviCRM meet',
215 $result = $this->callAPISuccess('Event', 'Get', $params);
220 * Test 'is.Current' option. Existing event is 'old' so only current should be returned
223 public function testGetIsCurrent() {
227 $currentEventParams = array(
228 'start_date' => date('Y-m-d', strtotime('+ 1 day')),
229 'end_date' => date('Y-m-d', strtotime('+ 1 week')),
231 $currentEventParams = array_merge($this->_params
[1], $currentEventParams);
232 $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams);
233 $description = "Demonstrates use of is.Current option.";
234 $subfile = "IsCurrentOption";
235 $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
236 $allEvents = $this->callAPISuccess('Event', 'Get', array());
237 $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id']));
238 $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__
);
239 $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__
);
240 $this->assertEquals($currentEvent['id'], $result['id'], '');
244 * There has been a schema change & the api needs to buffer developers from it
247 public function testGetPaymentProcessorId() {
248 $params = $this->_params
[0];
249 $params['payment_processor_id'] = 1;
250 $params['sequential'] = 1;
251 $result = $this->callAPISuccess('event', 'create', $params);
252 $this->assertEquals(1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility");
253 $result = $this->callAPISuccess('event', 'get', $params);
254 $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility");
258 * @param int $version
259 * @dataProvider versionThreeAndFour
261 public function testInvalidData($version) {
262 $this->_apiversion
= $version;
263 $params = $this->_params
[0];
264 $params['sequential'] = 1;
265 $params['loc_block_id'] = 100;
266 $result = $this->callAPIFailure('event', 'create', $params);
271 * Test 'is_full' option.
274 public function testGetSingleReturnIsFull() {
275 $contactID = $this->individualCreate();
277 'id' => $this->_eventIds
[0],
278 'max_participants' => 1,
280 $result = $this->callAPISuccess('Event', 'Create', $params);
282 $getEventParams = array(
283 'id' => $this->_eventIds
[0],
284 'return.is_full' => 1,
287 $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams);
288 $description = "Demonstrates use of return is_full .";
289 $subfile = "IsFullOption";
290 $this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
291 $this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
292 $participant = $this->callAPISuccess('Participant', 'create', array(
293 'participant_status' => 1,
295 'contact_id' => $contactID,
296 'event_id' => $this->_eventIds
[0],
298 $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__
, __FILE__
, $description, $subfile);
299 $this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__
);
300 $this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__
);
302 $this->contactDelete($contactID);
306 * Legacy support for Contribution Type ID.
308 * We need to ensure this is supported as an alias for financial_type_id.
310 public function testCreateGetEventLegacyContributionTypeID() {
311 $contributionTypeArray = array('contribution_type_id' => 3);
312 if (isset($this->_params
[0]['financial_type_id'])) {
313 //in case someone edits $this->_params & invalidates this test :-)
314 unset($this->_params
[0]['financial_type_id']);
316 $result = $this->callAPISuccess('event', 'create', $this->_params
[0] +
$contributionTypeArray);
317 $getresult = $this->callAPISuccess('event', 'get', array() +
$contributionTypeArray);
318 $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
319 $this->assertEquals($result['id'], $getresult['id']);
320 $this->callAPISuccess('event', 'delete', array('id' => $result['id']));
324 * Chaining get event and loc block.
325 * @param int $version
326 * @dataProvider versionThreeAndFour
328 public function testChainingGetLocBlock($version) {
329 $this->_apiversion
= $version;
330 // create a loc block and an event for that loc block.
331 $eventParams = $this->_params
[0];
332 $eventParams['loc_bloc_id'] = '$value.id';
333 $locBlockParams = array(
335 'street_address' => 'Kipdorp 24',
336 'postal_code' => '2000',
337 'city' => 'Antwerpen',
338 'country_id' => '1020',
339 'location_type_id' => '1',
341 'api.Event.create' => $eventParams,
344 $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams);
345 $locBlockId = $createResult['id'];
346 $eventId = $createResult['values'][0]['api.Event.create']['id'];
348 // request the event with its loc block:
349 $check = $this->callAPISuccess($this->_entity
, 'getsingle', array(
351 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
356 $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__
);
357 $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__
);
358 $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__
);
361 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $eventId));
365 * Chaining get event and non existing loc block.
367 * Even if there is no loc block, at least the event should be returned.
368 * http://forum.civicrm.org/index.php/topic,36113.0.html
370 public function testChainingGetNonExistingLocBlock() {
371 $params = $this->_params
[0];
372 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
374 $check = $this->callAPISuccess($this->_entity
, 'get', array(
375 'id' => $result['id'],
376 // this chaining request should not break things:
377 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
379 $this->assertEquals($result['id'], $check['id']);
381 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
385 * Check with complete array + custom field.
387 * Note that the test is written on purpose without any
388 * variables specific to participant so it can be replicated into other entities
389 * and / or moved to the automated test suite.
390 * @param int $version
391 * @dataProvider versionThreeAndFour
393 public function testCreateWithCustom($version) {
394 $this->_apiversion
= $version;
395 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
397 $params = $this->_params
[0];
398 $params['custom_' . $ids['custom_field_id']] = "custom string";
400 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
402 $check = $this->callAPISuccess($this->_entity
, 'get', array(
403 'return.custom_' . $ids['custom_field_id'] => 1,
404 'id' => $result['id'],
406 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
408 $this->customFieldDelete($ids['custom_field_id']);
409 $this->customGroupDelete($ids['custom_group_id']);
410 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
414 * Check searching on custom fields.
416 * https://issues.civicrm.org/jira/browse/CRM-16036
417 * @param int $version
418 * @dataProvider versionThreeAndFour
420 public function testSearchCustomField($version) {
421 $this->_apiversion
= $version;
422 // create custom group with custom field on event
423 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
425 // Search for events having CRM-16036 as the value for this custom
426 // field. This should not return anything.
427 $check = $this->callAPISuccess($this->_entity
, 'get', array(
428 'custom_' . $ids['custom_field_id'] => 'CRM-16036',
431 $this->assertEquals(0, $check['count']);
433 $this->customFieldDelete($ids['custom_field_id']);
434 $this->customGroupDelete($ids['custom_group_id']);
438 * Check searching on custom fields with IS NULL.
440 * https://issues.civicrm.org/jira/browse/CRM-20740
441 * @param int $version
442 * @dataProvider versionThreeAndFour
444 public function testSearchCustomFieldIsNull($version) {
445 $this->_apiversion
= $version;
446 // create custom group with custom field on event
447 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
449 // Search for events having NULL as the value for this custom
450 // field. This should return all events created in setUp.
451 $check = $this->callAPISuccess($this->_entity
, 'get', array(
452 'custom_' . $ids['custom_field_id'] => array('IS NULL' => 1),
455 $this->assertGreaterThan(0, $check['count']);
457 $this->customFieldDelete($ids['custom_field_id']);
458 $this->customGroupDelete($ids['custom_group_id']);
462 * Test searching on custom fields returning a contact reference.
464 * https://issues.civicrm.org/jira/browse/CRM-16036
467 public function testEventGetCustomContactRefFieldCRM16036() {
468 // Create some contact.
469 $test_contact_name = 'Contact, Test';
470 $contact_save_result = $this->callAPISuccess('contact', 'create', array(
471 'sort_name' => $test_contact_name,
472 'contact_type' => 'Individual',
473 'display_name' => $test_contact_name,
475 $contact_id = $contact_save_result['id'];
477 // I have no clue what this $subfile is about. I just copied it from another
479 $subfile = 'ContactRefCustomField';
480 $description = "Demonstrates get with Contact Reference Custom Field.";
482 // Create a custom group, and add a custom contact reference field.
483 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
485 'custom_group_id' => $ids['custom_group_id'],
486 'name' => 'Worker_Lookup',
487 'label' => 'Worker Lookup',
488 'html_type' => 'Autocomplete-Select',
489 'data_type' => 'ContactReference',
491 'is_searchable' => 1,
494 $customField = $this->callAPISuccess('custom_field', 'create', $params);
496 // Create an event, and add the contact as 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_' . $customField['id']] = "$contact_id";
504 $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
506 // Retrieve the activity, search for the contact.
507 $result = $this->callAPIAndDocument($this->_entity
, 'get', array(
508 'return.custom_' . $customField['id'] => 1,
509 'custom_' . $customField['id'] => $contact_id,
510 ), __FUNCTION__
, __FILE__
, $description, $subfile);
512 $this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
513 $this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__
);
514 // Not sure whether I should test for custom_X_1 and custom_X_1_id as well.
515 // (1 being the id of the record in the custom value table)
517 $this->customFieldDelete($ids['custom_field_id']);
518 $this->customGroupDelete($ids['custom_group_id']);
519 $this->callAPISuccess('contact', 'delete', array(
521 'skip_undelete' => TRUE,
526 * Test searching on custom fields with less than or equal.
529 * @param int $version
530 * @dataProvider versionThreeAndFour
532 public function testEventGetCustomFieldLte($version) {
533 $this->_apiversion
= $version;
534 // create custom group with custom field on event
535 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
537 // Create an event, with a custom value.
538 $params = $this->_params
;
539 $params['title'] = "My test event.";
540 $params['start_date'] = "2015-03-14";
541 // Just assume that an event type 1 exists.
542 $params['event_type_id'] = 1;
543 $params['custom_' . $ids['custom_field_id']] = "AAAA";
545 $save_result = $this->callApiSuccess($this->_entity
, 'create', $params);
547 // Retrieve the activity, search for custom field < 'BBBB'
548 $get_result = $this->callAPISuccess($this->_entity
, 'get', array(
549 'return.custom_' . $ids['custom_field_id'] => 1,
550 'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'),
553 // Expect that we find the saved event.
554 $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
556 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $save_result['id']));
560 * Test searching on custom fields with netsted call with id param.
562 * Search for an event on a custom field, and perform a chained call
563 * to retrieve it's (non-existing) loc block, using $value-substitution.
564 * This test just checks whether the event is found, because something
565 * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing
566 * CiviCRM to return 0 results.
567 * Of course, CRM-16168 should also be fixed for this test to pass.
569 public function testEventSearchCustomFieldWithChainedCall() {
570 // Create a custom group, and add a custom contact reference field.
571 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
572 $custom_field_id = $ids['custom_field_id'];
574 // Create an event with a custom value.
575 $params = $this->_params
;
576 $params['title'] = "My test event.";
577 $params['start_date'] = "2015-03-14";
578 // Just assume that an event type 1 exists.
579 $params['event_type_id'] = 1;
580 $params['custom_' . $custom_field_id] = "12345";
582 $this->callAPISuccess($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
584 // Retrieve the activity, and chain loc block using $value.
585 $result = $this->callAPISuccess($this->_entity
, 'get', array(
586 'custom_' . $custom_field_id => "12345",
587 'api.LocBlock.get' => array("id" => '$value.loc_block_id'),
590 $this->assertEquals(1, $result['count']);
592 $this->customFieldDelete($ids['custom_field_id']);
593 $this->customGroupDelete($ids['custom_group_id']);
594 $this->callAPISuccess('event', 'delete', array(
595 'id' => $result['id'],
596 'skip_undelete' => TRUE,
601 * Test that an event with a price set can be created.
604 public function testCreatePaidEvent() {
605 //@todo alter API so that an integer is converted to an array
606 $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1);
607 $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params
[0], $priceSetParams));
608 $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id'));
609 $this->assertArrayKeyExists('price_set_id', $event);
613 * @param int $version
614 * @dataProvider versionThreeAndFour
616 public function testCreateEventEmptyParams($version) {
617 $this->_apiversion
= $version;
619 $result = $this->callAPIFailure('event', 'create', $params);
623 * @param int $version
624 * @dataProvider versionThreeAndFour
626 public function testCreateEventParamsWithoutTitle($version) {
627 $this->_apiversion
= $version;
628 unset($this->_params
['title']);
629 $result = $this->callAPIFailure('event', 'create', $this->_params
);
630 $this->assertAPIFailure($result);
634 * @param int $version
635 * @dataProvider versionThreeAndFour
637 public function testCreateEventParamsWithoutEventTypeId($version) {
638 $this->_apiversion
= $version;
639 unset($this->_params
['event_type_id']);
640 $result = $this->callAPIFailure('event', 'create', $this->_params
);
644 * @param int $version
645 * @dataProvider versionThreeAndFour
647 public function testCreateEventParamsWithoutStartDate($version) {
648 $this->_apiversion
= $version;
649 unset($this->_params
['start_date']);
650 $result = $this->callAPIFailure('event', 'create', $this->_params
, 'start_date');
654 * @param int $version
655 * @dataProvider versionThreeAndFour
657 public function testCreateEventSuccess($version) {
658 $this->_apiversion
= $version;
659 $result = $this->callAPIAndDocument('Event', 'Create', $this->_params
[0], __FUNCTION__
, __FILE__
);
660 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
661 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
662 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
663 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set');
664 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set');
665 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set');
666 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set');
670 * Test that passing in Unique field names works.
671 * Skip api4 which doesn't use unique names
673 public function testCreateEventSuccessUniqueFieldNames() {
674 $this->_params
[0]['event_start_date'] = $this->_params
[0]['start_date'];
675 unset($this->_params
[1]['start_date']);
676 $this->_params
[0]['event_title'] = $this->_params
[0]['title'];
677 unset($this->_params
[0]['title']);
678 $result = $this->callAPISuccess('Event', 'Create', $this->_params
[0]);
679 $this->assertAPISuccess($result);
680 $this->assertArrayHasKey('id', $result['values'][$result['id']]);
681 $result = $this->callAPISuccess($this->_entity
, 'Get', array('id' => $result['id']));
682 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
684 $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__
);
685 $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__
);
686 $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__
);
687 $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__
);
688 $this->assertEquals($this->_params
[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__
);
692 * @param int $version
693 * @dataProvider versionThreeAndFour
695 public function testUpdateEvent($version) {
696 $this->_apiversion
= $version;
697 $result = $this->callAPISuccess('event', 'create', $this->_params
[1]);
700 'id' => $result['id'],
701 'max_participants' => 150,
703 $this->callAPISuccess('Event', 'Create', $params);
704 $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__
, __FILE__
);
705 $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
706 $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
707 $this->callAPISuccess($this->_entity
, 'Delete', array('id' => $result['id']));
711 * @param int $version
712 * @dataProvider versionThreeAndFour
714 public function testDeleteEmptyParams($version) {
715 $this->_apiversion
= $version;
716 $result = $this->callAPIFailure('Event', 'Delete', array());
720 * @param int $version
721 * @dataProvider versionThreeAndFour
723 public function testDelete($version) {
724 $this->_apiversion
= $version;
726 'id' => $this->_eventIds
[0],
728 $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__
, __FILE__
);
732 * Check event_id still supported for delete.
733 * @param int $version
734 * @dataProvider versionThreeAndFour
736 public function testDeleteWithEventId($version) {
737 $this->_apiversion
= $version;
739 'event_id' => $this->_eventIds
[0],
741 $result = $this->callAPISuccess('Event', 'Delete', $params);
742 $this->assertAPISuccess($result);
746 * Trying to delete an event with participants should return error.
747 * @param int $version
748 * @dataProvider versionThreeAndFour
750 public function testDeleteWithExistingParticipant($version) {
751 $this->_apiversion
= $version;
752 $contactID = $this->individualCreate();
753 $this->participantCreate(
755 'contactID' => $contactID,
756 'eventID' => $this->_eventIds
[0],
759 $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds
[0]));
763 * @param int $version
764 * @dataProvider versionThreeAndFour
766 public function testDeleteWithWrongEventId($version) {
767 $this->_apiversion
= $version;
768 $params = array('event_id' => $this->_eventIds
[0]);
769 $result = $this->callAPISuccess('Event', 'Delete', $params);
770 // try to delete again - there's no such event anymore
771 $params = array('event_id' => $this->_eventIds
[0]);
772 $result = $this->callAPIFailure('Event', 'Delete', $params);
776 * Test civicrm_event_search with wrong params type.
777 * @param int $version
778 * @dataProvider versionThreeAndFour
780 public function testSearchWrongParamsType($version) {
781 $this->_apiversion
= $version;
782 $params = 'a string';
783 $result = $this->callAPIFailure('event', 'get', $params);
787 * Test civicrm_event_search with empty params.
788 * @param int $version
789 * @dataProvider versionThreeAndFour
791 public function testSearchEmptyParams($version) {
792 $this->_apiversion
= $version;
793 $this->callAPISuccess('event', 'create', $this->_params
[1]);
798 $result = $this->callAPISuccess('event', 'get', $getParams);
799 $this->assertEquals($result['count'], 3);
800 $res = $result['values'][0];
801 $this->assertArrayKeyExists('title', $res);
802 $this->assertEquals($res['event_type_id'], $this->_params
[1]['event_type_id']);
806 * Test civicrm_event_search. Success expected.
807 * @param int $version
808 * @dataProvider versionThreeAndFour
810 public function testSearch($version) {
811 $this->_apiversion
= $version;
813 'event_type_id' => 1,
816 'return.start_date' => 1,
818 $result = $this->callAPISuccess('event', 'get', $params);
820 $this->assertEquals($result['values'][$this->_eventIds
[0]]['id'], $this->_eventIds
[0]);
821 $this->assertEquals($result['values'][$this->_eventIds
[0]]['title'], 'Annual CiviCRM meet');
825 * Test civicrm_event_search.
829 * return.offset and return.max_results test (CRM-5266)
831 public function testSearchWithOffsetAndMaxResults() {
834 while ($maxEvents > 0) {
836 'title' => 'Test Event' . $maxEvents,
837 'event_type_id' => 2,
838 'start_date' => 20081021,
841 $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
845 'event_type_id' => 2,
848 'return.offset' => 2,
849 'return.max_results' => 2,
851 $result = $this->callAPISuccess('event', 'get', $params);
852 $this->assertAPISuccess($result);
853 $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__
);
857 * @param int $version
858 * @dataProvider versionThreeAndFour
860 public function testEventCreationPermissions($version) {
861 $this->_apiversion
= $version;
863 'event_type_id' => 1,
864 'start_date' => '2010-10-03',
865 'title' => 'le cake is a tie',
866 'check_permissions' => TRUE,
868 $config = CRM_Core_Config
::singleton();
869 $config->userPermissionClass
->permissions
= array('access CiviCRM');
870 $result = $this->callAPIFailure('event', 'create', $params, 'failed');
872 $config->userPermissionClass
->permissions
= array(
877 $result = $this->callAPISuccess('event', 'create', $params);
881 * @param int $version
882 * @dataProvider versionThreeAndFour
884 public function testgetfields($version) {
885 $this->_apiversion
= $version;
886 $description = "Demonstrate use of getfields to interrogate api.";
887 $params = array('action' => 'create');
888 $result = $this->callAPISuccess('event', 'getfields', $params);
889 $this->assertEquals('is_active', $result['values']['is_active']['name']);
893 * Test api_action param also works.
895 public function testgetfieldsRest() {
896 $description = "Demonstrate use of getfields to interrogate api.";
897 $params = array('api_action' => 'create');
898 $result = $this->callAPISuccess('event', 'getfields', $params);
899 $this->assertEquals(1, $result['values']['is_active']['api.default']);
903 * Skip api4 - output is different
905 public function testgetfieldsGet() {
906 $description = "Demonstrate use of getfields to interrogate api.";
907 $params = array('action' => 'get');
908 $result = $this->callAPISuccess('event', 'getfields', $params);
909 $this->assertEquals('title', $result['values']['event_title']['name']);
913 * Skip api4 - output is different
915 public function testgetfieldsDelete() {
916 $description = "Demonstrate use of getfields to interrogate api.";
917 $params = array('action' => 'delete');
918 $result = $this->callAPISuccess('event', 'getfields', $params);
919 $this->assertEquals(1, $result['values']['id']['api.required']);
923 * @param int $version
924 * @dataProvider versionThreeAndFour
926 public function testCreateFromTemplate($version) {
927 $this->_apiversion
= $version;
928 $templateParams = array(
929 'summary' => 'Sign up now to learn the results of this unit test',
930 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
931 'event_type_id' => 1,
933 'end_date' => '2018-06-25 17:00:00',
934 'is_online_registration' => 1,
935 'registration_start_date' => '2017-06-25 17:00:00',
936 'registration_end_date' => '2018-06-25 17:00:00',
937 'max_participants' => 100,
938 'event_full_text' => 'Sorry! We are already full',
940 $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') +
$templateParams);
941 $eventResult = $this->callAPISuccess('Event', 'create', array(
942 'template_id' => $templateResult['id'],
944 'start_date' => '2018-06-25 16:00:00',
946 $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
947 foreach ($templateParams as $param => $value) {
948 $this->assertEquals($value, $eventResult[$param]);