Commit | Line | Data |
---|---|---|
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 | ||
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | ||
31 | /** | |
32 | * Class contains api test cases for "civicrm_payment_processor_type" | |
33 | * | |
34 | */ | |
35 | class 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 | ); | |
d0e1eff2 | 71 | $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams); |
6a488035 TO |
72 | $this->assertEquals($result['error_message'], |
73 | 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode' | |
74 | ); | |
75 | } | |
76 | ||
77 | /** | |
78 | * create payment processor type | |
79 | */ | |
80 | function testPaymentProcessorTypeCreate() { | |
81 | $params = array( | |
82 | 'version' => $this->_apiversion, | |
83 | 'sequential' => 1, | |
84 | 'name' => 'API_Test_PP', | |
85 | 'title' => 'API Test Payment Processor', | |
86 | 'class_name' => 'CRM_Core_Payment_APITest', | |
87 | 'billing_mode' => 'form', | |
88 | 'is_recur' => 0, | |
89 | ); | |
90 | $result = civicrm_api('payment_processor_type', 'create', $params); | |
91 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
48ab68c7 | 92 | $this->assertAPISuccess($result); |
6a488035 TO |
93 | $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); |
94 | ||
95 | // mutate $params to match expected return value | |
96 | unset($params['version']); | |
97 | unset($params['sequential']); | |
98 | $params['billing_mode'] = CRM_Core_Payment::BILLING_MODE_FORM; | |
99 | //assertDBState compares expected values in $result to actual values in the DB | |
100 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Test using example code | |
105 | */ | |
106 | function testPaymentProcessorTypeCreateExample() { | |
107 | require_once 'api/v3/examples/PaymentProcessorTypeCreate.php'; | |
108 | $result = payment_processor_type_create_example(); | |
109 | $expectedResult = payment_processor_type_create_expectedresult(); | |
48ab68c7 | 110 | $this->assertAPISuccess($result); |
6a488035 TO |
111 | } |
112 | ||
113 | ///////////////// civicrm_payment_processor_type_delete methods | |
114 | ||
115 | /** | |
116 | * check with empty array | |
117 | */ | |
118 | function testPaymentProcessorTypeDeleteEmpty() { | |
119 | $params = array(); | |
d0e1eff2 | 120 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
6a488035 TO |
121 | } |
122 | ||
123 | /** | |
124 | * check with No array | |
125 | */ | |
126 | function testPaymentProcessorTypeDeleteParamsNotArray() { | |
d0e1eff2 | 127 | $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string'); |
6a488035 TO |
128 | } |
129 | ||
130 | /** | |
131 | * check if required fields are not passed | |
132 | */ | |
133 | function testPaymentProcessorTypeDeleteWithoutRequired() { | |
134 | $params = array( | |
135 | 'name' => 'API_Test_PP', | |
136 | 'title' => 'API Test Payment Processor', | |
137 | 'class_name' => 'CRM_Core_Payment_APITest', | |
138 | ); | |
139 | ||
d0e1eff2 CW |
140 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
141 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); | |
6a488035 TO |
142 | } |
143 | ||
144 | /** | |
145 | * check with incorrect required fields | |
146 | */ | |
147 | function testPaymentProcessorTypeDeleteWithIncorrectData() { | |
148 | $params = array( | |
149 | 'id' => 'abcd', | |
150 | 'version' => $this->_apiversion, | |
151 | ); | |
152 | ||
d0e1eff2 | 153 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
6a488035 TO |
154 | $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID'); |
155 | } | |
156 | ||
157 | /** | |
158 | * check payment processor type delete | |
159 | */ | |
160 | function testPaymentProcessorTypeDelete() { | |
161 | $payProcType = $this->paymentProcessorTypeCreate(); | |
162 | // create sample payment processor type. | |
163 | $params = array( | |
164 | 'id' => $payProcType, | |
165 | 'version' => $this->_apiversion, | |
166 | ); | |
167 | ||
168 | $result = civicrm_api('payment_processor_type', 'delete', $params); | |
169 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
48ab68c7 | 170 | $this->assertAPISuccess($result); |
6a488035 TO |
171 | } |
172 | ||
173 | ///////////////// civicrm_payment_processor_type_update | |
174 | ||
175 | /** | |
176 | * check with empty array | |
177 | */ | |
178 | function testPaymentProcessorTypeUpdateEmpty() { | |
179 | $params = array(); | |
d0e1eff2 CW |
180 | $result = $this->callAPIFailure('payment_processor_type', 'create', $params); |
181 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'); | |
6a488035 TO |
182 | } |
183 | ||
184 | /** | |
185 | * check with No array | |
186 | */ | |
187 | function testPaymentProcessorTypeUpdateParamsNotArray() { | |
d0e1eff2 | 188 | $result = $this->callAPIFailure('payment_processor_type', 'create', 'string'); |
6a488035 TO |
189 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
190 | } | |
191 | ||
192 | /** | |
193 | * check with all parameters | |
194 | */ | |
195 | function testPaymentProcessorTypeUpdate() { | |
196 | // create sample payment processor type. | |
197 | $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL); | |
198 | ||
199 | $params = array( | |
200 | 'id' => $this->_ppTypeID, | |
201 | 'name' => 'API_Test_PP', // keep the same | |
202 | 'title' => 'API Test Payment Processor 2', | |
203 | 'class_name' => 'CRM_Core_Payment_APITest 2', | |
204 | 'billing_mode' => 2, | |
205 | 'is_recur' => 0, | |
206 | 'version' => $this->_apiversion, | |
207 | ); | |
208 | ||
21150aae | 209 | $result = civicrm_api('payment_processor_type', 'create', $params); |
6a488035 TO |
210 | $this->assertNotNull($result['id']); |
211 | unset($params['version']); | |
212 | // assertDBState compares expected values in $result to actual values in the DB | |
213 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params); | |
214 | } | |
215 | ||
216 | ///////////////// civicrm_payment_processor_types_get methods | |
217 | ||
218 | /** | |
219 | * check with empty array | |
220 | */ | |
221 | function testPaymentProcessorTypesGetEmptyParams() { | |
222 | $results = civicrm_api('payment_processor_type', 'get', array( | |
223 | 'version' => $this->_apiversion, | |
224 | )); | |
225 | $baselineCount = $results['count']; | |
226 | ||
227 | $firstRelTypeParams = array( | |
228 | 'name' => 'API_Test_PP', | |
229 | 'title' => 'API Test Payment Processor', | |
230 | 'class_name' => 'CRM_Core_Payment_APITest', | |
231 | 'billing_mode' => 1, | |
232 | 'is_recur' => 0, | |
233 | 'version' => $this->_apiversion, | |
234 | ); | |
235 | ||
236 | $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams); | |
237 | ||
238 | $secondRelTypeParams = array( | |
239 | 'name' => 'API_Test_PP2', | |
240 | 'title' => 'API Test Payment Processor 2', | |
241 | 'class_name' => 'CRM_Core_Payment_APITest 2', | |
242 | 'billing_mode' => 2, | |
243 | 'is_recur' => 0, | |
244 | 'version' => $this->_apiversion, | |
245 | ); | |
246 | $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams); | |
48ab68c7 | 247 | $result = civicrm_api('payment_processor_type', 'get', array( |
6a488035 TO |
248 | 'version' => $this->_apiversion, |
249 | )); | |
250 | ||
48ab68c7 | 251 | $this->assertEquals($baselineCount + 2, $result['count']); |
252 | $this->assertAPISuccess($result); | |
6a488035 TO |
253 | } |
254 | ||
255 | /** | |
256 | * check with valid params array. | |
257 | */ | |
258 | function testPaymentProcessorTypesGet() { | |
259 | $firstRelTypeParams = array( | |
260 | 'name' => 'API_Test_PP_11', | |
261 | 'title' => 'API Test Payment Processor 11', | |
262 | 'class_name' => 'CRM_Core_Payment_APITest_11', | |
263 | 'billing_mode' => 1, | |
264 | 'is_recur' => 0, | |
265 | 'version' => $this->_apiversion, | |
266 | ); | |
267 | ||
268 | $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams); | |
269 | ||
270 | $secondRelTypeParams = array( | |
271 | 'name' => 'API_Test_PP_12', | |
272 | 'title' => 'API Test Payment Processor 12', | |
273 | 'class_name' => 'CRM_Core_Payment_APITest_12', | |
274 | 'billing_mode' => 2, | |
275 | 'is_recur' => 0, | |
276 | 'version' => $this->_apiversion, | |
277 | ); | |
278 | $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams); | |
279 | ||
280 | $params = array( | |
281 | 'name' => 'API_Test_PP_12', | |
282 | 'version' => $this->_apiversion, | |
283 | ); | |
48ab68c7 | 284 | $result = civicrm_api('payment_processor_type', 'get', $params); |
6a488035 | 285 | |
48ab68c7 | 286 | $this->assertAPISuccess($result); |
287 | $this->assertEquals(1, $result['count'], ' in line ' . __LINE__); | |
288 | $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__); | |
6a488035 TO |
289 | } |
290 | } | |
291 |