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 if required fields are not passed.
96 public function testPaymentProcessorTypeDeleteWithoutRequired() {
98 'name' => 'API_Test_PP',
99 'title' => 'API Test Payment Processor',
100 'class_name' => 'CRM_Core_Payment_APITest',
103 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
104 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
108 * Check with incorrect required fields.
110 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
111 $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']);
115 * Check payment processor type delete.
117 public function testPaymentProcessorTypeDelete() {
118 $payProcType = $this->paymentProcessorTypeCreate();
120 'id' => $payProcType,
123 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
126 ///////////////// civicrm_payment_processor_type_update
129 * Check with empty array.
131 public function testPaymentProcessorTypeUpdateEmpty() {
133 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
134 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
138 * Check with all parameters.
140 public function testPaymentProcessorTypeUpdate() {
141 // create sample payment processor type.
142 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
145 'id' => $this->_ppTypeID
,
147 'name' => 'API_Test_PP',
148 'title' => 'API Test Payment Processor 2',
149 'class_name' => 'CRM_Core_Payment_APITest 2',
154 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
155 $this->assertNotNull($result['id']);
156 // assertDBState compares expected values in $result to actual values in the DB
157 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
160 ///////////////// civicrm_payment_processor_types_get methods
163 * Check with empty array.
165 public function testPaymentProcessorTypesGetEmptyParams() {
166 $results = $this->callAPISuccess('payment_processor_type', 'get', []);
167 $baselineCount = $results['count'];
169 $firstRelTypeParams = [
170 'name' => 'API_Test_PP',
171 'title' => 'API Test Payment Processor',
172 'class_name' => 'CRM_Core_Payment_APITest',
177 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
179 $secondRelTypeParams = [
180 'name' => 'API_Test_PP2',
181 'title' => 'API Test Payment Processor 2',
182 'class_name' => 'CRM_Core_Payment_APITest 2',
186 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
187 $result = $this->callAPISuccess('payment_processor_type', 'get', []);
189 $this->assertEquals($baselineCount +
2, $result['count']);
190 $this->assertAPISuccess($result);
194 * Check with valid params array.
196 public function testPaymentProcessorTypesGet() {
197 $firstRelTypeParams = [
198 'name' => 'API_Test_PP_11',
199 'title' => 'API Test Payment Processor 11',
200 'class_name' => 'CRM_Core_Payment_APITest_11',
205 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
207 $secondRelTypeParams = [
208 'name' => 'API_Test_PP_12',
209 'title' => 'API Test Payment Processor 12',
210 'class_name' => 'CRM_Core_Payment_APITest_12',
214 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
217 'name' => 'API_Test_PP_12',
219 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
221 $this->assertAPISuccess($result);
222 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
223 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);