CRM-13072 upgrade PaymentProcessTypeTest & PaymentProcessorTest to pass post update...
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
index ec5b480b3d4372bba806e185df142bf305f2fec9..0b11710a9f6c7c4281bce5772380e263beeb614c 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-// $Id$
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
@@ -66,12 +64,8 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
    */
   function testPaymentProcessorTypeCreateWithoutName() {
     $payProcParams = array(
-      'is_active' => 1,
-      'version' => $this->_apiversion,
-    );
-    $result = civicrm_api('payment_processor_type', 'create', $payProcParams);
-
-    $this->assertEquals($result['is_error'], 1);
+      'is_active' => 1,    );
+    $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
     $this->assertEquals($result['error_message'],
       'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
     );
@@ -81,21 +75,17 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
    * create payment processor type
    */
   function testPaymentProcessorTypeCreate() {
-    $params = array(
-      'version' => $this->_apiversion,
-      'sequential' => 1,
+    $params = array(      'sequential' => 1,
       'name' => 'API_Test_PP',
       'title' => 'API Test Payment Processor',
       'class_name' => 'CRM_Core_Payment_APITest',
       'billing_mode' => 'form',
       'is_recur' => 0,
     );
-    $result = civicrm_api('payment_processor_type', 'create', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
     $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__);
 
     // mutate $params to match expected return value
-    unset($params['version']);
     unset($params['sequential']);
     $params['billing_mode'] = CRM_Core_Payment::BILLING_MODE_FORM;
     //assertDBState compares expected values in $result to actual values in the DB
@@ -109,7 +99,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
     require_once 'api/v3/examples/PaymentProcessorTypeCreate.php';
     $result = payment_processor_type_create_example();
     $expectedResult = payment_processor_type_create_expectedresult();
-    $this->assertEquals($result['is_error'], 0);
+    $this->assertAPISuccess($result);
   }
 
   ///////////////// civicrm_payment_processor_type_delete methods
@@ -119,18 +109,14 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
    */
   function testPaymentProcessorTypeDeleteEmpty() {
     $params = array();
-    $result = civicrm_api('payment_processor_type', 'delete', $params);
-
-    $this->assertEquals($result['is_error'], 1);
+    $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
   }
 
   /**
    * check with No array
    */
   function testPaymentProcessorTypeDeleteParamsNotArray() {
-    $result = civicrm_api('payment_processor_type', 'delete', 'string');
-
-    $this->assertEquals($result['is_error'], 1);
+    $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
   }
 
   /**
@@ -143,25 +129,15 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
       'class_name' => 'CRM_Core_Payment_APITest',
     );
 
-    $result = civicrm_api('payment_processor_type', 'delete', $params);
-
-    $this->assertEquals($result['is_error'], 1);
-    $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id');
+    $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
+    $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
   }
 
   /**
    * check with incorrect required fields
    */
   function testPaymentProcessorTypeDeleteWithIncorrectData() {
-    $params = array(
-      'id' => 'abcd',
-      'version' => $this->_apiversion,
-    );
-
-    $result = civicrm_api('payment_processor_type', 'delete', $params);
-
-    $this->assertEquals($result['is_error'], 1);
-    $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID');
+    $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
   }
 
   /**
@@ -169,15 +145,11 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
    */
   function testPaymentProcessorTypeDelete() {
     $payProcType = $this->paymentProcessorTypeCreate();
-    // create sample payment processor type.
     $params = array(
       'id' => $payProcType,
-      'version' => $this->_apiversion,
     );
 
-    $result = civicrm_api('payment_processor_type', 'delete', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals($result['is_error'], 0);
+    $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
   }
 
   ///////////////// civicrm_payment_processor_type_update
@@ -187,19 +159,15 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
    */
   function testPaymentProcessorTypeUpdateEmpty() {
     $params = array();
-    $result = civicrm_api('payment_processor_type', 'create', $params);
-
-    $this->assertEquals($result['is_error'], 1);
-    $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name, title, class_name, billing_mode');
+    $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
+    $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
   }
 
   /**
    * check with No array
    */
   function testPaymentProcessorTypeUpdateParamsNotArray() {
-    $result = civicrm_api('payment_processor_type', 'create', 'string');
-
-    $this->assertEquals($result['is_error'], 1);
+    $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
     $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
   }
 
@@ -216,13 +184,10 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
       'title' => 'API Test Payment Processor 2',
       'class_name' => 'CRM_Core_Payment_APITest 2',
       'billing_mode' => 2,
-      'is_recur' => 0,
-      'version' => $this->_apiversion,
-    );
+      'is_recur' => 0,    );
 
