Add in Country and StateProvince APIv4 Entities
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
7d61e75f
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035 11
6a488035
TO
12/**
13 * Class contains api test cases for "civicrm_payment_processor_type"
14 *
acb109b7 15 * @group headless
6a488035
TO
16 */
17class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
6a488035
TO
18 protected $_ppTypeID;
19 protected $_apiversion;
b7c9bc4c 20
00be9182 21 public function setUp() {
6a488035
TO
22
23 parent::setUp();
1da902df 24 $this->useTransaction(TRUE);
6a488035 25 $this->_apiversion = 3;
6a488035
TO
26 }
27
6c6e6187
TO
28 // function tearDown() {
29 //
30 // $tablesToTruncate = array(
31 // 'civicrm_payment_processor_type',
32 // );
33 // $this->quickCleanup($tablesToTruncate);
34 // }
6a488035
TO
35
36 ///////////////// civicrm_payment_processor_type_add methods
37
38 /**
eceb18cc 39 * Check with no name.
6a488035 40 */
00be9182 41 public function testPaymentProcessorTypeCreateWithoutName() {
9099cab3 42 $payProcParams = [
92915c55 43 'is_active' => 1,
9099cab3 44 ];
d0e1eff2 45 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
6a488035
TO
46 $this->assertEquals($result['error_message'],
47 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
48 );
49 }
50
51 /**
eceb18cc 52 * Create payment processor type.
6a488035 53 */
00be9182 54 public function testPaymentProcessorTypeCreate() {
9099cab3 55 $params = [
92915c55 56 'sequential' => 1,
6a488035
TO
57 'name' => 'API_Test_PP',
58 'title' => 'API Test Payment Processor',
59 'class_name' => 'CRM_Core_Payment_APITest',
60 'billing_mode' => 'form',
61 'is_recur' => 0,
9099cab3 62 ];
fa7b9efb 63 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
ba4a1892 64 $this->assertNotNull($result['values'][0]['id']);
6a488035
TO
65
66 // mutate $params to match expected return value
6a488035
TO
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);
71 }
72
73 /**
eceb18cc 74 * Test using example code.
6a488035 75 */
00be9182 76 public function testPaymentProcessorTypeCreateExample() {
be44cfcb 77 require_once 'api/v3/examples/PaymentProcessorType/Create.ex.php';
6a488035
TO
78 $result = payment_processor_type_create_example();
79 $expectedResult = payment_processor_type_create_expectedresult();
48ab68c7 80 $this->assertAPISuccess($result);
6a488035
TO
81 }
82
83 ///////////////// civicrm_payment_processor_type_delete methods
84
85 /**
eceb18cc 86 * Check with empty array.
6a488035 87 */
00be9182 88 public function testPaymentProcessorTypeDeleteEmpty() {
9099cab3 89 $params = [];
d0e1eff2 90 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
6a488035
TO
91 }
92
6a488035 93 /**
eceb18cc 94 * Check if required fields are not passed.
6a488035 95 */
00be9182 96 public function testPaymentProcessorTypeDeleteWithoutRequired() {
9099cab3 97 $params = [
6a488035
TO
98 'name' => 'API_Test_PP',
99 'title' => 'API Test Payment Processor',
100 'class_name' => 'CRM_Core_Payment_APITest',
9099cab3 101 ];
6a488035 102
d0e1eff2
CW
103 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
104 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
6a488035
TO
105 }
106
107 /**
eceb18cc 108 * Check with incorrect required fields.
6a488035 109 */
00be9182 110 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
9099cab3 111 $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']);
6a488035
TO
112 }
113
114 /**
eceb18cc 115 * Check payment processor type delete.
6a488035 116 */
00be9182 117 public function testPaymentProcessorTypeDelete() {
6a488035 118 $payProcType = $this->paymentProcessorTypeCreate();
9099cab3 119 $params = [
6a488035 120 'id' => $payProcType,
9099cab3 121 ];
6a488035 122
fa7b9efb 123 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
6a488035
TO
124 }
125
126 ///////////////// civicrm_payment_processor_type_update
127
128 /**
eceb18cc 129 * Check with empty array.
6a488035 130 */
00be9182 131 public function testPaymentProcessorTypeUpdateEmpty() {
9099cab3 132 $params = [];
d0e1eff2
CW
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');
6a488035
TO
135 }
136
6a488035 137 /**
eceb18cc 138 * Check with all parameters.
6a488035 139 */
00be9182 140 public function testPaymentProcessorTypeUpdate() {
6a488035
TO
141 // create sample payment processor type.
142 $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
143
9099cab3 144 $params = [
6a488035 145 'id' => $this->_ppTypeID,
39b959db
SL
146 // keep the same
147 'name' => 'API_Test_PP',
6a488035
TO
148 'title' => 'API Test Payment Processor 2',
149 'class_name' => 'CRM_Core_Payment_APITest 2',
150 'billing_mode' => 2,
92915c55 151 'is_recur' => 0,
9099cab3 152 ];
6a488035 153
fa7b9efb 154 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
6a488035 155 $this->assertNotNull($result['id']);
6a488035
TO
156 // assertDBState compares expected values in $result to actual values in the DB
157 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params);
158 }
159
160 ///////////////// civicrm_payment_processor_types_get methods
161
162 /**
eceb18cc 163 * Check with empty array.
6a488035 164 */
00be9182 165 public function testPaymentProcessorTypesGetEmptyParams() {
9099cab3 166 $results = $this->callAPISuccess('payment_processor_type', 'get', []);
6a488035
TO
167 $baselineCount = $results['count'];
168
9099cab3 169 $firstRelTypeParams = [
6a488035
TO
170 'name' => 'API_Test_PP',
171 'title' => 'API Test Payment Processor',
172 'class_name' => 'CRM_Core_Payment_APITest',
173 'billing_mode' => 1,
92915c55 174 'is_recur' => 0,
9099cab3 175 ];
6a488035 176
fa7b9efb 177 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
6a488035 178
9099cab3 179 $secondRelTypeParams = [
6a488035
TO
180 'name' => 'API_Test_PP2',
181 'title' => 'API Test Payment Processor 2',
182 'class_name' => 'CRM_Core_Payment_APITest 2',
183 'billing_mode' => 2,
92915c55 184 'is_recur' => 0,
9099cab3 185 ];
fa7b9efb 186 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
9099cab3 187 $result = $this->callAPISuccess('payment_processor_type', 'get', []);
6a488035 188
48ab68c7 189 $this->assertEquals($baselineCount + 2, $result['count']);
190 $this->assertAPISuccess($result);
6a488035
TO
191 }
192
193 /**
100fef9d 194 * Check with valid params array.
6a488035 195 */
00be9182 196 public function testPaymentProcessorTypesGet() {
9099cab3 197 $firstRelTypeParams = [
6a488035
TO
198 'name' => 'API_Test_PP_11',
199 'title' => 'API Test Payment Processor 11',
200 'class_name' => 'CRM_Core_Payment_APITest_11',
201 'billing_mode' => 1,
92915c55 202 'is_recur' => 0,
9099cab3 203 ];
6a488035 204
fa7b9efb 205 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
6a488035 206
9099cab3 207 $secondRelTypeParams = [
6a488035
TO
208 'name' => 'API_Test_PP_12',
209 'title' => 'API Test Payment Processor 12',
210 'class_name' => 'CRM_Core_Payment_APITest_12',
211 'billing_mode' => 2,
92915c55 212 'is_recur' => 0,
9099cab3 213 ];
fa7b9efb 214 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
6a488035 215
9099cab3 216 $params = [
92915c55 217 'name' => 'API_Test_PP_12',
9099cab3 218 ];
fa7b9efb 219 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
6a488035 220
48ab68c7 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__);
6a488035 224 }
96025800 225
6a488035 226}