3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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;
38 public function setUp() {
41 $this->useTransaction(TRUE);
42 $this->_apiversion
= 3;
45 // function tearDown() {
47 // $tablesToTruncate = array(
48 // 'civicrm_payment_processor_type',
50 // $this->quickCleanup($tablesToTruncate);
53 ///////////////// civicrm_payment_processor_type_add methods
58 public function testPaymentProcessorTypeCreateWithoutName() {
59 $payProcParams = array(
62 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
63 $this->assertEquals($result['error_message'],
64 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
69 * Create payment processor type.
71 public function testPaymentProcessorTypeCreate() {
74 'name' => 'API_Test_PP',
75 'title' => 'API Test Payment Processor',
76 'class_name' => 'CRM_Core_Payment_APITest',
77 'billing_mode' => 'form',
80 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
81 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
83 // mutate $params to match expected return value
84 unset($params['sequential']);
85 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
86 //assertDBState compares expected values in $result to actual values in the DB
87 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
91 * Test using example code.
93 public function testPaymentProcessorTypeCreateExample() {
94 require_once 'api/v3/examples/PaymentProcessorType/Create.php';
95 $result = payment_processor_type_create_example();
96 $expectedResult = payment_processor_type_create_expectedresult();
97 $this->assertAPISuccess($result);
100 ///////////////// civicrm_payment_processor_type_delete methods
103 * Check with empty array.
105 public function testPaymentProcessorTypeDeleteEmpty() {
107 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
111 * Check with No array.
113 public function testPaymentProcessorTypeDeleteParamsNotArray() {
114 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
118 * Check if required fields are not passed.
120 public function testPaymentProcessorTypeDeleteWithoutRequired() {
122 'name' => 'API_Test_PP',
123 'title' => 'API Test Payment Processor',
124 'class_name' => 'CRM_Core_Payment_APITest',
127 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
128 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
132 * Check with incorrect required fields.
134 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
135 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
139 * Check payment processor type delete.
141 public function testPaymentProcessorTypeDelete() {
142 $payProcType = $this->paymentProcessorTypeCreate();
144 'id' => $payProcType,
147 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
150 ///////////////// civicrm_payment_processor_type_update
153 * Check with empty array.
155 public function testPaymentProcessorTypeUpdateEmpty() {
157 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
158 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
162 * Check with No array.
164 public function testPaymentProcessorTypeUpdateParamsNotArray() {
165 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
166 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
170 * Check with all parameters.
172 public function testPaymentProcessorTypeUpdate() {
173 // create sample payment processor type.
174 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
177 'id' => $this->_ppTypeID
,
178 'name' => 'API_Test_PP', // keep the same
179 'title' => 'API Test Payment Processor 2',
180 'class_name' => 'CRM_Core_Payment_APITest 2',
185 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
186 $this->assertNotNull($result['id']);
187 // assertDBState compares expected values in $result to actual values in the DB
188 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
191 ///////////////// civicrm_payment_processor_types_get methods
194 * Check with empty array.
196 public function testPaymentProcessorTypesGetEmptyParams() {
197 $results = $this->callAPISuccess('payment_processor_type', 'get', array());
198 $baselineCount = $results['count'];
200 $firstRelTypeParams = array(
201 'name' => 'API_Test_PP',
202 'title' => 'API Test Payment Processor',
203 'class_name' => 'CRM_Core_Payment_APITest',
208 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
210 $secondRelTypeParams = array(
211 'name' => 'API_Test_PP2',
212 'title' => 'API Test Payment Processor 2',
213 'class_name' => 'CRM_Core_Payment_APITest 2',
217 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
218 $result = $this->callAPISuccess('payment_processor_type', 'get', array());
220 $this->assertEquals($baselineCount +
2, $result['count']);
221 $this->assertAPISuccess($result);
225 * Check with valid params array.
227 public function testPaymentProcessorTypesGet() {
228 $firstRelTypeParams = array(
229 'name' => 'API_Test_PP_11',
230 'title' => 'API Test Payment Processor 11',
231 'class_name' => 'CRM_Core_Payment_APITest_11',
236 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
238 $secondRelTypeParams = array(
239 'name' => 'API_Test_PP_12',
240 'title' => 'API Test Payment Processor 12',
241 'class_name' => 'CRM_Core_Payment_APITest_12',
245 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
248 'name' => 'API_Test_PP_12',
250 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
252 $this->assertAPISuccess($result);
253 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
254 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);