CRM-13072 upgrade additional test classes including fixing activity.type.delete
authoreileen <eileen@fuzion.co.nz>
Fri, 26 Jul 2013 07:12:09 +0000 (19:12 +1200)
committereileen <eileen@fuzion.co.nz>
Fri, 26 Jul 2013 07:12:09 +0000 (19:12 +1200)
api/v3/ActivityType.php
tests/phpunit/api/v3/ACLCachingTest.php
tests/phpunit/api/v3/ACLPermissionTest.php
tests/phpunit/api/v3/APIStandardsTest.php
tests/phpunit/api/v3/APITest.php
tests/phpunit/api/v3/ActivityTypeTest.php
tests/phpunit/api/v3/AddressTest.php
tests/phpunit/api/v3/CRM11793Test.php
tests/phpunit/api/v3/CampaignTest.php
tests/phpunit/api/v3/CaseTest.php

index cc92b29102ce34a3364371a50bd259fa410f1caa..50247e792ceac1f8524784cdc8e454462bd2b560 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
  * @access public
  *
  * @example ActivityTypeGet.php
- * @deprecated - use constant_get
+ * @deprecated - use getoptions
  */
 function civicrm_api3_activity_type_get($params) {
 
-
   $activityTypes = CRM_Core_OptionGroup::values('activity_type');
   return civicrm_api3_create_success($activityTypes, $params, 'activity_type', 'get');
 }
