Merge pull request #7732 from eileenmcnaughton/CRM-17951
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
28 /**
29 * Class contains api test cases for "civicrm_payment_processor_type"
30 *
31 */
32 class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
33 protected $_ppTypeID;
34 protected $_apiversion;
35
36 public function setUp() {
37
38 parent::setUp();
39 $this->useTransaction(TRUE);
40 $this->_apiversion = 3;
41 }
42
43 // function tearDown() {
44 //
45 // $tablesToTruncate = array(
46 // 'civicrm_payment_processor_type',
47 // );
48 // $this->quickCleanup($tablesToTruncate);
49 // }
50
51 ///////////////// civicrm_payment_processor_type_add methods
52
53 /**
54 * Check with no name.
55 */
56 public function testPaymentProcessorTypeCreateWithoutName() {
57 $payProcParams = array(
58 'is_active' => 1,
59 );
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'
63 );
64 }
65
66 /**
67 * Create payment processor type.
68 */
69 public function testPaymentProcessorTypeCreate() {
70 $params = array(
71 'sequential' => 1,
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 );
78 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
79 $this->assertNotNull($result['values'][0]['id']);
80
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);
86 }
87
88 /**
89 * Test using example code.
90 */
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);
96 }
97
98 ///////////////// civicrm_payment_processor_type_delete methods
99
100 /**
101 * Check with empty array.
102 */
103 public function testPaymentProcessorTypeDeleteEmpty() {
104 $params = array();
105 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
106 }
107
108 /**
109 * Check with No array.
110 */
111 public function testPaymentProcessorTypeDeleteParamsNotArray() {
112 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
113 }
114
115 /**
116 * Check if required fields are not passed.
117 */
118 public 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
125 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
126 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
127 }
128
129 /**
130 * Check with incorrect required fields.
131 */
132 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
133 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
134 }
135
136 /**
137 * Check payment processor type delete.
138 */
139 public function testPaymentProcessorTypeDelete() {
140 $payProcType = $this->paymentProcessorTypeCreate();
141 $params = array(
142 'id' => $payProcType,
143 );
144
145 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
146 }
147
148 ///////////////// civicrm_payment_processor_type_update
149
150 /**
151 * Check with empty array.
152 */
153 public function testPaymentProcessorTypeUpdateEmpty() {
154 $params = array();
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');
157 }
158
159 /**
160 * Check with No array.
161 */
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');
165 }
166
167 /**
168 * Check with all parameters.
169 */
170 public 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,
180 'is_recur' => 0,
181 );
182
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);
187 }
188
189 ///////////////// civicrm_payment_processor_types_get methods
190
191 /**
192 * Check with empty array.
193 */
194 public function testPaymentProcessorTypesGetEmptyParams() {
195 $results = $this->callAPISuccess('payment_processor_type', 'get', array());
196 $baselineCount = $results['count'];
197
198 $firstRelTypeParams = array(
199 'name' => 'API_Test_PP',
200 'title' => 'API Test Payment Processor',
201 'class_name' => 'CRM_Core_Payment_APITest',
202 'billing_mode' => 1,
203 'is_recur' => 0,
204 );
205
206 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
207
208 $secondRelTypeParams = array(
209 'name' => 'API_Test_PP2',
210 'title' => 'API Test Payment Processor 2',
211 'class_name' => 'CRM_Core_Payment_APITest 2',
212 'billing_mode' => 2,
213 'is_recur' => 0,
214 );
215 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
216 $result = $this->callAPISuccess('payment_processor_type', 'get', array());
217
218 $this->assertEquals($baselineCount + 2, $result['count']);
219 $this->assertAPISuccess($result);
220 }
221
222 /**
223 * Check with valid params array.
224 */
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',
230 'billing_mode' => 1,
231 'is_recur' => 0,
232 );
233
234 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
235
236 $secondRelTypeParams = array(
237 'name' => 'API_Test_PP_12',
238 'title' => 'API Test Payment Processor 12',
239 'class_name' => 'CRM_Core_Payment_APITest_12',
240 'billing_mode' => 2,
241 'is_recur' => 0,
242 );
243 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
244
245 $params = array(
246 'name' => 'API_Test_PP_12',
247 );
248 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
249
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__);
253 }
254
255 }