4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Class contains api test cases for "civicrm_payment_processor_type"
35 class api_v3_PaymentProcessorTypeTest
extends CiviUnitTestCase
{
37 protected $_apiversion;
38 public $_eNoticeCompliant = TRUE;
41 'name' => 'PaymentProcessorType Create',
42 'description' => 'Test all PaymentProcessorType Create API methods.',
43 'group' => 'CiviCRM API Tests',
50 $this->_apiversion
= 3;
55 $tablesToTruncate = array(
56 'civicrm_payment_processor_type',
58 $this->quickCleanup($tablesToTruncate);
61 ///////////////// civicrm_payment_processor_type_add methods
66 function testPaymentProcessorTypeCreateWithoutName() {
67 $payProcParams = array(
69 'version' => $this->_apiversion
,
71 $result = civicrm_api('payment_processor_type', 'create', $payProcParams);
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'
80 * create payment processor type
82 function testPaymentProcessorTypeCreate() {
84 'version' => $this->_apiversion
,
86 'name' => 'API_Test_PP',
87 'title' => 'API Test Payment Processor',
88 'class_name' => 'CRM_Core_Payment_APITest',
89 'billing_mode' => 'form',
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__
);
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);
105 * Test using example code
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);
114 ///////////////// civicrm_payment_processor_type_delete methods
117 * check with empty array
119 function testPaymentProcessorTypeDeleteEmpty() {
121 $result = civicrm_api('payment_processor_type', 'delete', $params);
123 $this->assertEquals($result['is_error'], 1);
127 * check with No array
129 function testPaymentProcessorTypeDeleteParamsNotArray() {
130 $result = civicrm_api('payment_processor_type', 'delete', 'string');
132 $this->assertEquals($result['is_error'], 1);
136 * check if required fields are not passed
138 function testPaymentProcessorTypeDeleteWithoutRequired() {
140 'name' => 'API_Test_PP',
141 'title' => 'API Test Payment Processor',
142 'class_name' => 'CRM_Core_Payment_APITest',
145 $result = civicrm_api('payment_processor_type', 'delete', $params);
147 $this->assertEquals($result['is_error'], 1);
148 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id');
152 * check with incorrect required fields
154 function testPaymentProcessorTypeDeleteWithIncorrectData() {
157 'version' => $this->_apiversion
,
160 $result = civicrm_api('payment_processor_type', 'delete', $params);
162 $this->assertEquals($result['is_error'], 1);
163 $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID');
167 * check payment processor type delete
169 function testPaymentProcessorTypeDelete() {
170 $payProcType = $this->paymentProcessorTypeCreate();
171 // create sample payment processor type.
173 'id' => $payProcType,
174 'version' => $this->_apiversion
,
177 $result = civicrm_api('payment_processor_type', 'delete', $params);
178 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
179 $this->assertEquals($result['is_error'], 0);
182 ///////////////// civicrm_payment_processor_type_update
185 * check with empty array
187 function testPaymentProcessorTypeUpdateEmpty() {
189 $result = civicrm_api('payment_processor_type', 'create', $params);
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');
196 * check with No array
198 function testPaymentProcessorTypeUpdateParamsNotArray() {
199 $result = civicrm_api('payment_processor_type', 'create', 'string');
201 $this->assertEquals($result['is_error'], 1);
202 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
206 * check with all parameters
208 function testPaymentProcessorTypeUpdate() {
209 // create sample payment processor type.
210 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
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',
219 'version' => $this->_apiversion
,
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);
229 ///////////////// civicrm_payment_processor_types_get methods
232 * check with empty array
234 function testPaymentProcessorTypesGetEmptyParams() {
235 $results = civicrm_api('payment_processor_type', 'get', array(
236 'version' => $this->_apiversion
,
238 $baselineCount = $results['count'];
240 $firstRelTypeParams = array(
241 'name' => 'API_Test_PP',
242 'title' => 'API Test Payment Processor',
243 'class_name' => 'CRM_Core_Payment_APITest',
246 'version' => $this->_apiversion
,
249 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
251 $secondRelTypeParams = array(
252 'name' => 'API_Test_PP2',
253 'title' => 'API Test Payment Processor 2',
254 'class_name' => 'CRM_Core_Payment_APITest 2',
257 'version' => $this->_apiversion
,
259 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
260 $results = civicrm_api('payment_processor_type', 'get', array(
261 'version' => $this->_apiversion
,
264 $this->assertEquals($baselineCount +
2, $results['count']);
265 $this->assertEquals(0, $results['is_error']);
269 * check with params Not Array.
271 function testPaymentProcessorTypesGetParamsNotArray() {
272 $results = civicrm_api('payment_processor_type', 'get', 'string');
273 $this->assertEquals(1, $results['is_error']);
277 * check with valid params array.
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',
286 'version' => $this->_apiversion
,
289 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
291 $secondRelTypeParams = array(
292 'name' => 'API_Test_PP_12',
293 'title' => 'API Test Payment Processor 12',
294 'class_name' => 'CRM_Core_Payment_APITest_12',
297 'version' => $this->_apiversion
,
299 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
302 'name' => 'API_Test_PP_12',
303 'version' => $this->_apiversion
,
305 $results = civicrm_api('payment_processor_type', 'get', $params);
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__
);