CRM-13072 more test upgrades
authoreileen <eileen@fuzion.co.nz>
Sat, 27 Jul 2013 11:58:38 +0000 (23:58 +1200)
committereileen <eileen@fuzion.co.nz>
Sat, 27 Jul 2013 11:58:38 +0000 (23:58 +1200)
tests/phpunit/api/v3/EventTest.php
tests/phpunit/api/v3/GrantTest.php
tests/phpunit/api/v3/PhoneTest.php
tests/phpunit/api/v3/PriceFieldValueTest.php
tests/phpunit/api/v3/PriceSetTest.php
tests/phpunit/api/v3/UtilsTest.php

index 7dce54a32a29a90a10da71b236cb1b51d69a3a83..0c1819b2e6a8444886e99b27343c4d6d2b02ad61 100644 (file)
@@ -62,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',
@@ -80,7 +79,6 @@ class api_v3_EventTest extends CiviUnitTestCase {
         'is_monetory' => 0,
         'is_active' => 1,
         'is_show_location' => 0,
-        'version' => $this->_apiversion,
       ),
     );
 
@@ -88,15 +86,11 @@ 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();
@@ -112,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',
@@ -132,10 +117,8 @@ class api_v3_EventTest extends CiviUnitTestCase {
 
   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');
   }
 
@@ -153,39 +136,31 @@ class api_v3_EventTest extends CiviUnitTestCase {
 
   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__);
 
 
@@ -197,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);
   }
   */
 
@@ -236,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");
   }
 
@@ -256,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__);
 
@@ -292,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__);
+    $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
 
