CRM-13072 upgrade Membership & Membership Payment test classes to pass
authoreileen <eileen@fuzion.co.nz>
Thu, 25 Jul 2013 07:20:29 +0000 (19:20 +1200)
committereileen <eileen@fuzion.co.nz>
Thu, 25 Jul 2013 07:20:29 +0000 (19:20 +1200)
tests/phpunit/api/v3/MembershipPaymentTest.php
tests/phpunit/api/v3/MembershipTest.php

index e45b5dc32c913b45f5fde43507e184c546804139..20a82bbb2f9961f3e86747f8b3ff4c7d02ddeb55 100644 (file)
@@ -63,10 +63,9 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
       'trxn_id' => '22ereerwww322323',
       'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
       'thankyou_date' => '20080522',
-      'version' => 3,
     );
 
-    $this->_contribution = civicrm_api('contribution','create', $params);
+    $this->_contribution = $this->callAPISuccess('contribution','create', $params);
   }
 
   function tearDown() {
@@ -81,7 +80,6 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
         'civicrm_line_item',
       )
     );
-    $this->contributionTypeDelete();
   }
 
   ///////////////// civicrm_membership_payment_create methods
@@ -90,9 +88,7 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
    * Test civicrm_membership_payment_create with empty params.
    */
   public function testCreateEmptyParams() {
-    $params = array('version' => $this->_apiversion);
-    $CreateEmptyParams = civicrm_api('membership_payment', 'create', $params);
-    $this->assertEquals($CreateEmptyParams['error_message'], 'Mandatory key(s) missing from params array: membership_id, contribution_id');
+    $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id');
   }
 
   /**
@@ -101,8 +97,6 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
   public function testCreate() {
     $contactId = $this->individualCreate(NULL);
 
-
-
     $params = array(
       'contact_id' => $contactId,
       'membership_type_id' => $this->_membershipTypeID,
@@ -112,19 +106,15 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => API_LATEST_VERSION,
     );
 
-    $membership = civicrm_api('membership', 'create', $params);
-    $this->assertAPISuccess($membership, "membership created in line " . __LINE__);
+    $membership = $this->callAPISuccess('membership', 'create', $params);
 
     $params = array(
       'contribution_id' => $this->_contribution['id'],
       'membership_id' => $membership['id'],
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('membership_payment', 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__);
     $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__);
     $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__);
 
@@ -138,17 +128,7 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
    */
   public function testGetWrongParamsType() {
     $params = 'eeee';
-    $GetWrongParamsType = civicrm_api('membership_payment', 'get', $params);
-    $this->assertEquals($GetWrongParamsType['error_message'], 'Input variable `params` is not an array');
-  }
-
-  /**
-   * Test civicrm_membershipPayment_get with empty params.
-   */
-  public function testGetEmptyParams() {
-    $params = array();
-    $GetEmptyParams = civicrm_api('membership_payment', 'get', $params);
-    $this->assertEquals($GetEmptyParams['error_message'], 'Mandatory key(s) missing from params array: version');
+    $GetWrongParamsType = $this->callAPIFailure('membership_payment', 'get', $params, 'Input variable `params` is not an array');
   }
 
   /**
@@ -162,23 +142,19 @@ class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
-    $ids = array();
-    $membership = CRM_Member_BAO_Membership::create($params, $ids);
+
+    $membership = $this->callAPISuccess('membership', 'create', $params);
 
     $params = array(
       'contribution_id' => $this->_contribution['id'],
-      'membership_id' => $membership->id,
-      'version' => $this->_apiversion,
+      'membership_id' => $membership['id'],
     );
-    civicrm_api('membership_payment', 'create', $params);
-
-    $result = civicrm_api('membership_payment', 'get', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership->id, 'Check Membership Id');
-    $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id');
+    $this->callAPISuccess('membership_payment', 'create', $params);
 
+    $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__);
+    $this->assertEquals($result['values'][$result['id']]['membership_id'], $params['membership_id'], 'Check Membership Id');
+    $this->assertEquals($result['values'][$result['id']]['contribution_id'], $params['contribution_id'], 'Check Contribution Id');
   }
 }
 
index c4096da953ca6c5845f35962c9f24a7b51f856be..a552d4d66743d2b775df7ec1864e952c219bb34a 100644 (file)
@@ -68,14 +68,16 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => 3,
     );
   }
 
   function tearDown() {
     $this->quickCleanup(array(
       'civicrm_membership',
-      'civicrm_membership_payment')
+      'civicrm_membership_payment',
+      'civicrm_membership_log',
+      ),
+      TRUE
     );
     $this->membershipStatusDelete($this->_membershipStatusID);
     $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
@@ -90,11 +92,8 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $membershipID = $this->contactMembershipCreate($this->_params);
     $params = array(
       'id' => $membershipID,
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('membership', 'delete', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, "In line " . __LINE__);
+    $result = $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__, __FILE__);
   }
 
   function testMembershipDeleteEmpty() {
@@ -103,7 +102,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   function testMembershipDeleteInvalidID() {
-    $params = array('version' => $this->_apiversion, 'id' => 'blah');
+    $params = array('id' => 'blah');
     $result = $this->callAPIFailure('membership', 'delete', $params);
   }
 
@@ -112,10 +111,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
    */
   function testMembershipDeleteWithInvalidMembershipId() {
     $membershipId = 'membership';
-    $result = civicrm_api('membership', 'delete', $membershipId);
-    $this->assertAPIFailure($result,
-      "In line " . __LINE__
-    );
+    $result = $this->callAPIFailure('membership', 'delete', $membershipId);
   }
 
   /**
@@ -126,13 +122,11 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
    */
   function testContactMembershipsGet() {
     $this->_membershipID = $this->contactMembershipCreate($this->_params);
-    $params = array('version' => $this->_apiversion);
-    $result = civicrm_api('membership', 'get', $params);
-    $this->assertEquals(0, $result['is_error'], "In line " . __LINE__);
-    $result = civicrm_api('Membership', 'Delete', array(
+    $params = array();
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $this->_membershipID,
-        'version' => $this->_apiversion,
-      ));
+    ));
   }
 
   /**
@@ -143,14 +137,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $this->_membershipID = $this->contactMembershipCreate($this->_params);
     $params = array(
       'contact_id' => $this->_contactID,
-      'version' => $this->_apiversion,
     );
-    $membership = civicrm_api('membership', 'get', $params);
+    $membership = $this->callAPISuccess('membership', 'get', $params);
 
     $result = $membership['values'][$this->_membershipID];
-    civicrm_api('Membership', 'Delete', array(
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $this->_membershipID,
-        'version' => $this->_apiversion,
       ));
     $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
     $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
@@ -167,16 +159,14 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
    * Gets treated as contact_id, memberships expected.
    */
   function testGetWithParamsMemberShipTypeId() {
-    $result = civicrm_api($this->_entity, 'create', $this->_params);
+    $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
     $params = array(
       'membership_type_id' => $this->_membershipTypeID,
-      'version' => $this->_apiversion,
     );
-    $membership = civicrm_api('membership', 'get', $params);
-    $result = civicrm_api('Membership', 'Delete', array(
+    $membership = $this->callAPISuccess('membership', 'get', $params);
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $membership['id'],
-        'version' => $this->_apiversion,
-      ));
+    ));
     $result = $membership['values'][$membership['id']];
     $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
     $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
