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