CRM-13072 upgrade PaymentProcessTypeTest & PaymentProcessorTest to pass post update...
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTypeTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Class contains api test cases for "civicrm_payment_processor_type"
32 *
33 */
34 class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
35 protected $_ppTypeID;
36 protected $_apiversion;
37 public $_eNoticeCompliant = TRUE;
38 function get_info() {
39 return array(
40 'name' => 'PaymentProcessorType Create',
41 'description' => 'Test all PaymentProcessorType Create API methods.',
42 'group' => 'CiviCRM API Tests',
43 );
44 }
45
46 function setUp() {
47
48 parent::setUp();
49 $this->_apiversion = 3;
50 }
51
52 function tearDown() {
53
54 $tablesToTruncate = array(
55 'civicrm_payment_processor_type',
56 );
57 $this->quickCleanup($tablesToTruncate);
58 }
59
60 ///////////////// civicrm_payment_processor_type_add methods
61
62 /**
63 * check with no name
64 */
65 function testPaymentProcessorTypeCreateWithoutName() {
66 $payProcParams = array(
67 'is_active' => 1, );
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'
71 );
72 }
73
74 /**
75 * create payment processor type
76 */
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',
83 'is_recur' => 0,
84 );
85 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
86 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__);
87
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);
93 }
94
95 /**
96 * Test using example code
97 */
98 function testPaymentProcessorTypeCreateExample() {
99 require_once 'api/v3/examples/PaymentProcessorTypeCreate.php';
100 $result = payment_processor_type_create_example();
101 $expectedResult = payment_processor_type_create_expectedresult();
102 $this->assertAPISuccess($result);
103 }
104
105 ///////////////// civicrm_payment_processor_type_delete methods
106
107 /**
108 * check with empty array
109 */
110 function testPaymentProcessorTypeDeleteEmpty() {
111 $params = array();
112 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
113 }
114
115 /**
116 * check with No array
117 */
118 function testPaymentProcessorTypeDeleteParamsNotArray() {
119 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
120 }
121
122 /**
123 * check if required fields are not passed
124 */
125 function testPaymentProcessorTypeDeleteWithoutRequired() {
126 $params = array(
127 'name' => 'API_Test_PP',
128 'title' => 'API Test Payment Processor',
129 'class_name' => 'CRM_Core_Payment_APITest',
130 );
131
132 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
133 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
134 }
135
136 /**
137 * check with incorrect required fields
138 */
139 function testPaymentProcessorTypeDeleteWithIncorrectData() {
140 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
141 }
142
143 /**
144 * check payment processor type delete
145 */
146 function testPaymentProcessorTypeDelete() {
147 $payProcType = $this->paymentProcessorTypeCreate();
148 $params = array(
149 'id' => $payProcType,
150 );
151
152 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
153 }
154
155 ///////////////// civicrm_payment_processor_type_update
156
157 /**
158 * check with empty array
159 */
160 function testPaymentProcessorTypeUpdateEmpty() {
161 $params = array();
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');
164 }
165
166 /**
167 * check with No array
168 */
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');
172 }
173
174 /**
175 * check with all parameters
176 */
177 function testPaymentProcessorTypeUpdate() {
178 // create sample payment processor type.
179 $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
180
181 $params = array(
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',
186 'billing_mode' => 2,
187 'is_recur' => 0, );
188
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);
193 }
194
195 ///////////////// civicrm_payment_processor_types_get methods
196
197 /**
198 * check with empty array
199 */
200 function testPaymentProcessorTypesGetEmptyParams() {
201 $results = $this->callAPISuccess('payment_processor_type', 'get', array( ));
202 $baselineCount = $results['count'];
203
204 $firstRelTypeParams = array(
205 'name' => 'API_Test_PP',
206 'title' => 'API Test Payment Processor',
207 'class_name' => 'CRM_Core_Payment_APITest',
208 'billing_mode' => 1,
209 'is_recur' => 0, );
210
211 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
212
213 $secondRelTypeParams = array(
214 'name' => 'API_Test_PP2',
215 'title' => 'API Test Payment Processor 2',
216 'class_name' => 'CRM_Core_Payment_APITest 2',
217 'billing_mode' => 2,
218 'is_recur' => 0, );
219 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
220 $result = $this->callAPISuccess('payment_processor_type', 'get', array( ));
221
222 $this->assertEquals($baselineCount + 2, $result['count']);
223 $this->assertAPISuccess($result);
224 }
225
226 /**
227 * check with valid params array.
228 */
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',
234 'billing_mode' => 1,
235 'is_recur' => 0, );
236
237 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
238
239 $secondRelTypeParams = array(
240 'name' => 'API_Test_PP_12',
241 'title' => 'API Test Payment Processor 12',
242 'class_name' => 'CRM_Core_Payment_APITest_12',
243 'billing_mode' => 2,
244 'is_recur' => 0, );
245 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
246
247 $params = array(
248 'name' => 'API_Test_PP_12', );
249 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
250
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__);
254 }
255 }
256