Add 'name' field to pseudoconstant schema CRM-12464
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27*/
28
29require_once 'CiviTest/CiviUnitTestCase.php';
30
31/**
32 * Class contains api test cases for "civicrm_payment_processor_type"
33 *
34 */
35class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
6a488035
TO
36 protected $_ppTypeID;
37 protected $_apiversion;
38 public $_eNoticeCompliant = TRUE;
39 function get_info() {
40 return array(
41 'name' => 'PaymentProcessorType Create',
42 'description' => 'Test all PaymentProcessorType Create API methods.',
43 'group' => 'CiviCRM API Tests',
44 );
45 }
46
47 function setUp() {
48
49 parent::setUp();
50 $this->_apiversion = 3;
6a488035
TO
51 }
52
53 function tearDown() {
54
55 $tablesToTruncate = array(
6a488035
TO
56 'civicrm_payment_processor_type',
57 );
58 $this->quickCleanup($tablesToTruncate);
59 }
60
61 ///////////////// civicrm_payment_processor_type_add methods
62
63 /**
64 * check with no name
65 */
66 function testPaymentProcessorTypeCreateWithoutName() {
67 $payProcParams = array(
68 'is_active' => 1,
69 'version' => $this->_apiversion,
70 );
71 $result = civicrm_api('payment_processor_type', 'create', $payProcParams);
72
48ab68c7 73 $this->assertAPIFailure($result);
6a488035
TO
74 $this->assertEquals($result['error_message'],
75 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
76 );
77 }
78
79 /**
80 * create payment processor type
81 */
82 function testPaymentProcessorTypeCreate() {
83 $params = array(
84 'version' => $this->_apiversion,
85 'sequential' => 1,
86 'name' => 'API_Test_PP',
87 'title' => 'API Test Payment Processor',
88 'class_name' => 'CRM_Core_Payment_APITest',
89 'billing_mode' => 'form',
90 'is_recur' => 0,
91 );
92 $result = civicrm_api('payment_processor_type', 'create', $params);
93 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
48ab68c7 94 $this->assertAPISuccess($result);
6a488035
TO
95 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__);
96
97 // mutate $params to match expected return value
98 unset($params['version']);
99 unset($params['sequential']);
100 $params['billing_mode'] = CRM_Core_Payment::BILLING_MODE_FORM;
101 //assertDBState compares expected values in $result to actual values in the DB
102 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
103 }
104
105 /**
106 * Test using example code
107 */
108 function testPaymentProcessorTypeCreateExample() {
109 require_once 'api/v3/examples/PaymentProcessorTypeCreate.php';
110 $result = payment_processor_type_create_example();
111 $expectedResult = payment_processor_type_create_expectedresult();
48ab68c7 112 $this->assertAPISuccess($result);
6a488035
TO
113 }
114
115 ///////////////// civicrm_payment_processor_type_delete methods
116
117 /**
118 * check with empty array
119 */
120 function testPaymentProcessorTypeDeleteEmpty() {
121 $params = array();
122 $result = civicrm_api('payment_processor_type', 'delete', $params);
48ab68c7 123 $this->assertAPIFailure($result);
6a488035
TO
124 }
125
126 /**
127 * check with No array
128 */
129 function testPaymentProcessorTypeDeleteParamsNotArray() {
130 $result = civicrm_api('payment_processor_type', 'delete', 'string');
48ab68c7 131 $this->assertAPIFailure($result);
6a488035
TO
132 }
133
134 /**
135 * check if required fields are not passed
136 */
137 function testPaymentProcessorTypeDeleteWithoutRequired() {
138 $params = array(
139 'name' => 'API_Test_PP',
140 'title' => 'API Test Payment Processor',
141 'class_name' => 'CRM_Core_Payment_APITest',
142 );
143
144 $result = civicrm_api('payment_processor_type', 'delete', $params);
145
48ab68c7 146 $this->assertAPIFailure($result);
6a488035
TO
147 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id');
148 }
149
150 /**
151 * check with incorrect required fields
152 */
153 function testPaymentProcessorTypeDeleteWithIncorrectData() {
154 $params = array(
155 'id' => 'abcd',
156 'version' => $this->_apiversion,
157 );
158
159 $result = civicrm_api('payment_processor_type', 'delete', $params);
160
48ab68c7 161 $this->assertAPIFailure($result);
6a488035
TO
162 $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID');
163 }
164
165 /**
166 * check payment processor type delete
167 */
168 function testPaymentProcessorTypeDelete() {
169 $payProcType = $this->paymentProcessorTypeCreate();
170 // create sample payment processor type.
171 $params = array(
172 'id' => $payProcType,
173 'version' => $this->_apiversion,
174 );
175
176 $result = civicrm_api('payment_processor_type', 'delete', $params);
177 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
48ab68c7 178 $this->assertAPISuccess($result);
6a488035
TO
179 }
180
181 ///////////////// civicrm_payment_processor_type_update
182
183 /**
184 * check with empty array
185 */
186 function testPaymentProcessorTypeUpdateEmpty() {
187 $params = array();
188 $result = civicrm_api('payment_processor_type', 'create', $params);
189
48ab68c7 190 $this->assertAPIFailure($result);
6a488035
TO
191 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name, title, class_name, billing_mode');
192 }
193
194 /**
195 * check with No array
196 */
197 function testPaymentProcessorTypeUpdateParamsNotArray() {
198 $result = civicrm_api('payment_processor_type', 'create', 'string');
199
48ab68c7 200 $this->assertAPIFailure($result);
6a488035
TO
201 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
202 }
203
204 /**
205 * check with all parameters
206 */
207 function testPaymentProcessorTypeUpdate() {
208 // create sample payment processor type.
209 $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
210
211 $params = array(
212 'id' => $this->_ppTypeID,
213 'name' => 'API_Test_PP', // keep the same
214 'title' => 'API Test Payment Processor 2',
215 'class_name' => 'CRM_Core_Payment_APITest 2',
216 'billing_mode' => 2,
217 'is_recur' => 0,
218 'version' => $this->_apiversion,
219 );
220
21150aae 221 $result = civicrm_api('payment_processor_type', 'create', $params);
6a488035
TO
222 $this->assertNotNull($result['id']);
223 unset($params['version']);
224 // assertDBState compares expected values in $result to actual values in the DB
225 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params);
226 }
227
228 ///////////////// civicrm_payment_processor_types_get methods
229
230 /**
231 * check with empty array
232 */
233 function testPaymentProcessorTypesGetEmptyParams() {
234 $results = civicrm_api('payment_processor_type', 'get', array(
235 'version' => $this->_apiversion,
236 ));
237 $baselineCount = $results['count'];
238
239 $firstRelTypeParams = array(
240 'name' => 'API_Test_PP',
241 'title' => 'API Test Payment Processor',
242 'class_name' => 'CRM_Core_Payment_APITest',
243 'billing_mode' => 1,
244 'is_recur' => 0,
245 'version' => $this->_apiversion,
246 );
247
248 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
249
250 $secondRelTypeParams = array(
251 'name' => 'API_Test_PP2',
252 'title' => 'API Test Payment Processor 2',
253 'class_name' => 'CRM_Core_Payment_APITest 2',
254 'billing_mode' => 2,
255 'is_recur' => 0,
256 'version' => $this->_apiversion,
257 );
258 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
48ab68c7 259 $result = civicrm_api('payment_processor_type', 'get', array(
6a488035
TO
260 'version' => $this->_apiversion,
261 ));
262
48ab68c7 263 $this->assertEquals($baselineCount + 2, $result['count']);
264 $this->assertAPISuccess($result);
6a488035
TO
265 }
266
267 /**
268 * check with valid params array.
269 */
270 function testPaymentProcessorTypesGet() {
271 $firstRelTypeParams = array(
272 'name' => 'API_Test_PP_11',
273 'title' => 'API Test Payment Processor 11',
274 'class_name' => 'CRM_Core_Payment_APITest_11',
275 'billing_mode' => 1,
276 'is_recur' => 0,
277 'version' => $this->_apiversion,
278 );
279
280 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
281
282 $secondRelTypeParams = array(
283 'name' => 'API_Test_PP_12',
284 'title' => 'API Test Payment Processor 12',
285 'class_name' => 'CRM_Core_Payment_APITest_12',
286 'billing_mode' => 2,
287 'is_recur' => 0,
288 'version' => $this->_apiversion,
289 );
290 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
291
292 $params = array(
293 'name' => 'API_Test_PP_12',
294 'version' => $this->_apiversion,
295 );
48ab68c7 296 $result = civicrm_api('payment_processor_type', 'get', $params);
6a488035 297
48ab68c7 298 $this->assertAPISuccess($result);
299 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__);
300 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__);
6a488035
TO
301 }
302}
303