/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
protected $_params;
protected $_apiversion;
protected $_entity;
- public $_eNoticeCompliant = TRUE;
+
function get_info() {
return array(
'name' => 'Event Create',
'is_monetary' => 0,
'is_active' => 1,
'is_show_location' => 0,
- 'version' => $this->_apiversion,
),
array(
'title' => 'Annual CiviCRM meet 2',
'is_monetory' => 0,
'is_active' => 1,
'is_show_location' => 0,
- 'version' => $this->_apiversion,
),
);
array(
'title' => 'Annual CiviCRM meet',
'event_type_id' => 1,
- 'start_date' => 20081021,
- 'version' => $this->_apiversion,
- ),
+ 'start_date' => 20081021, ),
array(
'title' => 'Annual CiviCRM meet 2',
'event_type_id' => 1,
- 'start_date' => 20101021,
- 'version' => $this->_apiversion,
- ),
+ 'start_date' => 20101021, ),
);
$this->events = array();
foreach ($this->eventIds as $eventId) {
$this->eventDelete($eventId);
}
-
- /*
- if ($this->_eventId) {
- $this->eventDelete($this->_eventId);
- }
- $this->eventDelete($this->_event['id']);
- */
-
-
$tablesToTruncate = array(
'civicrm_participant',
'civicrm_event',
function testGetEventById() {
$params = array(
- 'id' => $this->_events[1]['id'],
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('event', 'get', $params);
+ 'id' => $this->_events[1]['id'],);
+ $result = $this->callAPISuccess('event', 'get', $params);
$this->assertEquals($result['values'][$this->_eventIds[1]]['event_title'], 'Annual CiviCRM meet 2');
}
function testGetEventByWrongTitle() {
$params = array(
- 'title' => 'No event with that title',
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('Event', 'Get', $params);
+ 'title' => 'No event with that title',);
+ $result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertEquals(0, $result['count']);
}
function testGetEventByIdSort() {
$params = array(
'return.sort' => 'id ASC',
- 'return.max_results' => 1,
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('Event', 'Get', $params);
+ 'return.max_results' => 1, );
+ $result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertEquals(1, $result['id'], ' in line ' . __LINE__);
$params = array(
'options' => array(
'sort' => 'id DESC',
'limit' => 1,
- ),
- 'version' => $this->_apiversion,
- );
+ ), );
- $result = civicrm_api('Event', 'Get', $params);
+ $result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertAPISuccess($result, ' in line ' . __LINE__);
$this->assertEquals(2, $result['id'], ' in line ' . __LINE__);
$params = array(
'options' => array(
'sort' => 'id ASC',
'limit' => 1,
- ),
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('Event', 'Get', $params);
+ ), );
+ $result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertEquals(1, $result['id'], ' in line ' . __LINE__);
/*
function testGetIdOfEventByEventTitle() {
- $params = array(
- 'version' => $this->_apiversion,
- 'title' => 'Annual CiviCRM meet',
+ $params = array( 'title' => 'Annual CiviCRM meet',
'return' => 'id'
);
- $result = civicrm_api('Event', 'Get', $params);
+ $result = $this->callAPISuccess('Event', 'Get', $params);
}
*/
$description = "demonstrates use of is.Current option";
$subfile = "IsCurrentOption";
$result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $allEvents = $this->callAPISuccess('Event', 'Get', array('version' => 3));
- $this->callAPISuccess('Event', 'Delete', array('version' => 3, 'id' => $currentEvent['id']));
+ $allEvents = $this->callAPISuccess('Event', 'Get', array());
+ $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id']));
$this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__);
$this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__);
$this->assertEquals($currentEvent['id'], $result['id'], '');
$params = $this->_params[0];
$params['payment_processor_id'] = 1;
$params['sequential'] =1;
- $result = civicrm_api('event', 'create', $params);
+ $result = $this->callAPISuccess('event', 'create', $params);
$this->assertEquals( 1,$result['values'][0]['payment_processor'][0], "handing of payment processor compatibility");
- $result = civicrm_api('event', 'get', $params);
+ $result = $this->callAPISuccess('event', 'get', $params);
$this->assertEquals($result['values'][0]['payment_processor_id'], 1,"handing get payment processor compatibility");
}
function testGetSingleReturnIsFull() {
$contactID = $this->individualCreate();
$params = array(
- 'id' => $this->_eventIds[0],
- 'version' => $this->_apiversion,
- 'max_participants' => 1,
+ 'id' => $this->_eventIds[0], 'max_participants' => 1,
);
- $result = civicrm_api('Event', 'Create', $params);
+ $result = $this->callAPISuccess('Event', 'Create', $params);
$getEventParams = array(
- 'id' => $this->_eventIds[0],
- 'version' => $this->_apiversion,
- 'return.is_full' => 1,
+ 'id' => $this->_eventIds[0], 'return.is_full' => 1,
);
- $currentEvent = civicrm_api('Event', 'getsingle', $getEventParams);
+ $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams);
$description = "demonstrates use of return is_full ";
$subfile = "IsFullOption";
$this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__);
$this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__);
- $participant = civicrm_api('Participant', 'create', array('version' => 3, 'participant_status' => 1, 'role_id' => 1, 'contact_id' => $contactID, 'event_id' => $this->_eventIds[0]));
- $currentEvent = civicrm_api('Event', 'getsingle', $getEventParams);
-
- $this->documentMe($getEventParams, $currentEvent, __FUNCTION__, __FILE__, $description, $subfile, 'getsingle');
+ $participant = $this->callAPISuccess('Participant', 'create', array('participant_status' => 1, 'role_id' => 1, 'contact_id' => $contactID, 'event_id' => $this->_eventIds[0]));
+ $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__, __FILE__, $description, $subfile, 'getsingle');
$this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__);
$this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__);
//in case someone edits $this->_params & invalidates this test :-)
unset($this->_params[0]['financial_type_id']);
}
- $result = civicrm_api('event', 'create', $this->_params[0] + $contributionTypeArray);
- $this->assertAPISuccess($result, ' Event Creation Failedon line ' . __LINE__);
- $getresult = civicrm_api('event', 'get', array('version' => 3,) + $contributionTypeArray);
- $this->assertAPISuccess($result, ' Event Creation on line ' . __LINE__);
+ $result = $this->callAPISuccess('event', 'create', $this->_params[0] + $contributionTypeArray);
+ $getresult = $this->callAPISuccess('event', 'get', array() + $contributionTypeArray);
$this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
$this->assertEquals($result['id'], $getresult['id']);
- civicrm_api('event', 'delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess('event', 'delete', array('id' => $result['id']));
}
///////////////// civicrm_event_create methods
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
- $check = civicrm_api($this->_entity, 'get', array('version' => 3, 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id']));
+ $check = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id']));
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
- civicrm_api($this->_entity, 'Delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
}
function testCreateEventParamsNotArray() {
function testCreateEventParamsWithoutTitle() {
unset($this->_params['title']);
- $result = civicrm_api('event', 'create', $this->_params);
+ $result = $this->callAPIFailure('event', 'create', $this->_params);
$this->assertAPIFailure($result);
}
function testCreateEventParamsWithoutEventTypeId() {
unset($this->_params['event_type_id']);
- $result = civicrm_api('event', 'create', $this->_params);
- $this->assertAPIFailure($result);
+ $result = $this->callAPIFailure('event', 'create', $this->_params);
}
function testCreateEventParamsWithoutStartDate() {
unset($this->_params['start_date']);
- $result = civicrm_api('event', 'create', $this->_params);
- $this->assertAPIFailure($result);
+ $result = $this->callAPIFailure('event', 'create', $this->_params);
}
function testCreateEventSuccess() {
- $result = civicrm_api('Event', 'Create', $this->_params[0]);
- $this->documentMe($this->_params[0], $result, __FUNCTION__, __FILE__);
- $this->assertAPISuccess($result);
+ $result = $this->callAPIAndDocument('Event', 'Create', $this->_params[0], __FUNCTION__, __FILE__);
$this->assertArrayHasKey('id', $result['values'][$result['id']], 'In line ' . __LINE__);
- $result = civicrm_api($this->_entity, 'Get', array('version' => 3, 'id' => $result['id']));
- civicrm_api($this->_entity, 'Delete', array('version' => 3, 'id' => $result['id']));
-
+ $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
$this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__);
$this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__);
$this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__);
$this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__);
- civicrm_api($this->_entity, 'Delete', array('version' => 3, 'id' => $result['id']));
}
/*
* Test that passing in Unique field names works
unset($this->_params[1]['start_date']);
$this->_params[0]['event_title'] = $this->_params[0]['title'];
unset($this->_params[0]['title']);
- $result = civicrm_api('Event', 'Create', $this->_params[0]);
+ $result = $this->callAPISuccess('Event', 'Create', $this->_params[0]);
$this->assertAPISuccess($result, 'In line ' . __LINE__);
$this->assertArrayHasKey('id', $result['values'][$result['id']], 'In line ' . __LINE__);
- $result = civicrm_api($this->_entity, 'Get', array('version' => 3, 'id' => $result['id']));
- civicrm_api($this->_entity, 'Delete', array('version' => 3, 'id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
$this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__);
$this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__);
$this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__);
$this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__);
$this->assertEquals($this->_params[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__);
-
- civicrm_api($this->_entity, 'Delete', array('version' => 3, 'id' => $result['id']));
}
function testUpdateEvent() {
- $result = civicrm_api('event', 'create', $this->_params[1]);
+ $result = $this->callAPISuccess('event', 'create', $this->_params[1]);
- $this->assertAPISuccess($result);
$params = array(
- 'id' => $result['id'], 'version' => 3, 'max_participants' => 150,
+ 'id' => $result['id'], 'max_participants' => 150,
);
- civicrm_api('Event', 'Create', $params);
- $updated = civicrm_api('Event', 'Get', $params);
- $this->documentMe($this->_params, $updated, __FUNCTION__, __FILE__);
- $this->assertEquals($updated['is_error'], 0);
+ $this->callAPISuccess('Event', 'Create', $params);
+ $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
$this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
- civicrm_api($this->_entity, 'Delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
}
- ///////////////// civicrm_event_delete methods
- function testDeleteWrongParamsType() {
- $params = 'Annual CiviCRM meet';
- $result = $this->callAPIFailure('Event', 'Delete', $params);
- }
function testDeleteEmptyParams() {
- $params = array();
- $result = $this->callAPIFailure('Event', 'Delete', $params);
+ $result = $this->callAPIFailure('Event', 'Delete', array());
}
function testDelete() {
$params = array(
'id' => $this->_eventIds[0],
- 'version' => $this->_apiversion,
);
- $result = civicrm_api('Event', 'Delete', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
- $this->assertNotEquals($result['is_error'], 1);
+ $result = $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__, __FILE__);
}
- /*
- * check event_id still supported for delete
- */
+
+ /**
+ * check event_id still supported for delete
+ */
function testDeleteWithEventId() {
$params = array(
- 'event_id' => $this->_eventIds[0],
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('Event', 'Delete', $params);
+ 'event_id' => $this->_eventIds[0], );
+ $result = $this->callAPISuccess('Event', 'Delete', $params);
$this->assertAPISuccess($result, 'in line ' . __LINE__);
}
/*
* Trying to delete an event with participants should return error
*/
function testDeleteWithExistingParticipant() {
- $contactID = $this->individualCreate(NULL);
+ $contactID = $this->individualCreate();
$participantID = $this->participantCreate(
array(
'contactID' => $contactID,
'eventID' => $this->_eventIds[0],
)
);
- $result = civicrm_api('Event', 'Delete', array('version' => $this->_apiversion, 'id' => $this->_eventIds[0]));
- $this->assertEquals(0, $result['is_error'], "Deleting exist with participants");
+ $result = $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0]));
}
function testDeleteWithWrongEventId() {
- $params = array('event_id' => $this->_eventIds[0], 'version' => $this->_apiversion);
- $result = civicrm_api('Event', 'Delete', $params);
+ $params = array('event_id' => $this->_eventIds[0]);
+ $result = $this->callAPISuccess('Event', 'Delete', $params);
// try to delete again - there's no such event anymore
$params = array('event_id' => $this->_eventIds[0]);
$result = $this->callAPIFailure('Event', 'Delete', $params);
* Test civicrm_event_search with empty params
*/
function testSearchEmptyParams() {
- $event = civicrm_api('event', 'create', $this->_params[1]);
+ $event = $this->callAPISuccess('event', 'create', $this->_params[1]);
- $getparams = array(
- 'version' => $this->_apiversion,
- 'sequential' => 1,
+ $getparams = array( 'sequential' => 1,
);
- $result = civicrm_api('event', 'get', $getparams);
+ $result = $this->callAPISuccess('event', 'get', $getparams);
$this->assertEquals($result['count'], 3, 'In line ' . __LINE__);
$res = $result['values'][0];
$this->assertArrayKeyExists('title', $res, 'In line ' . __LINE__);
'event_type_id' => 1,
'return.title' => 1,
'return.id' => 1,
- 'return.start_date' => 1,
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('event', 'get', $params);
+ 'return.start_date' => 1, );
+ $result = $this->callAPISuccess('event', 'get', $params);
$this->assertEquals($result['values'][$this->_eventIds[0]]['id'], $this->_eventIds[0], 'In line ' . __LINE__);
$this->assertEquals($result['values'][$this->_eventIds[0]]['title'], 'Annual CiviCRM meet', 'In line ' . __LINE__);
$maxEvents = 5;
$events = array();
while ($maxEvents > 0) {
- $params = array(
- 'version' => $this->_apiversion,
- 'title' => 'Test Event' . $maxEvents,
+ $params = array( 'title' => 'Test Event' . $maxEvents,
'event_type_id' => 2,
'start_date' => 20081021,
);
- $events[$maxEvents] = civicrm_api('event', 'create', $params);
+ $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
$maxEvents--;
}
- $params = array(
- 'version' => $this->_apiversion,
- 'event_type_id' => 2,
+ $params = array( 'event_type_id' => 2,
'return.id' => 1,
'return.title' => 1,
'return.offset' => 2,
'return.max_results' => 2,
);
- $result = civicrm_api('event', 'get', $params);
+ $result = $this->callAPISuccess('event', 'get', $params);
$this->assertAPISuccess($result);
$this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__);
}
function testEventCreationPermissions() {
$params = array(
- 'event_type_id' => 1, 'start_date' => '2010-10-03', 'title' => 'le cake is a tie', 'check_permissions' => TRUE,
- 'version' => $this->_apiversion,
- );
+ 'event_type_id' => 1, 'start_date' => '2010-10-03', 'title' => 'le cake is a tie', 'check_permissions' => TRUE, );
$config = &CRM_Core_Config::singleton();
$config->userPermissionClass->permissions = array('access CiviCRM');
$result = $this->callAPIFailure('event', 'create', $params);
- $this->assertEquals('API permission check failed for event/create call; missing permission: access CiviEvent.', $result['error_message'], 'lacking permissions should not be enough to create an event');
+ $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');
$config->userPermissionClass->permissions = array('access CiviEvent', 'edit all events', 'access CiviCRM');
- $result = civicrm_api('event', 'create', $params);
- $this->assertEquals(0, $result['is_error'], 'overfluous permissions should be enough to create an event');
+ $result = $this->callAPISuccess('event', 'create', $params);
}
function testgetfields() {
$description = "demonstrate use of getfields to interogate api";
- $params = array('version' => 3, 'action' => 'create');
- $result = civicrm_api('event', 'getfields', $params);
+ $params = array('action' => 'create');
+ $result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals(1, $result['values']['title']['api.required'], 'in line ' . __LINE__);
}
/*
*/
function testgetfieldsRest() {
$description = "demonstrate use of getfields to interogate api";
- $params = array('version' => 3, 'api_action' => 'create');
- $result = civicrm_api('event', 'getfields', $params);
+ $params = array('api_action' => 'create');
+ $result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals(1, $result['values']['title']['api.required'], 'in line ' . __LINE__);
}
function testgetfieldsGet() {
$description = "demonstrate use of getfields to interogate api";
- $params = array('version' => 3, 'action' => 'get');
- $result = civicrm_api('event', 'getfields', $params);
+ $params = array('action' => 'get');
+ $result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals('title', $result['values']['event_title']['name'], 'in line ' . __LINE__);
}
function testgetfieldsDelete() {
$description = "demonstrate use of getfields to interogate api";
- $params = array('version' => 3, 'action' => 'delete');
- $result = civicrm_api('event', 'getfields', $params);
+ $params = array('action' => 'delete');
+ $result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals(1, $result['values']['id']['api.required']);
}
}