@@ -316,12 +281,12 @@ class api_v3_EventTest extends CiviUnitTestCase {
 
     $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() {
@@ -336,35 +301,29 @@ class api_v3_EventTest extends CiviUnitTestCase {
 
   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
@@ -374,66 +333,51 @@ 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->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->callAPIAndDocument('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__);
   }
   /*
@@ -447,13 +391,12 @@ class api_v3_EventTest extends CiviUnitTestCase {
         '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);
@@ -473,13 +416,11 @@ class api_v3_EventTest extends CiviUnitTestCase {
    *  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__);
@@ -494,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__);
@@ -511,48 +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 = $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');
 
     $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__);
   }
   /*
@@ -560,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']);
   }
 }
index 6dadf96baa0e917b070e655597f33f32dd5ee611..92ebf565a97754a8ac3d1c6761f2e37fa778fc54 100644 (file)
@@ -47,8 +47,7 @@ class api_v3_GrantTest extends CiviUnitTestCase {
     parent::setUp();
     $this->ids['contact'][0] = $this->individualCreate();
     $this->params = array(
-      'version' => 3,
-      'contact_id' => $this->ids['contact'][0],
+           'contact_id' => $this->ids['contact'][0],
       'application_received_date' => 'now',
       'decision_date' => 'next Monday',
       'amount_total' => '500',
@@ -62,37 +61,32 @@ class api_v3_GrantTest extends CiviUnitTestCase {
   function tearDown() {
     foreach ($this->ids as $entity => $entities) {
       foreach ($entities as $id) {
-        civicrm_api($entity, 'delete', array('version' => $this->_apiversion, 'id' => $id));
+        $this->callAPISuccess($entity, 'delete', array( 'id' => $id));
       }
     }
   }
 
   public function testCreateGrant() {
-    $result = civicrm_api($this->_entity, 'create', $this->params);
-    $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
     $this->getAndCheck($this->params, $result['id'], $this->_entity);
   }
 
   public function testGetGrant() {
-    $result = civicrm_api($this->_entity, 'create', $this->params);
+    $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
     $this->ids['grant'][0] = $result['id'];
-    $result = civicrm_api($this->_entity, 'get', array('version' => $this->_apiversion, 'rationale' => 'Just Because'));
-    $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'get', array('rationale' => 'Just Because'), __FUNCTION__, __FILE__);
     $this->assertAPISuccess($result, 'In line ' . __LINE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
   }
 
   public function testDeleteGrant() {
-    $result = civicrm_api($this->_entity, 'create', $this->params);
-    $result = civicrm_api($this->_entity, 'delete', array('version' => 3, 'id' => $result['id']));
-    $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
+    $result = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
     $this->assertAPISuccess($result, 'In line ' . __LINE__);
-    $checkDeleted = civicrm_api($this->_entity, 'get', array(
-      'version' => 3,
-      ));
+    $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array(
+           ));
     $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
   }
   /*
@@ -106,9 +100,8 @@ class api_v3_GrantTest extends CiviUnitTestCase {
   public function testCreateAutoGrant() {
     $entityName = $this->_entity;
     $baoString  = 'CRM_Grant_BAO_Grant';
-    $fields     = civicrm_api($entityName, 'getfields', array(
-        'version' => 3,
-        'action' => 'create',
+    $fields     = $this->callAPISuccess($entityName, 'getfields', array(
+               'action' => 'create',
       )
     );
 
@@ -116,9 +109,8 @@ class api_v3_GrantTest extends CiviUnitTestCase {
     $return = array_keys($fields);
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
-    $getentities = civicrm_api($entityName, 'get', array(
-        'version' => 3,
-        'sequential' => 1,
+    $getentities = $this->callAPISuccess($entityName, 'get', array(
+               'sequential' => 1,
         'return' => $return,
       ));
 
@@ -167,20 +159,18 @@ class api_v3_GrantTest extends CiviUnitTestCase {
           $entity[$field] = 'warm.beer.com';
       }
       $updateParams = array(
-        'version' => 3,
-        'id' => $entity['id'],
+               'id' => $entity['id'],
          $field => $entity[$field],
         'debug' => 1,
       );
-      $update = civicrm_api($entityName, 'create', $updateParams);
+      $update = $this->callAPISuccess($entityName, 'create', $updateParams);
       $this->assertAPISuccess($update, "setting $field to {$entity[$field]} in line " . __LINE__);
       $checkParams = array(
         'id' => $entity['id'],
-        'version' => 3,
         'sequential' => 1,
       );
-      $checkEntity = civicrm_api($entityName, 'getsingle', $checkParams);
-      $this->assertEquals($entity, $checkEntity, "changing field $field");
+      $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
+      $this->assertAPIArrayComparison((array) $entity, $checkEntity);
     }
     $baoObj->deleteTestObjects($baoString);
     $baoObj->free();
index 3e22656c8a262fd8cb73c1fe9200dbccdcf12e03..9ac44dd07c6dbf3a77fa55c639d96f1a3044180d 100644 (file)
@@ -56,7 +56,6 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
       'location_type_id' => $this->_locationType,
       'phone' => '(123) 456-7890',
       'is_primary' => 1,
-      'version' => $this->_apiversion,
       'phone_type_id' => 1,
     );
   }
@@ -68,53 +67,31 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
 
   public function testCreatePhone() {
 
-    $result = civicrm_api('phone', 'create', $this->_params);
-
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('phone', 'create', $this->_params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
 
-    // $this->assertEquals( 1, $result['id'], 'In line ' . __LINE__ );
-
-    $delresult = civicrm_api('phone', 'delete', array('id' => $result['id'], 'version' => $this->_apiversion));
-    $this->assertEquals(0, $delresult['is_error'], 'In line ' . __LINE__);
+    $this->callAPISuccess('phone', 'delete', array('id' => $result['id']));
   }
 
   public function testDeletePhone() {
     //create one
-    $create = civicrm_api('phone', 'create', $this->_params);
-
-    $this->assertAPISuccess($create, 'In line ' . __LINE__);
+    $create = $this->callAPISuccess('phone', 'create', $this->_params);
 
-    $result = civicrm_api('phone', 'delete', array('id' => $create['id'], 'version' => $this->_apiversion));
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('phone', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
-    $get = civicrm_api('phone', 'get', array(
-      'version' => $this->_apiversion, 'id' => $create['id'],
-        'location_type_id' => $this->_locationType,
-      ));
-    $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__);
+    $get = $this->callAPISuccess('phone', 'get', array(
+      'id' => $create['id'],
+      'location_type_id' => $this->_locationType,
+    ));
     $this->assertEquals(0, $get['count'], 'Phone not successfully deleted In line ' . __LINE__);
   }
 
-  /**
-   * Test civicrm_phone_get with wrong params type.
-   */
-  public function testGetWrongParamsType() {
-    $params = 'is_string';
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
-  }
-
   /**
    * Test civicrm_phone_get with empty params.
    */
   public function testGetEmptyParams() {
-    $params = array('version' => $this->_apiversion);
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('Phone', 'Get', array());
   }
 
   /**
@@ -122,9 +99,7 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
    */
   public function testGetWrongParams() {
     $this->callAPIFailure('Phone', 'Get', array('contact_id' => 'abc'));
-
     $this->callAPIFailure('Phone', 'Get', array('location_type_id' => 'abc'));
-
     $this->callAPIFailure('Phone', 'Get', array('phone_type_id' => 'abc'));
   }
 
@@ -136,11 +111,8 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
     $params = array(
       'contact_id' =>  $this->_params['contact_id'],
       'phone' => $phone['values'][$phone['id']]['phone'],
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('Phone', 'Get', $params, __FUNCTION__, __FILE__);
     $this->assertEquals($phone['values'][$phone['id']]['location_type_id'], $result['values'][$phone['id']]['location_type_id'], 'In line ' . __LINE__);
     $this->assertEquals($phone['values'][$phone['id']]['phone_type_id'], $result['values'][$phone['id']]['phone_type_id'], 'In line ' . __LINE__);
     $this->assertEquals($phone['values'][$phone['id']]['is_primary'], $result['values'][$phone['id']]['is_primary'], 'In line ' . __LINE__);
@@ -149,23 +121,14 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
 
   ///////////////// civicrm_phone_create methods
 
-  /**
-   * Test civicrm_phone_create with wrong params type.
-   */
-  public function testCreateWrongParamsType() {
-    $params = 'a string';
-    $result = $this->callAPIFailure('Phone', 'Create', $params);
-  }
-
   /**
    * Ensure numeric_phone field is correctly populated (this happens via sql trigger)
    */
   public function testNumericPhone() {
-    $result = civicrm_api('phone', 'create', $this->_params);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('phone', 'create', $this->_params);
     $id = $result['id'];
-    $params = array('id' => $id, 'version' => $this->_apiversion, 'return.phone_numeric' => 1);
-    $result = civicrm_api('phone', 'get', $params);
+    $params = array('id' => $id, 'return.phone_numeric' => 1);
+    $result = $this->callAPISuccess('phone', 'get', $params);
     $this->assertEquals('1234567890', $result['values'][$id]['phone_numeric']);
   }
 
@@ -177,26 +140,21 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
   public function testCreatePhonePrimaryHandlingChangeToPrimary() {
     $params = $this->_params;
     unset($params['is_primary']);
-    $phone1 = civicrm_api('phone', 'create', $params);
-    $this->assertApiSuccess($phone1, 'In line ' . __LINE__);
+    $phone1 = $this->callAPISuccess('phone', 'create', $params);
     //now we check & make sure it has been set to primary
-    $check = civicrm_api('phone', 'getcount', array(
-        'version' => 3,
+    $check = $this->callAPISuccess('phone', 'getcount', array(
         'is_primary' => 1,
         'id' => $phone1['id'],
       ));
     $this->assertEquals(1, $check);
   }
   public function testCreatePhonePrimaryHandlingChangeExisting() {
-    $phone1 = civicrm_api('phone', 'create', $this->_params);
-    $this->assertApiSuccess($phone1, 'In line ' . __LINE__);
-    $phone2 = civicrm_api('phone', 'create', $this->_params);
-    $this->assertApiSuccess($phone2, 'In line ' . __LINE__);
-    $check = civicrm_api('phone', 'getcount', array(
-        'version' => 3,
-        'is_primary' => 1,
-        'contact_id' => $this->_contactID,
-      ));
+    $phone1 = $this->callAPISuccess('phone', 'create', $this->_params);
+    $phone2 = $this->callAPISuccess('phone', 'create', $this->_params);
+    $check = $this->callAPISuccess('phone', 'getcount', array(
+      'is_primary' => 1,
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(1, $check);
   }
 }
index e9018af544045856ccfd1a4b6d2461327ffdf36b..aad09910ca59f21da007780728dc648cb506aa52 100644 (file)
@@ -40,7 +40,6 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
     parent::setUp();
     // put stuff here that should happen before all tests in this unit
     $priceSetparams = array(
-      'version' => 3,
       #     [domain_id] =>
       'name' => 'default_goat_priceset',
       'title' => 'Goat accomodation',
@@ -53,11 +52,10 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_reserved' => 1,
     );
 
-    $price_set = civicrm_api('price_set', 'create',$priceSetparams);
+    $price_set = $this->callAPISuccess('price_set', 'create',$priceSetparams);
     $this->priceSetID = $price_set['id'];
 
     $priceFieldparams = array(
-      'version' => $this->_apiversion,
       'price_set_id' => $this->priceSetID,
       'name' => 'grassvariety',
       'label' => 'Grass Variety',
@@ -65,10 +63,9 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_enter_qty' => 1,
       'is_active' => 1,
     );
-    $priceField = civicrm_api('price_field','create', $priceFieldparams);
+    $priceField = $this->callAPISuccess('price_field','create', $priceFieldparams);
     $this->priceFieldID = $priceField['id'];
     $this->_params = array(
-      'version' => 3,
       'price_field_id' => $this->priceFieldID,
       'name' => 'ryegrass',
       'label' => 'juicy and healthy',
@@ -78,7 +75,6 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
     $membershipOrgId = $this->organizationCreate(NULL);
     $this->_membershipTypeID = $this->membershipTypeCreate($membershipOrgId);
     $priceSetparams1 = array(
-      'version' => $this->_apiversion,
       'name' => 'priceset',
       'title' => 'Priceset with Multiple Terms',
       'is_active' => 1,
@@ -87,10 +83,9 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_quick_config' => 1,
       'is_reserved' => 1,
     );
-    $price_set1 = civicrm_api('price_set', 'create',$priceSetparams1);
+    $price_set1 = $this->callAPISuccess('price_set', 'create',$priceSetparams1);
     $this->priceSetID1 = $price_set1['id'];
     $priceFieldparams1 = array(
-      'version' => $this->_apiversion,
       'price_set_id' => $this->priceSetID1,
       'name' => 'memtype',
       'label' => 'memtype',
@@ -98,7 +93,7 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_enter_qty' => 1,
       'is_active' => 1,
     );
-    $priceField1 = civicrm_api('price_field','create', $priceFieldparams1);
+    $priceField1 = $this->callAPISuccess('price_field','create', $priceFieldparams1);
     $this->priceFieldID1 = $priceField1['id'];
   }
 
@@ -109,20 +104,16 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
     );
     $this->quickCleanup($tablesToTruncate);
     $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
-    civicrm_api('PriceField','delete', array(
-        'version' => 3,
+    $this->callAPISuccess('PriceField','delete', array(
         'id' => $this->priceFieldID1,
     ));
-    civicrm_api('PriceSet','delete', array(
-      'version' => 3,
+    $this->callAPISuccess('PriceSet','delete', array(
       'id' => $this->priceSetID1,
     ));
-    civicrm_api('PriceField','delete', array(
-        'version' => 3,
+    $this->callAPISuccess('PriceField','delete', array(
         'id' => $this->priceFieldID,
     ));
-    $delete = civicrm_api('PriceSet','delete', array(
-      'version' => 3,
+    $delete = $this->callAPISuccess('PriceSet','delete', array(
       'id' => $this->priceSetID,
     ));
 
@@ -130,9 +121,7 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
   }
 
   public function testCreatePriceFieldValue() {
-    $result = civicrm_api($this->_entity, 'create', $this->_params);
-    $this->id = $result['id'];
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
     $this->assertAPISuccess($result, 'In line ' . __LINE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
@@ -140,44 +129,34 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
   }
 
   public function testGetBasicPriceFieldValue() {
-    $createResult = civicrm_api($this->_entity, 'create', $this->_params);
+    $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
     $this->id = $createResult['id'];
     $this->assertAPISuccess($createResult);
     $getParams = array(
-      'version' => $this->_apiversion,
       'name' => 'contribution_amount',
     );
-    $getResult = civicrm_api($this->_entity, 'get', $getParams);
-    $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($getResult, 'In line ' . __LINE__);
+    $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
-    civicrm_api('price_field_value','delete', array('version' => 3, 'id' => $createResult['id']));
+    $this->callAPISuccess('price_field_value','delete', array('id' => $createResult['id']));
   }
 
   public function testDeletePriceFieldValue() {
-    $startCount = civicrm_api($this->_entity, 'getcount', array(
-      'version' => $this->_apiversion,
-      ));
-    $createResult = civicrm_api($this->_entity, 'create', $this->_params);
-    $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']);
-    $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams);
-    $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__);
-    $endCount = civicrm_api($this->_entity, 'getcount', array(
-      'version' => $this->_apiversion,
-      ));
+    $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+    $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+    $deleteParams = array('id' => $createResult['id']);
+    $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
+
+    $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
     $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__);
   }
 
   public function testGetFieldsPriceFieldValue() {
-    $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create'));
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
     $this->assertEquals(1, $result['values']['max_value']['type']);
   }
 
   public function testCreatePriceFieldValuewithMultipleTerms() {
     $params = array(
-      'version' => 3,
       'price_field_id' => $this->priceFieldID1,
       'membership_type_id' =>  $this->_membershipTypeID,
       'name' => 'memType1',
@@ -187,16 +166,13 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_active' => 1,
       'financial_type_id' => 2,
      );
-    $result = civicrm_api($this->_entity, 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
     $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
-    civicrm_api($this->_entity, 'delete', array('version' => 3, 'id' => $result['id']));
+    $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
   }
   public function testGetPriceFieldValuewithMultipleTerms() {
     $params1 = array(
-      'version' => 3,
       'price_field_id' => $this->priceFieldID1,
       'membership_type_id' =>  $this->_membershipTypeID,
       'name' => 'memType1',
@@ -207,7 +183,6 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'financial_type_id' => 2,
      );
     $params2 = array(
-      'version' => 3,
       'price_field_id' => $this->priceFieldID1,
       'membership_type_id' =>  $this->_membershipTypeID,
       'name' => 'memType2',
@@ -217,13 +192,12 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_active' => 1,
       'financial_type_id' => 2,
      );
-    $result1 = civicrm_api($this->_entity, 'create', $params1);
-    $result2 = civicrm_api($this->_entity, 'create', $params2);
-    $result = civicrm_api($this->_entity, 'get', array( 'version' => 3, 'price_field_id' =>$this->priceFieldID1 ));
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result1 = $this->callAPISuccess($this->_entity, 'create', $params1);
+    $result2 = $this->callAPISuccess($this->_entity, 'create', $params2);
+    $result = $this->callAPISuccess($this->_entity, 'get', array('price_field_id' =>$this->priceFieldID1 ));
     $this->assertEquals(2, $result['count'], 'In line ' . __LINE__);
-    civicrm_api($this->_entity,'delete', array('version' => 3, 'id' => $result1['id']));
-    civicrm_api($this->_entity,'delete', array('version' => 3, 'id' => $result2['id']));
+    $this->callAPISuccess($this->_entity,'delete', array('id' => $result1['id']));
+    $this->callAPISuccess($this->_entity,'delete', array('id' => $result2['id']));
   }
 }
 
index d1ce89269eb77ea0c2dc21787c0af20ba51ff7d4..43ae55b48eeffc58f3882487c0f10ec38eda9a6c 100644 (file)
@@ -38,7 +38,6 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
   public function setUp() {
     parent::setUp();
     $this->_params = array(
-      'version' => $this->_apiversion,
 #     [domain_id] =>
       'name' => 'default_goat_priceset',
       'title' => 'Goat accessories',
@@ -56,10 +55,7 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
   }
 
   public function testCreatePriceSet() {
-    $result = civicrm_api($this->_entity, 'create', $this->_params);
-    $this->id = $result['id'];
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
     $this->getAndCheck($this->_params, $result['id'], $this->_entity);
@@ -67,18 +63,14 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
 
   public function testGetBasicPriceSet() {
     $getParams = array(
-      'version' => $this->_apiversion,
       'name' => 'default_contribution_amount',
     );
-    $getResult = civicrm_api($this->_entity, 'get', $getParams);
-    $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($getResult, 'In line ' . __LINE__);
+    $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
   }
 
   public function testEventPriceSet() {
-    $event = civicrm_api('event', 'create', array(
-      'version' => $this->_apiversion,
+    $event = $this->callAPISuccess('event', 'create', array(
       'title' => 'Event with Price Set',
       'event_type_id' => 1,
       'is_public' => 1,
@@ -86,44 +78,31 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
       'end_date' => 20151023,
       'is_active' => 1,
     ));
-    $this->assertAPISuccess($event);
     $createParams = array(
-      'version' => $this->_apiversion,
       'entity_table' => 'civicrm_event',
       'entity_id' => $event['id'],
       'name' => 'event price',
       'title' => 'event price',
       'extends' => 1,
     );
-    $createResult = civicrm_api($this->_entity, 'create', $createParams);
-    $this->documentMe($createParams, $createResult, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($createResult, 'In line ' . __LINE__);
-    $id = $createResult['id'];
-    $result = civicrm_api($this->_entity, 'get', array(
-      'version' => $this->_apiversion,
-      'id' => $id,
+    $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
+    $result = $this->callAPISuccess($this->_entity, 'get', array(
+      'id' => $createResult['id'],
     ));
-    $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$id]['entity'], 'In line ' . __LINE__);
+    $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity'], 'In line ' . __LINE__);
   }
 
   public function testDeletePriceSet() {
-    $startCount = civicrm_api($this->_entity, 'getcount', array(
-      'version' => $this->_apiversion,
-      ));
-    $createResult = civicrm_api($this->_entity, 'create', $this->_params);
-    $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']);
-    $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams);
-    $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__);
-    $endCount = civicrm_api($this->_entity, 'getcount', array(
-      'version' => $this->_apiversion,
-      ));
+    $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+    $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+    $deleteParams = array('id' => $createResult['id']);
+    $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
+    $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
     $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__);
   }
 
   public function testGetFieldsPriceSet() {
-    $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create'));
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
     $this->assertEquals(16, $result['values']['is_quick_config']['type']);
   }
 
index 787ff6e1fb05d819e61bbed5d82071fc0ba39bb7..548cbfc88921bae76aecb92ca328936334167615 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
@@ -35,7 +34,7 @@ require_once 'CRM/Utils/DeprecatedUtils.php';
  * @package   CiviCRM
  */
 class api_v3_UtilsTest extends CiviUnitTestCase {
-  protected $_apiversion;
+  protected $_apiversion = 3;
   public $DBResetRequired = FALSE;
   public $_eNoticeCompliant = TRUE;
   public $_contactID = 1;
@@ -48,7 +47,6 @@ class api_v3_UtilsTest extends CiviUnitTestCase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->_apiversion = 3;
   }
 
   /**
@@ -119,7 +117,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase {
       'contact_id' => $this->_contactID,
       'modified_date' => '2011-01-31',
       'subject' => NULL,
-      'version' => $this->_apiversion,
+      'version' => $this->_apiversion
     );
     try {
       $result = civicrm_api3_verify_mandatory($params, 'CRM_Core_BAO_Note', array('note', 'subject'));
@@ -162,7 +160,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase {
      */
   function testVerifyOneMandatoryOneSet() {
     _civicrm_api3_initialize(TRUE);
-    $params = array('entity_table' => 'civicrm_contact', 'note' => 'note', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => NULL, 'version' => $this->_apiversion);
+    $params = array('version' => 3, 'entity_table' => 'civicrm_contact', 'note' => 'note', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => NULL);
 
     try {
       civicrm_api3_verify_one_mandatory($params, NULL, array('note', 'subject'));
@@ -247,22 +245,20 @@ class api_v3_UtilsTest extends CiviUnitTestCase {
   }
 
   function testGetFields() {
-    $result = civicrm_api('membership', 'getfields', array('version' => 3));
+    $result = $this->callAPISuccess('membership', 'getfields', array());
     $this->assertArrayHasKey('values', $result);
-    $result = civicrm_api('relationship', 'getfields', array('version' => 3));
+    $result = $this->callAPISuccess('relationship', 'getfields', array());
     $this->assertArrayHasKey('values', $result);
-    $result = civicrm_api('event', 'getfields', array('version' => 3));
+    $result = $this->callAPISuccess('event', 'getfields', array());
     $this->assertArrayHasKey('values', $result);
   }
 
   function testGetFields_AllOptions() {
-    $result = civicrm_api('contact', 'getfields', array(
+    $result = $this->callAPISuccess('contact', 'getfields', array(
       'options' => array(
         'get_options' => 'all',
       ),
-      'version' => 3
     ));
-    $this->assertAPISuccess($result);
     $this->assertEquals('Household', $result['values']['contact_type']['options']['Household']);
     $this->assertEquals('HTML', $result['values']['preferred_mail_format']['options']['HTML']);
   }