Merge pull request #15820 from seamuslee001/dev_core_183_custom_contribsybnt
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class contains api test cases for "civicrm_payment_processor_type"
14 *
15 * @group headless
16 */
17 class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
18 protected $_ppTypeID;
19 protected $_apiversion;
20
21 public function setUp() {
22
23 parent::setUp();
24 $this->useTransaction(TRUE);
25 $this->_apiversion = 3;
26 }
27
28 // function tearDown() {
29 //
30 // $tablesToTruncate = array(
31 // 'civicrm_payment_processor_type',
32 // );
33 // $this->quickCleanup($tablesToTruncate);
34 // }
35
36 ///////////////// civicrm_payment_processor_type_add methods
37
38 /**
39 * Check with no name.
40 */
41 public function testPaymentProcessorTypeCreateWithoutName() {
42 $payProcParams = [
43 'is_active' => 1,
44 ];
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'
48 );
49 }
50
51 /**
52 * Create payment processor type.
53 */
54 public function testPaymentProcessorTypeCreate() {
55 $params = [
56 'sequential' => 1,
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,
62 ];
63 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
64 $this->assertNotNull($result['values'][0]['id']);
65
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);
71 }
72
73 /**
74 * Test using example code.
75 */
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);
81 }
82
83 ///////////////// civicrm_payment_processor_type_delete methods
84
85 /**
86 * Check with empty array.
87 */
88 public function testPaymentProcessorTypeDeleteEmpty() {
89 $params = [];
90 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
91 }
92
93 /**
94 * Check if required fields are not passed.
95 */
96 public function testPaymentProcessorTypeDeleteWithoutRequired() {
97 $params = [
98 'name' => 'API_Test_PP',
99 'title' => 'API Test Payment Processor',
100 'class_name' => 'CRM_Core_Payment_APITest',
101 ];
102
103 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
104 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
105 }
106
107 /**
108 * Check with incorrect required fields.
109 */
110 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
111 $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']);
112 }
113
114 /**
115 * Check payment processor type delete.
116 */
117 public function testPaymentProcessorTypeDelete() {
118 $payProcType = $this->paymentProcessorTypeCreate();
119 $params = [
120 'id' => $payProcType,
121 ];
122
123 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
124 }
125
126 ///////////////// civicrm_payment_processor_type_update
127
128 /**
129 * Check with empty array.
130 */
131 public function testPaymentProcessorTypeUpdateEmpty() {
132 $params = [];
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');
135 }
136
137 /**
138 * Check with all parameters.
139 */
140 public function testPaymentProcessorTypeUpdate() {
141 // create sample payment processor type.
142 $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
143
144 $params = [
145 'id' => $this->_ppTypeID,
146 // keep the same
147 'name' => 'API_Test_PP',
148 'title' => 'API Test Payment Processor 2',
149 'class_name' => 'CRM_Core_Payment_APITest 2',
150 'billing_mode' => 2,
151 'is_recur' => 0,
152 ];
153
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);
158 }
159
160 ///////////////// civicrm_payment_processor_types_get methods
161
162 /**
163 * Check with empty array.
164 */
165 public function testPaymentProcessorTypesGetEmptyParams() {
166 $results = $this->callAPISuccess('payment_processor_type', 'get', []);
167 $baselineCount = $results['count'];
168
169 $firstRelTypeParams = [
170 'name' => 'API_Test_PP',
171 'title' => 'API Test Payment Processor',
172 'class_name' => 'CRM_Core_Payment_APITest',
173 'billing_mode' => 1,
174 'is_recur' => 0,
175 ];
176
177 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
178
179 $secondRelTypeParams = [
180 'name' => 'API_Test_PP2',
181 'title' => 'API Test Payment Processor 2',
182 'class_name' => 'CRM_Core_Payment_APITest 2',
183 'billing_mode' => 2,
184 'is_recur' => 0,
185 ];
186 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
187 $result = $this->callAPISuccess('payment_processor_type', 'get', []);
188
189 $this->assertEquals($baselineCount + 2, $result['count']);
190 $this->assertAPISuccess($result);
191 }
192
193 /**
194 * Check with valid params array.
195 */
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',
201 'billing_mode' => 1,
202 'is_recur' => 0,
203 ];
204
205 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
206
207 $secondRelTypeParams = [
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,
212 'is_recur' => 0,
213 ];
214 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
215
216 $params = [
217 'name' => 'API_Test_PP_12',
218 ];
219 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
220
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__);
224 }
225
226 }