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 = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
72 $this->assertEquals($result['error_message'],
73 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
78 * create payment processor type
80 function testPaymentProcessorTypeCreate() {
82 'version' => $this->_apiversion
,
84 'name' => 'API_Test_PP',
85 'title' => 'API Test Payment Processor',
86 'class_name' => 'CRM_Core_Payment_APITest',
87 'billing_mode' => 'form',
90 $result = civicrm_api('payment_processor_type', 'create', $params);
91 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
92 $this->assertAPISuccess($result);
93 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
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);
104 * Test using example code
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();
110 $this->assertAPISuccess($result);
113 ///////////////// civicrm_payment_processor_type_delete methods
116 * check with empty array
118 function testPaymentProcessorTypeDeleteEmpty() {
120 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
124 * check with No array
126 function testPaymentProcessorTypeDeleteParamsNotArray() {
127 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
131 * check if required fields are not passed
133 function testPaymentProcessorTypeDeleteWithoutRequired() {
135 'name' => 'API_Test_PP',
136 'title' => 'API Test Payment Processor',
137 'class_name' => 'CRM_Core_Payment_APITest',
140 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
141 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
145 * check with incorrect required fields
147 function testPaymentProcessorTypeDeleteWithIncorrectData() {
150 'version' => $this->_apiversion
,
153 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
154 $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID');
158 * check payment processor type delete
160 function testPaymentProcessorTypeDelete() {
161 $payProcType = $this->paymentProcessorTypeCreate();
162 // create sample payment processor type.
164 'id' => $payProcType,
165 'version' => $this->_apiversion
,
168 $result = civicrm_api('payment_processor_type', 'delete', $params);
169 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
170 $this->assertAPISuccess($result);
173 ///////////////// civicrm_payment_processor_type_update
176 * check with empty array
178 function testPaymentProcessorTypeUpdateEmpty() {
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');
185 * check with No array
187 function testPaymentProcessorTypeUpdateParamsNotArray() {
188 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
189 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
193 * check with all parameters
195 function testPaymentProcessorTypeUpdate() {
196 // create sample payment processor type.
197 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
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',
206 'version' => $this->_apiversion
,
209 $result = civicrm_api('payment_processor_type', 'create', $params);
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);
216 ///////////////// civicrm_payment_processor_types_get methods
219 * check with empty array
221 function testPaymentProcessorTypesGetEmptyParams() {
222 $results = civicrm_api('payment_processor_type', 'get', array(
223 'version' => $this->_apiversion
,
225 $baselineCount = $results['count'];
227 $firstRelTypeParams = array(
228 'name' => 'API_Test_PP',
229 'title' => 'API Test Payment Processor',
230 'class_name' => 'CRM_Core_Payment_APITest',
233 'version' => $this->_apiversion
,
236 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
238 $secondRelTypeParams = array(
239 'name' => 'API_Test_PP2',
240 'title' => 'API Test Payment Processor 2',
241 'class_name' => 'CRM_Core_Payment_APITest 2',
244 'version' => $this->_apiversion
,
246 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
247 $result = civicrm_api('payment_processor_type', 'get', array(
248 'version' => $this->_apiversion
,
251 $this->assertEquals($baselineCount +
2, $result['count']);
252 $this->assertAPISuccess($result);
256 * check with valid params array.
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',
265 'version' => $this->_apiversion
,
268 $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams);
270 $secondRelTypeParams = array(
271 'name' => 'API_Test_PP_12',
272 'title' => 'API Test Payment Processor 12',
273 'class_name' => 'CRM_Core_Payment_APITest_12',
276 'version' => $this->_apiversion
,
278 $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams);
281 'name' => 'API_Test_PP_12',
282 'version' => $this->_apiversion
,
284 $result = civicrm_api('payment_processor_type', 'get', $params);
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__
);