3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class contains api test cases for "civicrm_payment_processor_type"
34 class api_v3_PaymentProcessorTypeTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
43 'name' => 'PaymentProcessorType Create',
44 'description' => 'Test all PaymentProcessorType Create API methods.',
45 'group' => 'CiviCRM API Tests',
52 $this->_apiversion
= 3;
57 $tablesToTruncate = array(
58 'civicrm_payment_processor_type',
60 $this->quickCleanup($tablesToTruncate);
63 ///////////////// civicrm_payment_processor_type_add methods
68 function testPaymentProcessorTypeCreateWithoutName() {
69 $payProcParams = array(
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() {
81 $params = array( 'sequential' => 1,
82 'name' => 'API_Test_PP',
83 'title' => 'API Test Payment Processor',
84 'class_name' => 'CRM_Core_Payment_APITest',
85 'billing_mode' => 'form',
88 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
89 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
91 // mutate $params to match expected return value
92 unset($params['sequential']);
93 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
94 //assertDBState compares expected values in $result to actual values in the DB
95 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
99 * Test using example code
101 function testPaymentProcessorTypeCreateExample() {
102 require_once 'api/v3/examples/PaymentProcessorType/Create.php';
103 $result = payment_processor_type_create_example();
104 $expectedResult = payment_processor_type_create_expectedresult();
105 $this->assertAPISuccess($result);
108 ///////////////// civicrm_payment_processor_type_delete methods
111 * check with empty array
113 function testPaymentProcessorTypeDeleteEmpty() {
115 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
119 * check with No array
121 function testPaymentProcessorTypeDeleteParamsNotArray() {
122 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
126 * check if required fields are not passed
128 function testPaymentProcessorTypeDeleteWithoutRequired() {
130 'name' => 'API_Test_PP',
131 'title' => 'API Test Payment Processor',
132 'class_name' => 'CRM_Core_Payment_APITest',
135 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
136 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
140 * check with incorrect required fields
142 function testPaymentProcessorTypeDeleteWithIncorrectData() {
143 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
147 * check payment processor type delete
149 function testPaymentProcessorTypeDelete() {
150 $payProcType = $this->paymentProcessorTypeCreate();
152 'id' => $payProcType,
155 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
158 ///////////////// civicrm_payment_processor_type_update
161 * check with empty array
163 function testPaymentProcessorTypeUpdateEmpty() {
165 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
166 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
170 * check with No array
172 function testPaymentProcessorTypeUpdateParamsNotArray() {
173 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
174 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
178 * check with all parameters
180 function testPaymentProcessorTypeUpdate() {
181 // create sample payment processor type.
182 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
185 'id' => $this->_ppTypeID
,
186 'name' => 'API_Test_PP', // keep the same
187 'title' => 'API Test Payment Processor 2',
188 'class_name' => 'CRM_Core_Payment_APITest 2',
192 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
193 $this->assertNotNull($result['id']);
194 // assertDBState compares expected values in $result to actual values in the DB
195 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
198 ///////////////// civicrm_payment_processor_types_get methods
201 * check with empty array
203 function testPaymentProcessorTypesGetEmptyParams() {
204 $results = $this->callAPISuccess('payment_processor_type', 'get', array( ));
205 $baselineCount = $results['count'];
207 $firstRelTypeParams = array(
208 'name' => 'API_Test_PP',
209 'title' => 'API Test Payment Processor',
210 'class_name' => 'CRM_Core_Payment_APITest',
214 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
216 $secondRelTypeParams = array(
217 'name' => 'API_Test_PP2',
218 'title' => 'API Test Payment Processor 2',
219 'class_name' => 'CRM_Core_Payment_APITest 2',
222 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
223 $result = $this->callAPISuccess('payment_processor_type', 'get', array( ));
225 $this->assertEquals($baselineCount +
2, $result['count']);
226 $this->assertAPISuccess($result);
230 * check with valid params array.
232 function testPaymentProcessorTypesGet() {
233 $firstRelTypeParams = array(
234 'name' => 'API_Test_PP_11',
235 'title' => 'API Test Payment Processor 11',
236 'class_name' => 'CRM_Core_Payment_APITest_11',
240 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
242 $secondRelTypeParams = array(
243 'name' => 'API_Test_PP_12',
244 'title' => 'API Test Payment Processor 12',
245 'class_name' => 'CRM_Core_Payment_APITest_12',
248 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
251 'name' => 'API_Test_PP_12', );
252 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
254 $this->assertAPISuccess($result);
255 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
256 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);