3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 +--------------------------------------------------------------------+
29 * Class contains api test cases for "civicrm_payment_processor_type"
32 class api_v3_PaymentProcessorTypeTest
extends CiviUnitTestCase
{
34 protected $_apiversion;
36 public function setUp() {
39 $this->useTransaction(TRUE);
40 $this->_apiversion
= 3;
43 // function tearDown() {
45 // $tablesToTruncate = array(
46 // 'civicrm_payment_processor_type',
48 // $this->quickCleanup($tablesToTruncate);
51 ///////////////// civicrm_payment_processor_type_add methods
56 public function testPaymentProcessorTypeCreateWithoutName() {
57 $payProcParams = array(
60 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
61 $this->assertEquals($result['error_message'],
62 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
67 * Create payment processor type.
69 public function testPaymentProcessorTypeCreate() {
72 'name' => 'API_Test_PP',
73 'title' => 'API Test Payment Processor',
74 'class_name' => 'CRM_Core_Payment_APITest',
75 'billing_mode' => 'form',
78 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
79 $this->assertNotNull($result['values'][0]['id']);
81 // mutate $params to match expected return value
82 unset($params['sequential']);
83 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
84 //assertDBState compares expected values in $result to actual values in the DB
85 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
89 * Test using example code.
91 public function testPaymentProcessorTypeCreateExample() {
92 require_once 'api/v3/examples/PaymentProcessorType/Create.php';
93 $result = payment_processor_type_create_example();
94 $expectedResult = payment_processor_type_create_expectedresult();
95 $this->assertAPISuccess($result);
98 ///////////////// civicrm_payment_processor_type_delete methods
101 * Check with empty array.
103 public function testPaymentProcessorTypeDeleteEmpty() {
105 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
109 * Check with No array.
111 public function testPaymentProcessorTypeDeleteParamsNotArray() {
112 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
116 * Check if required fields are not passed.
118 public function testPaymentProcessorTypeDeleteWithoutRequired() {
120 'name' => 'API_Test_PP',
121 'title' => 'API Test Payment Processor',
122 'class_name' => 'CRM_Core_Payment_APITest',
125 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
126 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
130 * Check with incorrect required fields.
132 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
133 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
137 * Check payment processor type delete.
139 public function testPaymentProcessorTypeDelete() {
140 $payProcType = $this->paymentProcessorTypeCreate();
142 'id' => $payProcType,
145 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
148 ///////////////// civicrm_payment_processor_type_update
151 * Check with empty array.
153 public function testPaymentProcessorTypeUpdateEmpty() {
155 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
156 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
160 * Check with No array.
162 public function testPaymentProcessorTypeUpdateParamsNotArray() {
163 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
164 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
168 * Check with all parameters.
170 public function testPaymentProcessorTypeUpdate() {
171 // create sample payment processor type.
172 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
175 'id' => $this->_ppTypeID
,
176 'name' => 'API_Test_PP', // keep the same
177 'title' => 'API Test Payment Processor 2',
178 'class_name' => 'CRM_Core_Payment_APITest 2',
183 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
184 $this->assertNotNull($result['id']);
185 // assertDBState compares expected values in $result to actual values in the DB
186 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
189 ///////////////// civicrm_payment_processor_types_get methods
192 * Check with empty array.
194 public function testPaymentProcessorTypesGetEmptyParams() {
195 $results = $this->callAPISuccess('payment_processor_type', 'get', array());
196 $baselineCount = $results['count'];
198 $firstRelTypeParams = array(
199 'name' => 'API_Test_PP',
200 'title' => 'API Test Payment Processor',
201 'class_name' => 'CRM_Core_Payment_APITest',
206 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
208 $secondRelTypeParams = array(
209 'name' => 'API_Test_PP2',
210 'title' => 'API Test Payment Processor 2',
211 'class_name' => 'CRM_Core_Payment_APITest 2',
215 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
216 $result = $this->callAPISuccess('payment_processor_type', 'get', array());
218 $this->assertEquals($baselineCount +
2, $result['count']);
219 $this->assertAPISuccess($result);
223 * Check with valid params array.
225 public function testPaymentProcessorTypesGet() {
226 $firstRelTypeParams = array(
227 'name' => 'API_Test_PP_11',
228 'title' => 'API Test Payment Processor 11',
229 'class_name' => 'CRM_Core_Payment_APITest_11',
234 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
236 $secondRelTypeParams = array(
237 'name' => 'API_Test_PP_12',
238 'title' => 'API Test Payment Processor 12',
239 'class_name' => 'CRM_Core_Payment_APITest_12',
243 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
246 'name' => 'API_Test_PP_12',
248 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
250 $this->assertAPISuccess($result);
251 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
252 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);