phpcs - Fix error, "CONST keyword must be lowercase; expected const but found CONST"
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30/**
31 * Class contains api test cases for "civicrm_payment_processor_type"
32 *
33 */
34class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
6a488035
TO
35 protected $_ppTypeID;
36 protected $_apiversion;
b7c9bc4c 37
6a488035
TO
38 function setUp() {
39
40 parent::setUp();
1da902df 41 $this->useTransaction(TRUE);
6a488035 42 $this->_apiversion = 3;
6a488035
TO
43 }
44
1da902df
TO
45// function tearDown() {
46//
47// $tablesToTruncate = array(
48// 'civicrm_payment_processor_type',
49// );
50// $this->quickCleanup($tablesToTruncate);
51// }
6a488035
TO
52
53 ///////////////// civicrm_payment_processor_type_add methods
54
55 /**
100fef9d 56 * Check with no name
6a488035
TO
57 */
58 function testPaymentProcessorTypeCreateWithoutName() {
59 $payProcParams = array(
fa7b9efb 60 'is_active' => 1, );
d0e1eff2 61 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
6a488035
TO
62 $this->assertEquals($result['error_message'],
63 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
64 );
65 }
66
67 /**
100fef9d 68 * Create payment processor type
6a488035
TO
69 */
70 function testPaymentProcessorTypeCreate() {
fa7b9efb 71 $params = array( 'sequential' => 1,
6a488035
TO
72 'name' => 'API_Test_PP',
73 'title' => 'API Test Payment Processor',
74 'class_name' => 'CRM_Core_Payment_APITest',
75 'billing_mode' => 'form',
76 'is_recur' => 0,
77 );
fa7b9efb 78 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
6a488035
TO
79 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__);
80
81 // mutate $params to match expected return value
6a488035
TO
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);
86 }
87
88 /**
89 * Test using example code
90 */
91 function testPaymentProcessorTypeCreateExample() {
3ec6e38d 92 require_once 'api/v3/examples/PaymentProcessorType/Create.php';
6a488035
TO
93 $result = payment_processor_type_create_example();
94 $expectedResult = payment_processor_type_create_expectedresult();
48ab68c7 95 $this->assertAPISuccess($result);
6a488035
TO
96 }
97
98 ///////////////// civicrm_payment_processor_type_delete methods
99
100 /**
100fef9d 101 * Check with empty array
6a488035
TO
102 */
103 function testPaymentProcessorTypeDeleteEmpty() {
104 $params = array();
d0e1eff2 105 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
6a488035
TO
106 }
107
108 /**
100fef9d 109 * Check with No array
6a488035
TO
110 */
111 function testPaymentProcessorTypeDeleteParamsNotArray() {
d0e1eff2 112 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
6a488035
TO
113 }
114
115 /**
100fef9d 116 * Check if required fields are not passed
6a488035
TO
117 */
118 function testPaymentProcessorTypeDeleteWithoutRequired() {
119 $params = array(
120 'name' => 'API_Test_PP',
121 'title' => 'API Test Payment Processor',
122 'class_name' => 'CRM_Core_Payment_APITest',
123 );
124
d0e1eff2
CW
125 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
126 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
6a488035
TO
127 }
128
129 /**
100fef9d 130 * Check with incorrect required fields
6a488035
TO
131 */
132 function testPaymentProcessorTypeDeleteWithIncorrectData() {
fa7b9efb 133 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
6a488035
TO
134 }
135
136 /**
100fef9d 137 * Check payment processor type delete
6a488035
TO
138 */
139 function testPaymentProcessorTypeDelete() {
140 $payProcType = $this->paymentProcessorTypeCreate();
6a488035
TO
141 $params = array(
142 'id' => $payProcType,
6a488035
TO
143 );
144
fa7b9efb 145 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
6a488035
TO
146 }
147
148 ///////////////// civicrm_payment_processor_type_update
149
150 /**
100fef9d 151 * Check with empty array
6a488035
TO
152 */
153 function testPaymentProcessorTypeUpdateEmpty() {
154 $params = array();
d0e1eff2
CW
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');
6a488035
TO
157 }
158
159 /**
100fef9d 160 * Check with No array
6a488035
TO
161 */
162 function testPaymentProcessorTypeUpdateParamsNotArray() {
d0e1eff2 163 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
6a488035
TO
164 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
165 }
166
167 /**
100fef9d 168 * Check with all parameters
6a488035
TO
169 */
170 function testPaymentProcessorTypeUpdate() {
171 // create sample payment processor type.
172 $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
173
174 $params = array(
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',
179 'billing_mode' => 2,
fa7b9efb 180 'is_recur' => 0, );
6a488035 181
fa7b9efb 182 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
6a488035 183 $this->assertNotNull($result['id']);
6a488035
TO
184 // assertDBState compares expected values in $result to actual values in the DB
185 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params);
186 }
187
188 ///////////////// civicrm_payment_processor_types_get methods
189
190 /**
100fef9d 191 * Check with empty array
6a488035
TO
192 */
193 function testPaymentProcessorTypesGetEmptyParams() {
fa7b9efb 194 $results = $this->callAPISuccess('payment_processor_type', 'get', array( ));
6a488035
TO
195 $baselineCount = $results['count'];
196
197 $firstRelTypeParams = array(
198 'name' => 'API_Test_PP',
199 'title' => 'API Test Payment Processor',
200 'class_name' => 'CRM_Core_Payment_APITest',
201 'billing_mode' => 1,
fa7b9efb 202 'is_recur' => 0, );
6a488035 203
fa7b9efb 204 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
6a488035
TO
205
206 $secondRelTypeParams = array(
207 'name' => 'API_Test_PP2',
208 'title' => 'API Test Payment Processor 2',
209 'class_name' => 'CRM_Core_Payment_APITest 2',
210 'billing_mode' => 2,
fa7b9efb 211 'is_recur' => 0, );
212 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
213 $result = $this->callAPISuccess('payment_processor_type', 'get', array( ));
6a488035 214
48ab68c7 215 $this->assertEquals($baselineCount + 2, $result['count']);
216 $this->assertAPISuccess($result);
6a488035
TO
217 }
218
219 /**
100fef9d 220 * Check with valid params array.
6a488035
TO
221 */
222 function testPaymentProcessorTypesGet() {
223 $firstRelTypeParams = array(
224 'name' => 'API_Test_PP_11',
225 'title' => 'API Test Payment Processor 11',
226 'class_name' => 'CRM_Core_Payment_APITest_11',
227 'billing_mode' => 1,
fa7b9efb 228 'is_recur' => 0, );
6a488035 229
fa7b9efb 230 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
6a488035
TO
231
232 $secondRelTypeParams = array(
233 'name' => 'API_Test_PP_12',
234 'title' => 'API Test Payment Processor 12',
235 'class_name' => 'CRM_Core_Payment_APITest_12',
236 'billing_mode' => 2,
fa7b9efb 237 'is_recur' => 0, );
238 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
6a488035
TO
239
240 $params = array(
fa7b9efb 241 'name' => 'API_Test_PP_12', );
242 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
6a488035 243
48ab68c7 244 $this->assertAPISuccess($result);
245 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__);
246 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__);
6a488035
TO
247 }
248}
249