3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class contains api test cases for "civicrm_payment_processor_type"
17 class api_v3_PaymentProcessorTypeTest
extends CiviUnitTestCase
{
19 protected $_apiversion;
21 public function setUp() {
24 $this->useTransaction(TRUE);
25 $this->_apiversion
= 3;
28 // function tearDown() {
30 // $tablesToTruncate = array(
31 // 'civicrm_payment_processor_type',
33 // $this->quickCleanup($tablesToTruncate);
36 ///////////////// civicrm_payment_processor_type_add methods
41 public function testPaymentProcessorTypeCreateWithoutName() {
45 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
46 $this->assertEquals($result['error_message'],
47 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
52 * Create payment processor type.
54 public function testPaymentProcessorTypeCreate() {
57 'name' => 'API_Test_PP',
58 'title' => 'API Test Payment Processor',
59 'class_name' => 'CRM_Core_Payment_APITest',
60 'billing_mode' => 'form',
63 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
64 $this->assertNotNull($result['values'][0]['id']);
66 // mutate $params to match expected return value
67 unset($params['sequential']);
68 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
69 //assertDBState compares expected values in $result to actual values in the DB
70 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
74 * Test using example code.
76 public function testPaymentProcessorTypeCreateExample() {
77 require_once 'api/v3/examples/PaymentProcessorType/Create.ex.php';
78 $result = payment_processor_type_create_example();
79 $expectedResult = payment_processor_type_create_expectedresult();
80 $this->assertAPISuccess($result);
83 ///////////////// civicrm_payment_processor_type_delete methods
86 * Check with empty array.
88 public function testPaymentProcessorTypeDeleteEmpty() {
90 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
94 * Check with No array.
96 public function testPaymentProcessorTypeDeleteParamsNotArray() {
97 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
101 * Check if required fields are not passed.
103 public function testPaymentProcessorTypeDeleteWithoutRequired() {
105 'name' => 'API_Test_PP',
106 'title' => 'API Test Payment Processor',
107 'class_name' => 'CRM_Core_Payment_APITest',
110 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
111 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
115 * Check with incorrect required fields.
117 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
118 $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']);
122 * Check payment processor type delete.
124 public function testPaymentProcessorTypeDelete() {
125 $payProcType = $this->paymentProcessorTypeCreate();
127 'id' => $payProcType,
130 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
133 ///////////////// civicrm_payment_processor_type_update
136 * Check with empty array.
138 public function testPaymentProcessorTypeUpdateEmpty() {
140 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
141 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
145 * Check with No array.
147 public function testPaymentProcessorTypeUpdateParamsNotArray() {
148 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
149 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
153 * Check with all parameters.
155 public function testPaymentProcessorTypeUpdate() {
156 // create sample payment processor type.
157 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
160 'id' => $this->_ppTypeID
,
162 'name' => 'API_Test_PP',
163 'title' => 'API Test Payment Processor 2',
164 'class_name' => 'CRM_Core_Payment_APITest 2',
169 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
170 $this->assertNotNull($result['id']);
171 // assertDBState compares expected values in $result to actual values in the DB
172 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
175 ///////////////// civicrm_payment_processor_types_get methods
178 * Check with empty array.
180 public function testPaymentProcessorTypesGetEmptyParams() {
181 $results = $this->callAPISuccess('payment_processor_type', 'get', []);
182 $baselineCount = $results['count'];
184 $firstRelTypeParams = [
185 'name' => 'API_Test_PP',
186 'title' => 'API Test Payment Processor',
187 'class_name' => 'CRM_Core_Payment_APITest',
192 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
194 $secondRelTypeParams = [
195 'name' => 'API_Test_PP2',
196 'title' => 'API Test Payment Processor 2',
197 'class_name' => 'CRM_Core_Payment_APITest 2',
201 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
202 $result = $this->callAPISuccess('payment_processor_type', 'get', []);
204 $this->assertEquals($baselineCount +
2, $result['count']);
205 $this->assertAPISuccess($result);
209 * Check with valid params array.
211 public function testPaymentProcessorTypesGet() {
212 $firstRelTypeParams = [
213 'name' => 'API_Test_PP_11',
214 'title' => 'API Test Payment Processor 11',
215 'class_name' => 'CRM_Core_Payment_APITest_11',
220 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
222 $secondRelTypeParams = [
223 'name' => 'API_Test_PP_12',
224 'title' => 'API Test Payment Processor 12',
225 'class_name' => 'CRM_Core_Payment_APITest_12',
229 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
232 'name' => 'API_Test_PP_12',
234 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
236 $this->assertAPISuccess($result);
237 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
238 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);