@@ -201,20 +191,15 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $params = $this->_params;
     $params['custom_' . $ids['custom_field_id']] = "custom string";
 
-    $result = civicrm_api($this->_entity, 'create', $params);
+    $result = $this->callAPISuccess($this->_entity, 'create', $params);
 
-    $this->assertAPISuccess($result,  ' in line ' . __LINE__);
-    $getParams = array('version' => 3, 'membership_type_id' => $params['membership_type_id']);
-    $check = civicrm_api($this->_entity, 'get', $getParams);
-    $this->documentMe($getParams, $check, __FUNCTION__, __FILE__);
+    $getParams = array('membership_type_id' => $params['membership_type_id']);
+    $check = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
     $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
 
-    $this->customFieldDelete($ids['custom_field_id']);
-    $this->customGroupDelete($ids['custom_group_id']);
-    $result = civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
+    ));
   }
 
   /**
@@ -225,16 +210,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $membershipID = $this->contactMembershipCreate($this->_params);
     $params = array(
       'contact_id' => $this->_contactID,
-      'version' => $this->_apiversion,
     );
 
-    $membership = civicrm_api('membership', 'get', $params);
-    //$this->documentMe($params,$membership,__FUNCTION__,__FILE__);
+    $membership = $this->callAPISuccess('membership', 'get', $params);
     $result = $membership['values'][$membershipID];
-    civicrm_api('Membership', 'Delete', array(
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $membership['id'],
-        'version' => $this->_apiversion,
-      ));
+    ));
     $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__);
     $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
     $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
@@ -255,26 +237,18 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $membershipID = $this->contactMembershipCreate($this->_params);
     $params = array(
       'contact_id' => $this->_contactID,
-      'version' => $this->_apiversion,
       'id' => $this->__membershipID,
       'return' => 'id',
     );
-    $result = civicrm_api('membership', 'get', $params);
-    $this->assertAPISuccess($result);
+    $result = $this->callAPISuccess('membership', 'get', $params);
     $this->assertEquals($membershipID, $result['id']);
     $params = array(
       'contact_id' => $this->_contactID,
-      'version' => $this->_apiversion,
       'membership_id' => $this->__membershipID,
       'return' => 'membership_id',
     );
-    $result = civicrm_api('membership', 'get', $params);
-    $this->assertAPISuccess($result);
+    $result = $this->callAPISuccess('membership', 'get', $params);
     $this->assertEquals($membershipID, $result['id']);
-    civicrm_api('Membership', 'Delete', array(
-      'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
   }
 
   /**
@@ -288,10 +262,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $params              = array(
       'contact_id' => $this->_contactID,
       'active_only' => 1,
-      'version' => $this->_apiversion,
     );
 
-    $membership = civicrm_api('membership', 'get', $params);
+    $membership = $this->callAPISuccess('membership', 'get', $params);
     $result = $membership['values'][$this->_membershipID];
     $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
     $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID, "In line " . __LINE__);
@@ -300,20 +273,17 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'filters' => array(
         'is_current' => 1,
       ),
-      'version' => $this->_apiversion,
     );
 
-    $membership = civicrm_api('membership', 'get', $params);
-    $this->documentMe($params, $membership, __FUNCTION__, __FILE__, $description, $subfile);
+    $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $result = $membership['values'][$this->_membershipID];
     $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
     $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID, "In line " . __LINE__);
 
 
-    $result = civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $this->_membershipID,
-        'version' => $this->_apiversion,
-      ));
+    ));
   }
 
   /**
@@ -323,10 +293,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   function testGetNoContactExists() {
     $params = array(
       'contact_id' => 55555,
-      'version' => $this->_apiversion,
     );
 
-    $membership = civicrm_api('membership', 'get', $params);
+    $membership = $this->callAPISuccess('membership', 'get', $params);
     $this->assertEquals($membership['count'], 0, "In line " . __LINE__);
   }
 
@@ -346,7 +315,6 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'contact_type_b' => 'Individual',
       'is_reserved' => 1,
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
     $relTypeID = $this->relationshipTypeCreate($relTypeParams);
 
@@ -357,13 +325,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'period_type' => 'rolling',
       'member_of_contact_id' => $membershipOrgId,
       'domain_id' => 1,
-                         'financial_type_id'   => 1,
+      'financial_type_id'   => 1,
       'relationship_type_id' => $relTypeID,
       'relationship_direction' => 'b_a',
       'is_active' => 1,
-      'version' => $this->_apiversion,
     );
-    $memType = civicrm_api('membership_type', 'create', $params);
+    $memType = $this->callAPISuccess('membership_type', 'create', $params);
 
     $params = array(
       'contact_id' => $memberContactId,
@@ -374,25 +341,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
     $membershipID = $this->contactMembershipCreate($params);
 
     $params = array(
       'contact_id' => $memberContactId,
       'membership_type_id' => $memType['id'],
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'get', $params);
+    $result = $this->callAPISuccess('membership', 'get', $params);
 
     $membership = $result['values'][$membershipID];
-    $this->assertEquals($this->_membershipStatusID, $membership['status_id'],
-      "In line " . __LINE__
-    );
-    $result = civicrm_api('Membership', 'Delete', array(
+    $this->assertEquals($this->_membershipStatusID, $membership['status_id']);
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $membership['id'],
-        'version' => $this->_apiversion,
       ));
     $this->membershipTypeDelete(array('id' => $memType['id']));
     $this->relationshipTypeDelete($relTypeID);
@@ -412,26 +374,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test civicrm_contact_memberships_create with params with wrong type.
-   * Error expected.
-   */
-  function testCreateWithParamsString() {
-    $params = 'a string';
-    $result = civicrm_api('membership', 'create', $params);
-    $this->assertAPIFailure($result,
-      "In line " . __LINE__
-    );
-  }
-  /*
    * If is_overide is passed in status must also be passed in
    */
   function testCreateOverrideNoStatus() {
     $params = $this->_params;
     unset($params['status_id']);
-    $result = civicrm_api('membership', 'create', $params);
-    $this->assertAPIFailure($result,
-        "In line " . __LINE__
-    );
+    $result = $this->callAPIFailure('membership', 'create', $params);
   }
 
   function testMembershipCreateMissingRequired() {
@@ -442,7 +390,6 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'end_date' => '2006-12-21',
       'source' => 'Payment',
       'status_id' => '2',
-      'version' => $this->_apiversion,
     );
 
     $result = $this->callAPIFailure('membership', 'create', $params);
