CRM-12595 fix formatting in tests files
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
1 <?php
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 {
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;
51 }
52
53 function tearDown() {
54
55 $tablesToTruncate = array(
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
73 $this->assertEquals($result['is_error'], 1);
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__);
94 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__);
95
96 // mutate $params to match expected return value
97 unset($params['version']);
98 unset($params['sequential']);
99 $params['billing_mode'] = CRM_Core_Payment::BILLING_MODE_FORM;
100 //assertDBState compares expected values in $result to actual values in the DB
101 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
102 }
103
104 /**
105 * Test using example code
106 */
107 function testPaymentProcessorTypeCreateExample() {
108 require_once 'api/v3/examples/PaymentProcessorTypeCreate.php';
109 $result = payment_processor_type_create_example();
110 $expectedResult = payment_processor_type_create_expectedresult();
111 $this->assertEquals($result['is_error'], 0);
112 }
113
114 ///////////////// civicrm_payment_processor_type_delete methods
115
116 /**
117 * check with empty array
118 */
119 function testPaymentProcessorTypeDeleteEmpty() {
120 $params = array();
121 $result = civicrm_api('payment_processor_type', 'delete', $params);
122
123 $this->assertEquals($result['is_error'], 1);
124 }
125
126 /**
127 * check with No array
128 */
129 function testPaymentProcessorTypeDeleteParamsNotArray() {
130 $result = civicrm_api('payment_processor_type', 'delete', 'string');
131
132 $this->assertEquals($result['is_error'], 1);
133 }
134
135 /**
136 * check if required fields are not passed
137 */
138 function testPaymentProcessorTypeDeleteWithoutRequired() {
139 $params = array(
140 'name' => 'API_Test_PP',
141 'title' => 'API Test Payment Processor',
142 'class_name' => 'CRM_Core_Payment_APITest',
143 );
144
145 $result = civicrm_api('payment_processor_type', 'delete', $params);
146
147 $this->assertEquals($result['is_error'], 1);
148 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id');
149 }
150
151 /**
152 * check with incorrect required fields
153 */
154 function testPaymentProcessorTypeDeleteWithIncorrectData() {
155 $params = array(
156 'id' => 'abcd',
157 'version' => $this->_apiversion,
158 );
159
160 $result = civicrm_api('payment_processor_type', 'delete', $params);
161
162 $this->assertEquals($result['is_error'], 1);
163 $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID');
164 }
165
166 /**
167 * check payment processor type delete
168 */
169 function testPaymentProcessorTypeDelete() {
170 $payProcType = $this->paymentProcessorTypeCreate();
171 // create sample payment processor type.
172 $params = array(
173 'id' => $payProcType,
174 'version' => $this->_apiversion,
175 );
176
177 $result = civicrm_api('payment_processor_type', 'delete', $params);
178 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
179 $this->assertEquals($result['is_error'], 0);
180 }
181
182 ///////////////// civicrm_payment_processor_type_update
183
184 /**
185 * check with empty array
186 */
187 function testPaymentProcessorTypeUpdateEmpty() {
188 $params = array();
189 $result = civicrm_api('payment_processor_type', 'create', $params);
190
191 $this->assertEquals($result['is_error'], 1);
192 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name, title, class_name, billing_mode');
193 }
194
195 /**
196 * check with No array
197 */
198 function testPaymentProcessorTypeUpdateParamsNotArray() {
199 $result = civicrm_api('payment_processor_type', 'create', 'string');
200
201 $this->assertEquals($result['is_error'], 1);
202 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
203 }
204
205 /**
206 * check with all parameters
207 */
208 function testPaymentProcessorTypeUpdate() {
209 // create sample payment processor type.
210 $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
211
212 $params = array(
213 'id' => $this->_ppTypeID,
214 'name' => 'API_Test_PP', // keep the same
215 'title' => 'API Test Payment Processor 2',
216 'class_name' => 'CRM_Core_Payment_APITest 2',
217 'billing_mode' => 2,
218 'is_recur' => 0,
219 'version' => $this->_apiversion,
220 );
221
222 $result = civicrm_api('payment_processor_type', 'create', $params);
223 $this->assertNotNull($result['id']);
224 unset($params['version']);
225 // assertDBState compares expected values in $result to actual values in the DB
226 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params);
227 }
228
229 ///////////////// civicrm_payment_processor_types_get methods
230
231 /**
232 * check with empty array
233 */
234 function testPaymentProcessorTypesGetEmptyParams() {
235 $results = civicrm_api('payment_processor_type', 'get', array(
236 'version' => $this->_apiversion,
237 ));
238 $baselineCount = $results['count'];
239
240 $firstRelTypeParams = array(
241 'name' => 'API_Test_PP',
242 'title' => 'API Test Payment Processor',
243 'class_name' => 'CRM_Core_Payment_APITest',
244 'billing_mode' => 1,
245 'is_recur' => 0,
246 'version' => $this->_apiversion,
247 );
248
249 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
250
251 $secondRelTypeParams = array(
252 'name' => 'API_Test_PP2',
253 'title' => 'API Test Payment Processor 2',
254 'class_name' => 'CRM_Core_Payment_APITest 2',
255 'billing_mode' => 2,
256 'is_recur' => 0,
257 'version' => $this->_apiversion,
258 );
259 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
260 $results = civicrm_api('payment_processor_type', 'get', array(
261 'version' => $this->_apiversion,
262 ));
263
264 $this->assertEquals($baselineCount + 2, $results['count']);
265 $this->assertEquals(0, $results['is_error']);
266 }
267
268 /**
269 * check with params Not Array.
270 */
271 function testPaymentProcessorTypesGetParamsNotArray() {
272 $results = civicrm_api('payment_processor_type', 'get', 'string');
273 $this->assertEquals(1, $results['is_error']);
274 }
275
276 /**
277 * check with valid params array.
278 */
279 function testPaymentProcessorTypesGet() {
280 $firstRelTypeParams = array(
281 'name' => 'API_Test_PP_11',
282 'title' => 'API Test Payment Processor 11',
283 'class_name' => 'CRM_Core_Payment_APITest_11',
284 'billing_mode' => 1,
285 'is_recur' => 0,
286 'version' => $this->_apiversion,
287 );
288
289 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
290
291 $secondRelTypeParams = array(
292 'name' => 'API_Test_PP_12',
293 'title' => 'API Test Payment Processor 12',
294 'class_name' => 'CRM_Core_Payment_APITest_12',
295 'billing_mode' => 2,
296 'is_recur' => 0,
297 'version' => $this->_apiversion,
298 );
299 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
300
301 $params = array(
302 'name' => 'API_Test_PP_12',
303 'version' => $this->_apiversion,
304 );
305 $results = civicrm_api('payment_processor_type', 'get', $params);
306
307 $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__);
308 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__);
309 $this->assertEquals('CRM_Core_Payment_APITest_12', $results['values'][$results['id']]['class_name'], ' in line ' . __LINE__);
310 }
311 }
312