-    $result = civicrm_api('payment_processor_type', 'create', $params);
+    $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
     $this->assertNotNull($result['id']);
-    unset($params['version']);
     // assertDBState compares expected values in $result to actual values in the DB
     $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params);
   }
@@ -233,9 +198,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
    * check with empty array
    */
   function testPaymentProcessorTypesGetEmptyParams() {
-    $results = civicrm_api('payment_processor_type', 'get', array(
-      'version' => $this->_apiversion,
-    ));
+    $results = $this->callAPISuccess('payment_processor_type', 'get', array(    ));
     $baselineCount = $results['count'];
 
     $firstRelTypeParams = array(
@@ -243,35 +206,21 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
       'title' => 'API Test Payment Processor',
       'class_name' => 'CRM_Core_Payment_APITest',
       'billing_mode' => 1,
-      'is_recur' => 0,
-      'version' => $this->_apiversion,
-    );
+      'is_recur' => 0,    );
 
-    $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
+    $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
 
     $secondRelTypeParams = array(
       'name' => 'API_Test_PP2',
       'title' => 'API Test Payment Processor 2',
       'class_name' => 'CRM_Core_Payment_APITest 2',
       'billing_mode' => 2,
-      'is_recur' => 0,
-      'version' => $this->_apiversion,
-    );
-    $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
-    $results = civicrm_api('payment_processor_type', 'get', array(
-      'version' => $this->_apiversion,
-    ));
+      'is_recur' => 0,    );
+    $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
+    $result = $this->callAPISuccess('payment_processor_type', 'get', array(    ));
 
-    $this->assertEquals($baselineCount + 2, $results['count']);
-    $this->assertEquals(0, $results['is_error']);
-  }
-
-  /**
-   * check with params Not Array.
-   */
-  function testPaymentProcessorTypesGetParamsNotArray() {
-    $results = civicrm_api('payment_processor_type', 'get', 'string');
-    $this->assertEquals(1, $results['is_error']);
+    $this->assertEquals($baselineCount + 2, $result['count']);
+    $this->assertAPISuccess($result);
   }
 
   /**
@@ -283,31 +232,25 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
       'title' => 'API Test Payment Processor 11',
       'class_name' => 'CRM_Core_Payment_APITest_11',
       'billing_mode' => 1,
-      'is_recur' => 0,
-      'version' => $this->_apiversion,
-    );
+      'is_recur' => 0,    );
 
-    $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
+    $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
 
     $secondRelTypeParams = array(
       'name' => 'API_Test_PP_12',
       'title' => 'API Test Payment Processor 12',
       'class_name' => 'CRM_Core_Payment_APITest_12',
       'billing_mode' => 2,
-      'is_recur' => 0,
-      'version' => $this->_apiversion,
-    );
-    $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
+      'is_recur' => 0,    );
+    $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
 
     $params = array(
-      'name' => 'API_Test_PP_12',
-      'version' => $this->_apiversion,
-    );
-    $results = civicrm_api('payment_processor_type', 'get', $params);
+      'name' => 'API_Test_PP_12',    );
+    $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
 
-    $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__);
-    $this->assertEquals(1, $results['count'], ' in line ' . __LINE__);
-    $this->assertEquals('CRM_Core_Payment_APITest_12', $results['values'][$results['id']]['class_name'], ' in line ' . __LINE__);
+    $this->assertAPISuccess($result);
+    $this->assertEquals(1, $result['count'], ' in line ' . __LINE__);
+    $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__);
   }
 }