@@ -458,13 +405,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__, __FILE__);
     $this->getAndCheck($params, $result['id'], $this->_entity);
-    $this->assertAPISuccess($result);
     $this->assertNotNull($result['id']);
     $this->assertEquals($this->_contactID, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__);
     $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__);
@@ -482,26 +426,27 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
-    $this->assertEquals('contact_id is not valid : 999', $result['error_message']);
+    $result = $this->callAPIFailure('membership', 'create', $params,
+      'contact_id is not valid : 999'
+    );
   }
   function testMembershipCreateWithInvalidStatus() {
     $params = $this->_params;
     $params['status_id'] = 999;
-
-    $result = civicrm_api('membership', 'create', $params);
-    $this->assertEquals("'999' is not a valid option for field status_id", $result['error_message']);
+    $result = $this->callAPIFailure('membership', 'create', $params,
+      "'999' is not a valid option for field status_id"
+    );
   }
 
   function testMembershipCreateWithInvalidType() {
     $params = $this->_params;
     $params['membership_type_id'] = 999;
 
-    $result = civicrm_api('membership', 'create', $params);
-    $this->assertEquals("'999' is not a valid option for field membership_type_id", $result['error_message']);
+    $result = $this->callAPIFailure('membership', 'create', $params,
+      "'999' is not a valid option for field membership_type_id"
+    );
   }
 
   /**
@@ -516,18 +461,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $params = $this->_params;
     $params['custom_' . $ids['custom_field_id']] = "custom string";
 
-    $result = civicrm_api($this->_entity, 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, ' in line ' . __LINE__);
-
-    $check = civicrm_api($this->_entity, 'get', array('version' => 3, 'id' => $result['id'], 'contact_id' => $this->_contactID));
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+    $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID));
     $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
-    $this->customFieldDelete($ids['custom_field_id']);
-    $this->customGroupDelete($ids['custom_group_id']);
-    civicrm_api('Membership', 'Delete', array(
-      'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
   }
 
   /**
@@ -547,15 +483,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
-    civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('membership', 'create', $params);
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
-    $this->assertAPISuccess($result, "in line " . __LINE__);
+    ));
     $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
   }
 
@@ -576,15 +509,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
-    civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('membership', 'create', $params);
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
       ));
-    $this->assertAPISuccess($result, "in line " . __LINE__);
+
     $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
   }
 
@@ -602,15 +533,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
-    civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('membership', 'create', $params);
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
-    $this->assertAPISuccess($result, "in line " . __LINE__);
+     ));
     $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
   }
 
@@ -627,15 +555,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'contact_id' => $this->_contactID,
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
-    civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('membership', 'create', $params);
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
-    $this->assertAPISuccess($result, "in line " . __LINE__);
+    ));
     $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
   }
 
@@ -650,17 +575,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'id' => $membershipID,
       'source' => 'changed',
       'contact_id' => $this->_contactID,
-      'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
-      'membership_type_id' => $this->_membershipTypeID,
+      'status_id' => $this->_membershipStatusID,      'membership_type_id' => $this->_membershipTypeID,
       'skipStatusCal' => 1,
     );
-    $result = civicrm_api('membership', 'create', $params);
-    $this->assertAPISuccess($result, "in line " . __LINE__);
+    $result = $this->callAPISuccess('membership', 'create', $params);
     $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
-    civicrm_api('Membership', 'Delete', array(
+    $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
       ));
   }
 
@@ -672,18 +593,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
 
     $params = $this->_params;
     $params['custom_' . $ids['custom_field_id']] = "custom string";
-    $result = civicrm_api($this->_entity, 'create', $params);
-
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, ' in line ' . __LINE__);
-    $result = civicrm_api($this->_entity, 'create', array('id' => $result['id'], 'version' => 3, 'custom_' . $ids['custom_field_id'] => "new custom"));
-    $this->assertAPISuccess($result, ' in line ' . __LINE__);
-    $check = civicrm_api($this->_entity, 'get', array('version' => 3, 'id' => $result['id'], 'contact_id' => $this->_contactID));
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+    $result = $this->callAPISuccess($this->_entity, 'create', array('id' => $result['id'], 'custom_' . $ids['custom_field_id'] => "new custom"));
+    $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID));
 
     $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
-    $delete = civicrm_api('Membership', 'Delete', array(
+    $delete = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $check['id'],
-        'version' => $this->_apiversion,
       ));
 
     $this->customFieldDelete($ids['custom_field_id']);
@@ -704,9 +620,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'end_date' => '2008-12-21',
       'source' => 'Payment',
       'is_override' => 1,
-      'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
-    );
+      'status_id' => $this->_membershipStatusID,    );
 
     $result = $this->callAPIFailure('membership', 'create', $params);
 
@@ -735,16 +649,13 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'source' => 'Payment',
       'is_override' => 1,
       'status_id' => $this->_membershipStatusID,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('membership', 'create', $params);
+    $result = $this->callAPISuccess('membership', 'create', $params);
 
-    $this->assertAPISuccess($result, ' in line ' . __LINE__);
-    $result = civicrm_api('Membership', 'Delete', array(
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
       'id' => $result['id'],
-        'version' => $this->_apiversion,
-      ));
+    ));
   }
 
   ///////////////// civicrm_membership_delete methods