Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / EventTest.php
index 0b1b4067c10d3909b9e8e4cc866a3045acd762e5..b8349e07ff1c71160462418fe473603139cf2172 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-// $Id$
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -32,7 +31,9 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 class api_v3_EventTest extends CiviUnitTestCase {
   protected $_params;
   protected $_apiversion;
-  protected $_entity; function get_info() {
+  protected $_entity;
+  public $_eNoticeCompliant = TRUE;
+  function get_info() {
     return array(
       'name' => 'Event Create',
       'description' => 'Test all Event Create API methods.',
@@ -61,7 +62,6 @@ class api_v3_EventTest extends CiviUnitTestCase {
         'is_monetary' => 0,
         'is_active' => 1,
         'is_show_location' => 0,
-        'version' => $this->_apiversion,
       ),
       array(
         'title' => 'Annual CiviCRM meet 2',
@@ -79,7 +79,6 @@ class api_v3_EventTest extends CiviUnitTestCase {
         'is_monetory' => 0,
         'is_active' => 1,
         'is_show_location' => 0,
-        'version' => $this->_apiversion,
       ),
     );
 
@@ -87,21 +86,17 @@ class api_v3_EventTest extends CiviUnitTestCase {
       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();
     $this->eventIds = array();
     foreach ($params as $event) {
-      $result            = civicrm_api('Event', 'Create', $event);
+      $result            = $this->callAPISuccess('Event', 'Create', $event);
       $this->_events[]   = $result;
       $this->_eventIds[] = $result['id'];
     }
@@ -111,15 +106,6 @@ class api_v3_EventTest extends CiviUnitTestCase {
     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',
@@ -128,26 +114,11 @@ class api_v3_EventTest extends CiviUnitTestCase {
   }
 
   ///////////////// civicrm_event_get methods
-  function testGetWrongParamsType() {
-    $params = 'Annual CiviCRM meet';
-    $result = civicrm_api('Event', 'Get', $params);
-
-    $this->assertEquals($result['is_error'], 1);
-  }
-
-  function testGetEventEmptyParams() {
-    $params = array();
-    $result = civicrm_api('event', 'get', $params);
-
-    $this->assertEquals($result['is_error'], 1);
-  }
 
   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');
   }
 
@@ -155,50 +126,41 @@ class api_v3_EventTest extends CiviUnitTestCase {
 
     $params = array(
       'event_title' => 'Annual CiviCRM meet',
-      'version' => $this->_apiversion,
+      'sequential' => TRUE,
     );
 
-    $result = civicrm_api('event', 'get', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count']);
-    $this->assertEquals($result['values'][0]['id'], $this->_eventIds[0]['id']);
+    $this->assertEquals($result['values'][0]['id'], $this->_eventIds[0]);
   }
 
   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(
+    $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__);
 
 
@@ -210,13 +172,11 @@ class api_v3_EventTest extends CiviUnitTestCase {
 
   /*
   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);
   }
   */
 
@@ -226,21 +186,18 @@ class api_v3_EventTest extends CiviUnitTestCase {
      */
   function testGetIsCurrent() {
     $params = array(
-      'version' => $this->_apiversion,
       'isCurrent' => 1,
     );
     $currentEventParams = array('start_date' => date('Y-m-d', strtotime('+ 1 day')),
       'end_date' => date('Y-m-d', strtotime('+ 1 week')),
     );
     $currentEventParams = array_merge($this->_params[1], $currentEventParams);
-    $currentEvent       = civicrm_api('Event', 'Create', $currentEventParams);
+    $currentEvent       = $this->callAPISuccess('Event', 'Create', $currentEventParams);
     $description        = "demonstrates use of is.Current option";
     $subfile            = "IsCurrentOption";
-    $result             = civicrm_api('Event', 'Get', $params);
-
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
-    $allEvents = civicrm_api('Event', 'Get', array('version' => 3));
-    civicrm_api('Event', 'Delete', array('version' => 3, 'id' => $currentEventParams['id']));
+    $result             = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
+    $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'], '');
@@ -252,9 +209,9 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $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");
   }
 
@@ -262,8 +219,7 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $params = $this->_params[0];
     $params['sequential'] =1;
     $params['loc_block_id'] =100;
-    $result = civicrm_api('event', 'create', $params);
-    $this->assertEquals(1, $result['is_error']);
+    $result = $this->callAPIFailure('event', 'create', $params);
 
   }
 
@@ -273,27 +229,21 @@ class api_v3_EventTest extends CiviUnitTestCase {
   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__);
 
@@ -309,13 +259,11 @@ class api_v3_EventTest extends CiviUnitTestCase {
       //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__);
-    $this->assertEquals($result['values'][$result['id']]['contribution_type_id'], 3);
+    $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
 
@@ -331,61 +279,51 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $params = $this->_params[0];
     $params['custom_' . $ids['custom_field_id']] = "custom string";
 
-    $result = civicrm_api($this->_entity, 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertNotEquals($result['is_error'], 1, $result['error_message'] . ' in line ' . __LINE__);
+    $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() {
     $params = NULL;
-    $result = civicrm_api('event', 'create', $params);
-    $this->assertEquals(1, $result['is_error']);
+    $result = $this->callAPIFailure('event', 'create', $params);
   }
 
   function testCreateEventEmptyParams() {
     $params = array();
-    $result = civicrm_api('event', 'create', $params);
-    $this->assertEquals($result['is_error'], 1);
+    $result = $this->callAPIFailure('event', 'create', $params);
   }
 
   function testCreateEventParamsWithoutTitle() {
     unset($this->_params['title']);
-    $result = civicrm_api('event', 'create', $this->_params);
-    $this->assertEquals($result['is_error'], 1);
+    $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->assertEquals($result['is_error'], 1);
+    $result = $this->callAPIFailure('event', 'create', $this->_params);
   }
 
   function testCreateEventParamsWithoutStartDate() {
     unset($this->_params['start_date']);
-    $result = civicrm_api('event', 'create', $this->_params);
-    $this->assertEquals($result['is_error'], 1);
+    $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->assertEquals($result['is_error'], 0);
+    $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
@@ -395,93 +333,73 @@ class api_v3_EventTest extends CiviUnitTestCase {
     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->assertEquals($result['is_error'], 0);
     $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 = civicrm_api('Event', 'Delete', $params);
-
-    $this->assertEquals($result['is_error'], 1);
-  }
 
   function testDeleteEmptyParams() {
-    $params = array();
-    $result = civicrm_api('Event', 'Delete', $params);
-    $this->assertEquals($result['is_error'], 1);
+    $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 = civicrm_api('Event', 'Delete', $params);
-    $this->assertEquals($result['is_error'], 1);
+    $result = $this->callAPIFailure('Event', 'Delete', $params);
   }
 
   ///////////////// civicrm_event_search methods
@@ -491,22 +409,18 @@ class api_v3_EventTest extends CiviUnitTestCase {
    */
   function testSearchWrongParamsType() {
     $params = 'a string';
-    $result = civicrm_api('event', 'get', $params);
-
-    $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__);
+    $result = $this->callAPIFailure('event', 'get', $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__);
@@ -521,10 +435,8 @@ class api_v3_EventTest extends CiviUnitTestCase {
       '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__);
@@ -538,49 +450,41 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $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 = civicrm_api('event', 'create', $params);
-    $this->assertEquals(1, $result['is_error'], 'lacking permissions should not be enough to create an event');
-    $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');
+    $result = $this->callAPIFailure('event', 'create', $params);
+    $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__);
   }
   /*
@@ -588,20 +492,20 @@ class api_v3_EventTest extends CiviUnitTestCase {
      */
   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']);
   }
 }