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;
40 'name' => 'PaymentProcessorType Create',
41 'description' => 'Test all PaymentProcessorType Create API methods.',
42 'group' => 'CiviCRM API Tests',
49 $this->_apiversion
= 3;
54 $tablesToTruncate = array(
55 'civicrm_payment_processor_type',
57 $this->quickCleanup($tablesToTruncate);
60 ///////////////// civicrm_payment_processor_type_add methods
65 function testPaymentProcessorTypeCreateWithoutName() {
66 $payProcParams = array(
68 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
69 $this->assertEquals($result['error_message'],
70 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
75 * create payment processor type
77 function testPaymentProcessorTypeCreate() {
78 $params = array( 'sequential' => 1,
79 'name' => 'API_Test_PP',
80 'title' => 'API Test Payment Processor',
81 'class_name' => 'CRM_Core_Payment_APITest',
82 'billing_mode' => 'form',
85 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
86 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
88 // mutate $params to match expected return value
89 unset($params['sequential']);
90 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
91 //assertDBState compares expected values in $result to actual values in the DB
92 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
96 * Test using example code
98 function testPaymentProcessorTypeCreateExample() {
99 require_once 'api/v3/examples/PaymentProcessorType/Create.php';
100 $result = payment_processor_type_create_example();
101 $expectedResult = payment_processor_type_create_expectedresult();
102 $this->assertAPISuccess($result);
105 ///////////////// civicrm_payment_processor_type_delete methods
108 * check with empty array
110 function testPaymentProcessorTypeDeleteEmpty() {
112 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
116 * check with No array
118 function testPaymentProcessorTypeDeleteParamsNotArray() {
119 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
123 * check if required fields are not passed
125 function testPaymentProcessorTypeDeleteWithoutRequired() {
127 'name' => 'API_Test_PP',
128 'title' => 'API Test Payment Processor',
129 'class_name' => 'CRM_Core_Payment_APITest',
132 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
133 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
137 * check with incorrect required fields
139 function testPaymentProcessorTypeDeleteWithIncorrectData() {
140 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
144 * check payment processor type delete
146 function testPaymentProcessorTypeDelete() {
147 $payProcType = $this->paymentProcessorTypeCreate();
149 'id' => $payProcType,
152 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
155 ///////////////// civicrm_payment_processor_type_update
158 * check with empty array
160 function testPaymentProcessorTypeUpdateEmpty() {
162 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
163 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
167 * check with No array
169 function testPaymentProcessorTypeUpdateParamsNotArray() {
170 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
171 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
175 * check with all parameters
177 function testPaymentProcessorTypeUpdate() {
178 // create sample payment processor type.
179 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
182 'id' => $this->_ppTypeID
,
183 'name' => 'API_Test_PP', // keep the same
184 'title' => 'API Test Payment Processor 2',
185 'class_name' => 'CRM_Core_Payment_APITest 2',
189 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
190 $this->assertNotNull($result['id']);
191 // assertDBState compares expected values in $result to actual values in the DB
192 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
195 ///////////////// civicrm_payment_processor_types_get methods
198 * check with empty array
200 function testPaymentProcessorTypesGetEmptyParams() {
201 $results = $this->callAPISuccess('payment_processor_type', 'get', array( ));
202 $baselineCount = $results['count'];
204 $firstRelTypeParams = array(
205 'name' => 'API_Test_PP',
206 'title' => 'API Test Payment Processor',
207 'class_name' => 'CRM_Core_Payment_APITest',
211 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
213 $secondRelTypeParams = array(
214 'name' => 'API_Test_PP2',
215 'title' => 'API Test Payment Processor 2',
216 'class_name' => 'CRM_Core_Payment_APITest 2',
219 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
220 $result = $this->callAPISuccess('payment_processor_type', 'get', array( ));
222 $this->assertEquals($baselineCount +
2, $result['count']);
223 $this->assertAPISuccess($result);
227 * check with valid params array.
229 function testPaymentProcessorTypesGet() {
230 $firstRelTypeParams = array(
231 'name' => 'API_Test_PP_11',
232 'title' => 'API Test Payment Processor 11',
233 'class_name' => 'CRM_Core_Payment_APITest_11',
237 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
239 $secondRelTypeParams = array(
240 'name' => 'API_Test_PP_12',
241 'title' => 'API Test Payment Processor 12',
242 'class_name' => 'CRM_Core_Payment_APITest_12',
245 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
248 'name' => 'API_Test_PP_12', );
249 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
251 $this->assertAPISuccess($result);
252 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
253 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);