@@ -66,14 +64,10 @@ function civicrm_api3_activity_type_get($params) {
  *
  * @access public
  *
- *{@schema Activity/ActivityType.xml}
- *
- * {@example ActivityTypeCreate.php 0}
  * @deprecated - we will introduce OptionValue Create - plse consider helping with this if not done
  */
 function civicrm_api3_activity_type_create($params) {
 
-
   $action = 1;
   $groupParams = array('name' => 'activity_type');
 
@@ -101,21 +95,15 @@ function _civicrm_api3_activity_type_create_spec(&$params) {
 /**
  * Function to delete activity type
  *
- * @param activityTypeId int   activity type id to delete
- *
- * @return boolen
+ * @param array $params array including id of activity_type to delete
+
+ * @return array API result array
  *
  * @access public
  *
  * @deprecated - we will introduce OptionValue Delete- plse consider helping with this if not done
- * {@example ActivityTypeDelete.php 0}
  */
 function civicrm_api3_activity_type_delete($params) {
-
-  civicrm_api3_verify_mandatory($params, NULL, array('activity_type_id'));
-
-  $activityTypeId = $params['activity_type_id'];
-
-  return CRM_Core_BAO_OptionValue::del($activityTypeId);
+  return civicrm_api3_create_success(CRM_Core_BAO_OptionValue::del($params['id']), $params);
 }
 
index 1e41a1cc6139383060a20343e6c3ff0dd8e4329f..9571f4bc9517ee12795618504e9763028255d694 100644 (file)
@@ -38,8 +38,8 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 class api_v3_ACLCachingTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
   protected $_params;
-
   public $_eNoticeCompliant = TRUE;
+  public $DBResetRequired = FALSE;
 
   function setUp() {
     parent::setUp();
index dc81156619c57e712ce689f711388ba757edba26..a7b9c287b952f0e76b5d2f43849e724863cb956b 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
@@ -36,17 +35,16 @@ require_once 'CiviTest/CiviUnitTestCase.php';
  */
 
 class api_v3_ACLPermissionTest extends CiviUnitTestCase {
-  protected $_apiversion;
+  protected $_apiversion = 3;
   protected $_params;
   protected $hookClass = null;
+  public $DBResetRequired = FALSE;
 
   public $_eNoticeCompliant = TRUE;
 
   protected $_entity;
 
   function setUp() {
-    $this->_apiversion = 3;
-
     parent::setUp();
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject('CRM_Pledge_BAO_Pledge', array(), 1, 0);
@@ -73,13 +71,10 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
  */
   function testContactGetNoResultsHook(){
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
-    $result = civicrm_api('contact', 'get', array(
-      'version' => $this->_apiversion,
+    $result = $this->callAPISuccess('contact', 'get', array(
       'check_permissions' => 1,
       'return' => 'display_name',
     ));
-
-    $this->assertAPISuccess($result,"this should succeed but return no results. line " . __LINE__);
     $this->assertEquals(0, $result['count']);
   }
 
@@ -88,28 +83,23 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   */
   function testContactGetAllResultsHook(){
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-    $result = civicrm_api('contact', 'get', array(
-        'version' => $this->_apiversion,
+    $result = $this->callAPISuccess('contact', 'get', array(
         'check_permissions' => 1,
         'return' => 'display_name',
     ));
 
-    $this->assertAPISuccess($result,"this should succeed but return no results. line " . __LINE__);
     $this->assertEquals(2, $result['count']);
   }
   /**
    * Function just tests that an empty where hook returns the 2 expected results
   */
   function testContactGetPermissionHookNoDeleted(){
-    civicrm_api('contact', 'create', array('id' => 2, 'version' => $this->_apiversion, 'is_deleted' => 1));
+    $this->callAPISuccess('contact', 'create', array('id' => 2, 'is_deleted' => 1));
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-    $result = civicrm_api('contact', 'get', array(
-        'version' => $this->_apiversion,
+    $result = $this->callAPISuccess('contact', 'get', array(
         'check_permissions' => 1,
         'return' => 'display_name',
     ));
-
-    $this->assertAPISuccess($result,"this should succeed but return one results. line " . __LINE__);
     $this->assertEquals(1, $result['count']);
   }
 
@@ -119,12 +109,10 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   function testContactGetHookLimitingHook(){
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
 
-    $result = civicrm_api('contact', 'get', array(
-      'version' => $this->_apiversion,
+    $result = $this->callAPISuccess('contact', 'get', array(
       'check_permissions' => 1,
       'return' => 'display_name',
       ));
-    $this->assertAPISuccess($result, 'api call succeeded');
     $this->assertEquals(1, $result['count']);
   }
 
@@ -133,12 +121,10 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
  */
   function testContactGetHookLimitingHookDontCheck(){
     //
-    $result = civicrm_api('contact', 'get', array(
-        'version' => $this->_apiversion,
-        'check_permissions' => 0,
-        'return' => 'display_name',
+    $result = $this->callAPISuccess('contact', 'get', array(
+      'check_permissions' => 0,
+      'return' => 'display_name',
     ));
-    $this->assertAPISuccess($result, 'api call succeeded');
     $this->assertEquals(2, $result['count']);
   }
   /**
@@ -146,14 +132,12 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
    */
   function testContactGetIDFilter(){
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-    $result = civicrm_api('contact', 'get', array(
-      'version' => $this->_apiversion,
+    $result = $this->callAPISuccess('contact', 'get', array(
       'sequential' => 1,
       'id' => 2,
       'check_permissions' => 1,
     ));
 
-    $this->assertAPISuccess($result, 'api call succeeded');
     $this->assertEquals(1, $result['count']);
     $this->assertEquals(2, $result['id']);
   }
@@ -163,8 +147,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
  */
     function testContactGetAddressReturned(){
       $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
-      $fullresult = civicrm_api('contact', 'get', array(
-          'version' => $this->_apiversion,
+      $fullresult = $this->callAPISuccess('contact', 'get', array(
           'sequential' => 1,
       ));
       //return doesn't work for all keys - can't fix that here so let's skip ...
@@ -184,13 +167,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
         'worldregion_id',
         'world_region');
       $expectedReturnElements = array_diff(array_keys($fullresult['values'][0]),$elementsReturnDoesntSupport);
-      $result = civicrm_api('contact', 'get', array(
-          'version' => $this->_apiversion,
+      $result = $this->callAPISuccess('contact', 'get', array(
           'check_permissions' => 1,
           'return' => $expectedReturnElements,
           'sequential' => 1,
       ));
-      $this->assertAPISuccess($result, 'api call succeeded');
       $this->assertEquals(1, $result['count']);
       foreach ($expectedReturnElements as $element){
         $this->assertArrayHasKey($element, $result['values'][0]);
@@ -201,17 +182,14 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
     */
     function testContactGetPledgeIDNotReturned(){
       $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-      $fullresult = civicrm_api('contact', 'get', array(
-          'version' => $this->_apiversion,
+      $fullresult = $this->callAPISuccess('contact', 'get', array(
           'sequential' => 1,
       ));
-      $result = civicrm_api('contact', 'get', array(
-        'version' => $this->_apiversion,
+      $result = $this->callAPISuccess('contact', 'get', array(
         'check_permissions' => 1,
         'return' => 'pledge_id',
         'sequential' => 1,
       ));
-      $this->assertAPISuccess($result);
       $this->assertArrayNotHasKey('pledge_id', $result['values'][0]);
     }
 
@@ -220,17 +198,14 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
     */
     function testContactGetPledgeIDNotFiltered(){
       $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-      $fullresult = civicrm_api('contact', 'get', array(
-          'version' => $this->_apiversion,
+      $fullresult = $this->callAPISuccess('contact', 'get', array(
           'sequential' => 1,
       ));
-      $result = civicrm_api('contact', 'get', array(
-        'version' => $this->_apiversion,
+      $result = $this->callAPISuccess('contact', 'get', array(
         'check_permissions' => 1,
         'pledge_id' => 1,
         'sequential' => 1,
       ));
-      $this->assertAPISuccess($result, 'api call succeeded');
       $this->assertEquals(2, $result['count']);
     }
 
@@ -239,17 +214,16 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
     */
     function testContactGetPledgeNotChainable(){
       $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
-      $fullresult = civicrm_api('contact', 'get', array(
-          'version' => $this->_apiversion,
+      $fullresult = $this->callAPISuccess('contact', 'get', array(
           'sequential' => 1,
       ));
-      $result = civicrm_api('contact', 'get', array(
-          'version' => $this->_apiversion,
+      $result = $this->callAPIFailure('contact', 'get', array(
           'check_permissions' => 1,
           'api.pledge.get' => 1,
           'sequential' => 1,
-      ));
-      $this->assertEquals('Error in call to pledge_get : API permission check failed for pledge/get call; missing permission: access CiviCRM.', $result['error_message']);
+      ),
+      'Error in call to pledge_get : API permission check failed for pledge/get call; missing permission: access CiviCRM.'
+      );
     }
 
   /**
index 6697e43e78076c0d99fecd397c60729ac5ae290c..15fd69ecdbe3b07caa6f93091ae42b02ef484382 100644 (file)
@@ -114,16 +114,9 @@ class api_v3_APIStandardsTest extends CiviUnitTestCase {
             try {
                 $result = $function($params);
             } catch ( Exception $e ) {
-              $this->assertEquals("Input variable `params` is not an array", $e->getMessage());
               continue;
             }
 
-            $this->assertEquals(1,
-                                $result['is_error'],
-                                $function . " does not return error in line " . __LINE__);
-            $this->assertEquals('Input variable `params` is not an array',
-                                $result['error_message'],
-                                "$function does not return correct error when a non-array is submitted in line " . __LINE__ );
         }*/
   }
 
index 066380e4f9f87484bf11b94f378f703f30be8770..44ae5690b28df0e8b16b172b6700bdbb7f19677d 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
@@ -38,7 +37,7 @@ class api_v3_APITest extends CiviUnitTestCase {
   public $DBResetRequired = FALSE;
   public $_eNoticeCompliant = TRUE;
 
-  protected $_apiversion;
+  protected $_apiversion =3;
 
   /**
    * Sets up the fixture, for example, opens a network connection.
@@ -48,7 +47,6 @@ class api_v3_APITest extends CiviUnitTestCase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->_apiversion = 3;
   }
 
   /**
@@ -95,40 +93,26 @@ class api_v3_APITest extends CiviUnitTestCase {
   function testAPIWrapperIncludeNoFile() {
 
 
-    $result = civicrm_api('RandomFile', 'get', array('version' => 3));
-    $this->assertAPIFailure($result);
-    $this->assertEquals($result['error_message'], 'API (RandomFile,get) does not exist (join the API team and implement it!)');
+    $result = $this->callAPIFailure('RandomFile', 'get', array(), 'API (RandomFile,get) does not exist (join the API team and implement it!)');
   }
 
   function testAPIWrapperCamelCaseFunction() {
-    $result = civicrm_api('OptionGroup', 'Get', array(
-      'version' => 3,
-      ));
-    $this->assertEquals(0, $result['is_error']);
+    $result = $this->callAPISuccess('OptionGroup', 'Get', array());
   }
 
   function testAPIWrapperLcaseFunction() {
-    $result = civicrm_api('OptionGroup', 'get', array(
-      'version' => 3,
-      ));
-    $this->assertEquals(0, $result['is_error']);
+    $result = $this->callAPISuccess('OptionGroup', 'get', array());
   }
 
   function testAPIResolver() {
     $oldpath = get_include_path();
     set_include_path($oldpath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver');
 
-    $result = civicrm_api('contact', 'example_action1', array(
-        'version' => 3,
-      ));
+    $result = $this->callAPISuccess('contact', 'example_action1', array());
     $this->assertEquals($result['values'][0], 'civicrm_api3_generic_example_action1 is ok');
-    $result = civicrm_api('contact', 'example_action2', array(
-        'version' => 3,
-      ));
+    $result = $this->callAPISuccess('contact', 'example_action2', array());
     $this->assertEquals($result['values'][0], 'civicrm_api3_contact_example_action2 is ok');
-    $result = civicrm_api('test_entity', 'example_action3', array(
-        'version' => 3,
-      ));
+    $result = $this->callAPISuccess('test_entity', 'example_action3', array());
     $this->assertEquals($result['values'][0], 'civicrm_api3_test_entity_example_action3 is ok');
 
     set_include_path($oldpath);
index a2dc892dc1e4baf50633797faadd3d648a3167be..bfea6f0c658dc4f09ef6d9966bc599dcbc8be908 100644 (file)
@@ -55,9 +55,8 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase {
    *  Test civicrm_activity_type_get()
    */
   function testActivityTypeGet() {
-    $params = array('version' => $this->_apiversion);
-    $result = civicrm_api('activity_type', 'get', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $params = array();
+    $result = $this->callAPIAndDocument('activity_type', 'get', $params, __FUNCTION__, __FILE__);
     $this->assertEquals($result['values']['1'], 'Meeting', 'In line ' . __LINE__);
     $this->assertEquals($result['values']['13'], 'Open Case', 'In line ' . __LINE__);
   }
@@ -70,15 +69,12 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase {
     $params = array(
       'weight' => '2',
       'label' => 'send out letters',
-      'version' => $this->_apiversion,
       'filter' => 0,
       'is_active' => 1,
       'is_optgroup' => 1,
       'is_default' => 0,
     );
-    $result = civicrm_api('activity_type', 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result);
+    $result = $this->callAPIAndDocument('activity_type', 'create', $params, __FUNCTION__, __FILE__);
   }
 
   /**
@@ -89,11 +85,8 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase {
     $params = array(
       'label' => 'type_create',
       'weight' => '2',
-      'version' => $this->_apiversion,
     );
-    $activitycreate = civicrm_api('activity_type', 'create', $params);
-    $activityID = $activitycreate['id'];
-    $this->assertAPISuccess($activitycreate, "in line " . __LINE__);
+    $activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
     $this->assertArrayHasKey('id', $activitycreate);
     $this->assertArrayHasKey('option_group_id', $activitycreate['values'][$activitycreate['id']]);
   }
@@ -106,16 +99,12 @@ class api_v3_ActivityTypeTest extends CiviUnitTestCase {
     $params = array(
       'label' => 'type_create_delete',
       'weight' => '2',
-      'version' => $this->_apiversion,
     );
-    $activitycreate = civicrm_api('activity_type', 'create', $params);
+    $activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
     $params = array(
       'activity_type_id' => $activitycreate['id'],
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('activity_type', 'delete', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPIFailure($result, 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('activity_type', 'delete', $params, __FUNCTION__, __FILE__);
   }
 }
 
index e881e9abde2074a532336311efd66538a7dd8447..7a0e365f5eb374a597facde12aa6995a3b5a538e 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
@@ -35,7 +34,7 @@
 
 require_once 'CiviTest/CiviUnitTestCase.php';
 class api_v3_AddressTest extends CiviUnitTestCase {
-  protected $_apiversion;
+  protected $_apiversion =3;
   protected $_contactID;
   protected $_locationType;
   protected $_params;
@@ -43,7 +42,6 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   protected $_entity;
 
   function setUp() {
-    $this->_apiversion = 3;
     $this->_entity = 'Address';
     parent::setUp();
 
@@ -61,7 +59,6 @@ class api_v3_AddressTest extends CiviUnitTestCase {
       'country_id' => '1152',
       'city' => 'Brummen',
       'is_primary' => 1,
-      'version' => $this->_apiversion,
     );
   }
 
@@ -71,17 +68,14 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   }
 
   public function testCreateAddress() {
-
-    $result = civicrm_api('address', 'create', $this->_params);
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('address', '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'], 'address');
   }
+
   public function testCreateAddressParsing() {
     $params = array(
-      'version' => $this->_apiversion,
       'street_parsing' => 1,
       'street_address' => '54A Excelsior Ave. Apt 1C',
       'location_type_id' => $this->_locationType->id,
@@ -89,14 +83,12 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     );
     $subfile     = "AddressParse";
     $description = "Demonstrates Use of address parsing param";
-    $result = civicrm_api('address', 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('address', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(54, $result['values'][$result['id']]['street_number'], 'In line ' . __LINE__);
     $this->assertEquals('A', $result['values'][$result['id']]['street_number_suffix'], 'In line ' . __LINE__);
     $this->assertEquals('Excelsior Ave.', $result['values'][$result['id']]['street_name'], 'In line ' . __LINE__);
     $this->assertEquals('Apt 1C', $result['values'][$result['id']]['street_unit'], 'In line ' . __LINE__);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $result['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
 
   }
 
@@ -109,8 +101,7 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   public function testCreateAddressTestDefaults() {
     $params = $this->_params;
     unset($params['is_primary']);
-    $result = civicrm_api('address', 'create', $params);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('address', 'create', $params);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertEquals(1, $result['values'][$result['id']]['is_primary'], 'In line ' . __LINE__);
     $this->getAndCheck($this->_params, $result['id'], 'address');
@@ -120,8 +111,7 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $params = $this->_params;
     $params['street_number_suffix'] = 'really long string';
     $result = $this->callAPIFailure('address', 'create', $params);
-    $this->assertEquals(2100, $result['error_code']);
-  }
+   }
   /*
      * is_primary shoule be set as a default. ie. create the address, unset the params & recreate.
      * is_primary should be 0 before & after the update. ie - having no other address
@@ -133,40 +123,31 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   public function testCreateAddressTestDefaultWithID() {
     $params = $this->_params;
     $params['is_primary'] = 0;
-    $result = civicrm_api('address', 'create', $params);
+    $result = $this->callAPISuccess('address', 'create', $params);
     unset($params['is_primary']);
     $params['id'] = $result['id'];
-    $result       = civicrm_api('address', 'create', $params);
-    $address      = civicrm_api('address', 'get', array('version' => 3, 'contact_id' => $params['contact_id']));
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
-    $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
+    $result       = $this->callAPISuccess('address', 'create', $params);
+    $address      = $this->callAPISuccess('address', 'get', array('contact_id' => $params['contact_id']));
+   $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertEquals(1, $result['values'][$result['id']]['is_primary'], 'In line ' . __LINE__);
     $this->getAndCheck($params, $result['id'], 'address', __FUNCTION__);
   }
   public function testDeleteAddress() {
 
     //check there are no addresss to start with
-    $get = civicrm_api('address', 'get', array(
-      'version' => 3,
-        'location_type_id' => $this->_locationType->id,
-      ));
-    $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__);
+    $get = $this->callAPISuccess('address', 'get', array(
+      'location_type_id' => $this->_locationType->id,
+    ));
     $this->assertEquals(0, $get['count'], 'Contact already exists ' . __LINE__);
 
     //create one
-    $create = civicrm_api('address', 'create', $this->_params);
-
-    $this->assertEquals(0, $create['is_error'], 'In line ' . __LINE__);
+    $create = $this->callAPISuccess('address', 'create', $this->_params);
 
-    $result = civicrm_api('address', 'delete', array('id' => $create['id'], 'version' => 3));
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('address', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
-    $get = civicrm_api('address', 'get', array(
-      'version' => 3,
-        'location_type_id' => $this->_locationType->id,
-      ));
-    $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__);
+    $get = $this->callAPISuccess('address', 'get', array(
+     'location_type_id' => $this->_locationType->id,
+    ));
     $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
   }
 
@@ -174,18 +155,14 @@ class api_v3_AddressTest extends CiviUnitTestCase {
    * Test civicrm_address_get - success expected.
    */
   public function testGetAddress() {
-    $address = civicrm_api('address', 'create', $this->_params);
-    $this->assertAPISuccess($address, 'In line ' . __LINE__);
+    $address = $this->callAPISuccess('address', 'create', $this->_params);
 
     $params = array(
       'contact_id' => $this->_contactID,
       'street_name' => $address['values'][$address['id']]['street_name'],
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('Address', 'Get', ($params));
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    civicrm_api('Address', 'delete', array('version' => 3, 'id' => $result['id']));
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__);
+    $this->callAPISuccess('Address', 'delete', array('id' => $result['id']));
     $this->assertEquals($address['values'][$address['id']]['location_type_id'], $result['values'][$address['id']]['location_type_id'], 'In line ' . __LINE__);
     $this->assertEquals($address['values'][$address['id']]['is_primary'], $result['values'][$address['id']]['is_primary'], 'In line ' . __LINE__);
     $this->assertEquals($address['values'][$address['id']]['street_address'], $result['values'][$address['id']]['street_address'], 'In line ' . __LINE__);
@@ -195,21 +172,20 @@ class api_v3_AddressTest extends CiviUnitTestCase {
    * Test civicrm_address_get - success expected.
    */
   public function testGetSingleAddress() {
-    civicrm_api('address', 'create', $this->_params);
+    $this->callAPISuccess('address', 'create', $this->_params);
     $params = array(
       'contact_id' => $this->_contactID,
-      'version' => $this->_apiversion,
     );
-    $address = civicrm_api('Address', 'getsingle', ($params));
+    $address = $this->callAPISuccess('Address', 'getsingle', ($params));
     $this->assertEquals($address['location_type_id'], $this->_params['location_type_id'], 'In line ' . __LINE__);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $address['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $address['id']));
   }
 
   /**
    * Test civicrm_address_get with sort option- success expected.
    */
   public function testGetAddressSort() {
-    $create = civicrm_api('address', 'create', $this->_params);
+    $create = $this->callAPISuccess('address', 'create', $this->_params);
     $subfile     = "AddressSort";
     $description = "Demonstrates Use of sort filter";
     $params      = array(
@@ -217,51 +193,43 @@ class api_v3_AddressTest extends CiviUnitTestCase {
         'sort' => 'street_address DESC',
         'limit' => 2,
       ),
-      'version' => $this->_apiversion,
       'sequential' => 1,
     );
-    $result = civicrm_api('Address', 'Get', ($params));
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(2, $result['count'], 'In line ' . __LINE__);
     $this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address'], 'In line ' . __LINE__);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $create['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $create['id']));
   }
 
   /**
    * Test civicrm_address_get with sort option- success expected.
    */
   public function testGetAddressLikeSuccess() {
-    civicrm_api('address', 'create', $this->_params);
+    $this->callAPISuccess('address', 'create', $this->_params);
     $subfile     = "AddressLike";
     $description = "Demonstrates Use of Like";
     $params      = array('street_address' => array('LIKE' => '%mb%'),
-      'version' => $this->_apiversion,
       'sequential' => 1,
     );
-    $result = civicrm_api('Address', 'Get', ($params));
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address'], 'In line ' . __LINE__);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $result['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
   }
 
   /**
    * Test civicrm_address_get with sort option- success expected.
    */
   public function testGetAddressLikeFail() {
-    $create = civicrm_api('address', 'create', $this->_params);
+    $create = $this->callAPISuccess('address', 'create', $this->_params);
     $subfile     = "AddressLike";
     $description = "Demonstrates Use of Like";
     $params      = array('street_address' => array('LIKE' => "'%xy%'"),
-      'version' => $this->_apiversion,
       'sequential' => 1,
     );
-    $result = civicrm_api('Address', 'Get', ($params));
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('Address', 'Get', ($params));
     $this->assertEquals(0, $result['count'], 'In line ' . __LINE__);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $create['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $create['id']));
   }
 
   function testGetWithCustom() {
@@ -270,45 +238,40 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $params = $this->_params;
     $params['custom_' . $ids['custom_field_id']] = "custom string";
 
-    $result = civicrm_api($this->_entity, 'create', $params);
-    $this->assertAPISuccess($result, ' in line ' . __LINE__);
+    $result = $this->callAPISuccess($this->_entity, 'create', $params);
 
-    $getParams = array('version' => 3, 'id' => $result['id'], 'return' => array('custom'));
-    $check = civicrm_api($this->_entity, 'get', $getParams);
+    $getParams = array('id' => $result['id'], 'return' => array('custom'));
+    $check = $this->callAPISuccess($this->_entity, 'get', $getParams);
 
     $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('address', 'delete', array('version' => 3, 'id' => $result['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
   }
 
   public function testCreateAddressPrimaryHandlingChangeToPrimary() {
     $params = $this->_params;
     unset($params['is_primary']);
-    $address1 = civicrm_api('address', 'create', $params);
+    $address1 = $this->callAPISuccess('address', 'create', $params);
     $this->assertApiSuccess($address1, 'In line ' . __LINE__);
     //now we check & make sure it has been set to primary
-    $check = civicrm_api('address', 'getcount', array(
-        'version' => 3,
+    $check = $this->callAPISuccess('address', 'getcount', array(
         'is_primary' => 1,
         'id' => $address1['id'],
       ));
     $this->assertEquals(1, $check);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $address1['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
   }
   public function testCreateAddressPrimaryHandlingChangeExisting() {
-    $address1 = civicrm_api('address', 'create', $this->_params);
-    $this->assertApiSuccess($address1, 'In line ' . __LINE__);
-    $address2 = civicrm_api('address', 'create', $this->_params);
-    $this->assertApiSuccess($address2, 'In line ' . __LINE__);
-    $check = civicrm_api('address', 'getcount', array(
-        'version' => 3,
+    $address1 = $this->callAPISuccess('address', 'create', $this->_params);
+    $address2 = $this->callAPISuccess('address', 'create', $this->_params);
+    $check = $this->callAPISuccess('address', 'getcount', array(
         'is_primary' => 1,
         'contact_id' => $this->_contactID,
       ));
     $this->assertEquals(1, $check);
-    civicrm_api('address', 'delete', array('version' => 3, 'id' => $address1['id']));
+    $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
   }
 }
 
index f7f01be0db05fa7e2e7c7faa93fe62f2aa40a4d4..6dadeb887c5e6f6e457363151ddf3dc78475fefa 100644 (file)
@@ -60,16 +60,14 @@ class api_v3_CRM11793Test extends CiviUnitTestCase {
   }
 
   function _testCRM11793ContactType($contactType) {
-    $result = civicrm_api(
+    $result = $this->callAPISuccess(
       'contact',
       'get',
       array(
-        'version' => 3,
         'contact_type' => $contactType
       )
     );
 
-    $this->assertAPISuccess($result, "In line " . __LINE__);
     foreach ($result['values'] as $idx => $contact) {
       $this->assertEquals($contact['contact_type'], $contactType, "In line " . __LINE__);
     }
index 2328886c921c835eafb30a07d85083c2b32ef386..9ece7f2995327cfaa941a8dccc74e9d46fb3cf2a 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
 | CiviCRM version 4.3                                                |
@@ -38,7 +37,6 @@ class api_v3_CampaignTest extends CiviUnitTestCase {
   function setUp() {
     $this->_apiversion = 3;
     $this->params = array(
-      'version' => 3,
       'title' => "campaign title",
       'description' => "Call people, ask for money",
       'created_date' => 'first sat of July 2008',
@@ -50,34 +48,25 @@ class api_v3_CampaignTest extends CiviUnitTestCase {
 
   public function testCreateCampaign() {
     $description = "Create a campaign - Note use of relative dates here http://www.php.net/manual/en/datetime.formats.relative.php";
-    $result = civicrm_api('campaign', 'create', $this->params);
-    $this->documentMe($this->params, $result, __FUNCTION__, __FILE__, $description);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
     $this->getAndCheck(array_merge($this->params, array('created_date' => '2008-07-05 00:00:00')), $result['id'], 'campaign', TRUE);
   }
 
   public function testGetCampaign() {
-    $result = civicrm_api('campaign', 'create', $this->params);
-    $result = civicrm_api('campaign', 'get', ($this->params));
-    $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('campaign', 'create', $this->params);
+    $result = $this->callAPIAndDocument('campaign', 'get', $this->params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
-    $this->id = $result['id'];
   }
 
   public function testDeleteCampaign() {
-    $entity = civicrm_api('campaign', 'get', ($this->params));
-    $delete = array('version' => 3, 'id' => $entity['id']);
-    $result = civicrm_api('campaign', 'delete', $delete);
-    $this->documentMe($delete, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $entity = $this->callAPISuccess('campaign', 'get', ($this->params));
+    $delete = array('id' => $entity['id']);
+    $result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__);
 
-    $checkDeleted = civicrm_api('campaign', 'get', array(
-      'version' => 3,
-      ));
+    $checkDeleted = $this->callAPISuccess('campaign', 'get', array());
     $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
   }
 }
index a7b4c903692154c01913cac1cb52ab074cc0db88..10197f68b1e3c7a39688e372903612da7b882345 100644 (file)
@@ -41,7 +41,7 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 class api_v3_CaseTest extends CiviUnitTestCase {
   protected $_params;
   protected $_entity;
-  protected $_apiversion;
+  protected $_apiversion =3;
   protected $followup_activity_type_value;
   protected $caseTypeId;
   protected $caseStatusGroup;
@@ -55,7 +55,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
    *  and redirect stdin to a temporary file
    */
   public function setUp() {
-    $this->_apiversion = 3;
     $this->_entity = 'case';
 
     parent::setUp();
@@ -63,10 +62,15 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     //. Using XML was causing breakage as id numbers were changing over time
     // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
     // state where tests could run afterwards without re-loading.
-    $this->caseStatusGroup = civicrm_api('option_group', 'get', array('version' => API_LATEST_VERSION, 'name' => 'case_status', 'format.only_id' => 1));
-    $this->caseTypeGroup = civicrm_api('option_group', 'get', array('version' => API_LATEST_VERSION, 'name' => 'case_type', 'format.only_id' => 1));
-    $caseTypes = civicrm_api('option_value', 'Create', array(
-      'version' => API_LATEST_VERSION,
+    $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array(
+      'name' => 'case_status',
+      'format.only_id' => 1)
+    );
+    $this->caseTypeGroup = $this->callAPISuccess('option_group', 'get', array(
+      'name' => 'case_type',
+      'format.only_id' => 1)
+    );
+    $caseTypes = $this->callAPISuccess('option_value', 'Create', array(
         'option_group_id' => $this->caseTypeGroup,
         'name' => 'housing_support',
         'label' => "Housing Support",
@@ -85,8 +89,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'Income and benefits stabilization' => 'Income and benefits stabilization',
     );
     foreach ($optionValues as $name => $label) {
-      $activityTypes = civicrm_api('option_value', 'Create', array(
-        'version' => API_LATEST_VERSION,
+      $activityTypes = $this->callAPISuccess('option_value', 'Create', array(
           'option_group_id' => 2,
           'name' => $name,
           'label' => $label,
@@ -110,12 +113,12 @@ class api_v3_CaseTest extends CiviUnitTestCase {
 
     $this->quickCleanup($tablesToTruncate);
 
-    $activityTypes = civicrm_api('option_value', 'get', array(
-      'version' => API_LATEST_VERSION, 'option_group_id' => 2,
-        'name' => 'Follow Up',
-        'label' => 'Follow Up',
-        'sequential' => 1,
-      ));
+    $activityTypes = $this->callAPISuccess('option_value', 'get', array(
+      'option_group_id' => 2,
+      'name' => 'Follow Up',
+      'label' => 'Follow Up',
+      'sequential' => 1,
+    ));
     $this->followup_activity_type_value = $activityTypes['values'][0]['value'];
     //  Insert a row in civicrm_contact creating contact 17
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
@@ -136,7 +139,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'contact_type_b' => 'Individual',
       'is_reserved' => 0,
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
     $this->relationshipTypeCreate($relTypeParams);
 
@@ -150,7 +152,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'contact_type_b' => 'Individual',
       'is_reserved' => 0,
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
     $this->relationshipTypeCreate($relTypeParams);
 
@@ -164,7 +165,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'contact_type_b' => 'Individual',
       'is_reserved' => 0,
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
     $this->relationshipTypeCreate($relTypeParams);
 
@@ -178,7 +178,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'contact_type_b' => 'Individual',
       'is_reserved' => 0,
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
     $this->relationshipTypeCreate($relTypeParams);
 
@@ -192,7 +191,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'contact_type_b' => 'Individual',
       'is_reserved' => 0,
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
     $this->relationshipTypeCreate($relTypeParams);
 
@@ -200,7 +198,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     $this->customDirectories(array('template_path' => TRUE));
 
     // case is not enabled by default
-    require_once 'CRM/Core/BAO/ConfigSetting.php';
     $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
 
@@ -208,7 +205,6 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'case_type_id' => $this->caseTypeId,
       'subject' => 'Test case',
       'contact_id' => 17,
-      'version' => $this->_apiversion,
     );
 
     // create a logged in USER since the code references it for source_contact_id
@@ -229,7 +225,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
    */
   function tearDown() {
     foreach ($this->optionValues as $id) {
-      civicrm_api('option_value', 'delete', array('version' => API_LATEST_VERSION, 'id' => $id));
+      $this->callAPISuccess('option_value', 'delete', array('id' => $id));
     }
     $tablesToTruncate = array(
       'civicrm_contact',
@@ -250,11 +246,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
    * check with empty array
    */
   function testCaseCreateEmpty() {
-    $params = array('version' => $this->_apiversion);
-    $result = civicrm_api('case', 'create', $params);
-    $this->assertAPIFailure($result,
-      "In line " . __LINE__
-    );
+    $result = $this->callAPIFailure('case', 'create', array());
   }
 
   /**
@@ -264,13 +256,9 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     $params = array(
       'subject' => 'this case should fail',
       'case_type_id' => 1,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('case', 'create', $params);
-    $this->assertAPIFailure($result,
-      "In line " . __LINE__
-    );
+    $result = $this->callAPIFailure('case', 'create', $params);
   }
 
   /**
@@ -282,12 +270,11 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     // Test using label instead of value
     unset($params['case_type_id']);
     $params['case_type'] = 'Housing Support';
-    $result = civicrm_api('case', 'create', $params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $params);
     $id = $result['id'];
 
     // Check result
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
+    $result = $this->callAPISuccess('case', 'get', array('id' => $id));
     $this->assertEquals($result['values'][$id]['id'], 1, 'in line ' . __LINE__);
     $this->assertEquals($result['values'][$id]['case_type_id'], $this->caseTypeId, 'in line ' . __LINE__);
     $this->assertEquals($result['values'][$id]['subject'], $params['subject'], 'in line ' . __LINE__);
@@ -301,20 +288,18 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     $params = $this->_params;
     // Test using name instead of value
     $params['case_type_id'] = 'housing_support';
-    $result = civicrm_api('case', 'create', $params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $params);
     $id = $result['id'];
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
+    $result = $this->callAPISuccess('case', 'get', array('id' => $id));
     $case = $result['values'][$id];
 
     // Update Case
-    $params = array('id' => $id, 'version' => $this->_apiversion);
+    $params = array('id' => $id);
     $params['subject'] = $case['subject'] = 'Something Else';
-    $result = civicrm_api('case', 'create', $params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $params);
 
     // Verify that updated case is exactly equal to the original with new subject
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'case_id' => $id));
+    $result = $this->callAPISuccess('case', 'get', array('case_id' => $id));
     $this->assertEquals($result['values'][$id], $case, 'in line ' . __LINE__);
   }
 
@@ -323,25 +308,22 @@ class api_v3_CaseTest extends CiviUnitTestCase {
    */
   function testCaseDelete() {
     // Create Case
-    $result = civicrm_api('case', 'create', $this->_params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $this->_params);
 
     // Move Case to Trash
     $id = $result['id'];
-    $result = civicrm_api('case', 'delete', array('version' => $this->_apiversion, 'id' => $id, 'move_to_trash' => 1));
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'delete', array('id' => $id, 'move_to_trash' => 1));
 
     // Check result - also check that 'case_id' works as well as 'id'
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'case_id' => $id));
+    $result = $this->callAPISuccess('case', 'get', array('case_id' => $id));
     $this->assertEquals(1, $result['values'][$id]['is_deleted'], 'in line ' . __LINE__);
 
     // Delete Case Permanently - also check that 'case_id' works as well as 'id'
-    $result = civicrm_api('case', 'delete', array('version' => $this->_apiversion, 'case_id' => $id));
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'delete', array('case_id' => $id));
 
     // Check result - case should no longer exist
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
-    $this->assertEquals(0, $result['count'], 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'get', array('id' => $id));
+    $this->assertEquals(0, $result['count']);
   }
 
   /**
@@ -349,18 +331,16 @@ class api_v3_CaseTest extends CiviUnitTestCase {
    */
   function testCaseGetByActivity() {
     // Create Case
-    $result = civicrm_api('case', 'create', $this->_params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $this->_params);
     $id = $result['id'];
 
     // Check result - we should get a list of activity ids
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'get', array('id' => $id));
     $case = $result['values'][$id];
     $activity = $case['activities'][0];
 
     // Fetch case based on an activity id
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'activity_id' => $activity, 'return' => 'activities,contacts'));
+    $result = $this->callAPISuccess('case', 'get', array('activity_id' => $activity, 'return' => 'activities,contacts'));
     $this->assertEquals(FALSE, empty($result['values'][$id]), 'in line ' . __LINE__);
     $this->assertEquals($result['values'][$id], $case, 'in line ' . __LINE__);
   }
@@ -370,16 +350,15 @@ class api_v3_CaseTest extends CiviUnitTestCase {
    */
   function testCaseGetByContact() {
     // Create Case
-    $result = civicrm_api('case', 'create', $this->_params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $this->_params);
     $id = $result['id'];
 
     // Store result for later
-    $case = civicrm_api('case', 'getsingle', array('version' => $this->_apiversion, 'id' => $id));
+    $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id));
 
     // Fetch case based on client contact id
-    $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'client_id' => $this->_params['contact_id'], 'return' => array('activities', 'contacts')));
-    $this->assertEquals($result['values'][$id], $case, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'get', array('client_id' => $this->_params['contact_id'], 'return' => array('activities', 'contacts')));
+    $this->assertAPIArrayComparison($result['values'][$id], $case);
   }
 
   /**
@@ -388,8 +367,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
   function testCaseActivityCreate() {
     // Create a case first
     $params = $this->_params;
-    $result = civicrm_api('case', 'create', $params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('case', 'create', $params);
     $params = array(
       'case_id' => 1,
       // follow up
@@ -397,24 +375,20 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'subject' => 'Test followup',
       'source_contact_id' => $this->_loggedInUser,
       'target_contact_id' => $this->_params['contact_id'],
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('activity', 'create', $params);
-    $this->assertAPISuccess($result, 'in line ' . __LINE__);
+    $result = $this->callAPISuccess('activity', 'create', $params);
     $this->assertEquals($result['values'][$result['id']]['activity_type_id'], $params['activity_type_id'], 'in line ' . __LINE__);
 
     // might need this for other tests that piggyback on this one
     $this->_caseActivityId = $result['values'][$result['id']]['id'];
 
     // Check other DB tables populated properly - is there a better way to do this? assertDBState() requires that we know the id already.
-    require_once 'CRM/Case/DAO/CaseActivity.php';
-    $dao              = new CRM_Case_DAO_CaseActivity();
-    $dao->case_id     = 1;
+    $dao = new CRM_Case_DAO_CaseActivity();
+    $dao->case_id = 1;
     $dao->activity_id = $this->_caseActivityId;
     $this->assertEquals($dao->find(), 1, 'case_activity table not populated correctly in line ' . __LINE__);
     $dao->free();
 
-    require_once 'CRM/Activity/DAO/ActivityContact.php';
     $dao = new CRM_Activity_DAO_ActivityContact();
     $dao->activity_id = $this->_caseActivityId;
     $dao->contact_id = $this->_params['contact_id'];
@@ -438,13 +412,9 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'activity_type_id' => 14,
       'source_contact_id' => $this->_loggedInUser,
       'subject' => 'New subject',
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('activity', 'create', $params);
+    $result = $this->callAPISuccess('activity', 'create', $params);
 
-    $this->assertAPISuccess($result,
-      "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
-    );
     $this->assertEquals($result['values'][$result['id']]['subject'], $params['subject'], 'in line ' . __LINE__);
 
     // id should be one greater, since this is a new revision
@@ -460,16 +430,12 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     // Check revision is as expected
     $revParams = array(
       'activity_id' => $this->_caseActivityId,
-      'version' => $this->_apiversion,
     );
-    $revActivity = civicrm_api('activity', 'get', $revParams);
+    $revActivity = $this->callAPISuccess('activity', 'get', $revParams);
     $this->assertEquals($revActivity['values'][$this->_caseActivityId]['is_current_revision'],
-      0,
-      'in line ' . __LINE__
-    );
+      0);
     $this->assertEquals($revActivity['values'][$this->_caseActivityId]['is_deleted'],
-      0,
-      'in line ' . __LINE__
+      0
     );
 
     //TODO: check some more things
@@ -477,8 +443,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
 
   function testCaseActivityUpdateCustom() {
     // Create a case first
-    $params = $this->_params;
-    $result = civicrm_api('case', 'create', $params);
+    $result = $this->callAPISuccess('case', 'create', $this->_params);
 
     // Create custom field group
     // Note the second parameter is Activity on purpose, not Case.
@@ -486,20 +451,15 @@ class api_v3_CaseTest extends CiviUnitTestCase {
 
     // create activity
     $params = array(
-      'case_id' => 1,
+      'case_id' => $result['id'],
       // follow up
       'activity_type_id' => 14,
       'subject' => 'Test followup',
       'source_contact_id' => $this->_loggedInUser,
       'target_contact_id' => $this->_params['contact_id'],
       'custom_' . $custom_ids['custom_field_id'] => "custom string",
-      'version' => $this->_apiversion,
-    );
-    $result = civicrm_api('activity', 'create', $params);
-
-    $this->assertAPISuccess($result,
-      "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
     );
+    $result = $this->callAPISuccess('activity', 'create', $params);
 
     $aid = $result['values'][$result['id']]['id'];
 
@@ -510,25 +470,16 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'activity_type_id' => 14,
       'source_contact_id' => $this->_loggedInUser,
       'subject' => 'New subject',
-      'version' => $this->_apiversion,
-    );
-    $revAct = civicrm_api('activity', 'create', $params);
-
-    $this->assertEquals($revAct['is_error'], 0,
-      "Error message: " . CRM_Utils_Array::value('error_message', $revAct) . ' in line ' . __LINE__
     );
+    $revAct = $this->callAPISuccess('activity', 'create', $params);
 
     // Retrieve revision and check custom fields got copied
     $revParams = array(
       'activity_id' => $aid + 1,
-      'version' => $this->_apiversion,
       'return.custom_' . $custom_ids['custom_field_id'] => 1,
     );
-    $revAct = civicrm_api('activity', 'get', $revParams);
+    $revAct = $this->callAPISuccess('activity', 'get', $revParams);
 
-    $this->assertEquals($revAct['is_error'], 0,
-      "Error message: " . CRM_Utils_Array::value('error_message', $revAct) . ' in line ' . __LINE__
-    );
     $this->assertEquals($revAct['values'][$aid + 1]['custom_' . $custom_ids['custom_field_id']], "custom string",
       "Error message: " . CRM_Utils_Array::value('error_message', $revAct) . ' in line ' . __LINE__
     );