Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 { | |
6a488035 TO |
35 | protected $_ppTypeID; |
36 | protected $_apiversion; | |
b7c9bc4c | 37 | |
6a488035 TO |
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; | |
6a488035 TO |
50 | } |
51 | ||
52 | function tearDown() { | |
53 | ||
54 | $tablesToTruncate = array( | |
6a488035 TO |
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( | |
fa7b9efb | 67 | 'is_active' => 1, ); |
d0e1eff2 | 68 | $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams); |
6a488035 TO |
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() { | |
fa7b9efb | 78 | $params = array( 'sequential' => 1, |
6a488035 TO |
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 | ); | |
fa7b9efb | 85 | $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
86 | $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); |
87 | ||
88 | // mutate $params to match expected return value | |
6a488035 TO |
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() { | |
3ec6e38d | 99 | require_once 'api/v3/examples/PaymentProcessorType/Create.php'; |
6a488035 TO |
100 | $result = payment_processor_type_create_example(); |
101 | $expectedResult = payment_processor_type_create_expectedresult(); | |
48ab68c7 | 102 | $this->assertAPISuccess($result); |
6a488035 TO |
103 | } |
104 | ||
105 | ///////////////// civicrm_payment_processor_type_delete methods | |
106 | ||
107 | /** | |
108 | * check with empty array | |
109 | */ | |
110 | function testPaymentProcessorTypeDeleteEmpty() { | |
111 | $params = array(); | |
d0e1eff2 | 112 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
6a488035 TO |
113 | } |
114 | ||
115 | /** | |
116 | * check with No array | |
117 | */ | |
118 | function testPaymentProcessorTypeDeleteParamsNotArray() { | |
d0e1eff2 | 119 | $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string'); |
6a488035 TO |
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 | ||
d0e1eff2 CW |
132 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
133 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); | |
6a488035 TO |
134 | } |
135 | ||
136 | /** | |
137 | * check with incorrect required fields | |
138 | */ | |
139 | function testPaymentProcessorTypeDeleteWithIncorrectData() { | |
fa7b9efb | 140 | $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd')); |
6a488035 TO |
141 | } |
142 | ||
143 | /** | |
144 | * check payment processor type delete | |
145 | */ | |
146 | function testPaymentProcessorTypeDelete() { | |
147 | $payProcType = $this->paymentProcessorTypeCreate(); | |
6a488035 TO |
148 | $params = array( |
149 | 'id' => $payProcType, | |
6a488035 TO |
150 | ); |
151 | ||
fa7b9efb | 152 | $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
153 | } |
154 | ||
155 | ///////////////// civicrm_payment_processor_type_update | |
156 | ||
157 | /** | |
158 | * check with empty array | |
159 | */ | |
160 | function testPaymentProcessorTypeUpdateEmpty() { | |
161 | $params = array(); | |
d0e1eff2 CW |
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'); | |
6a488035 TO |
164 | } |
165 | ||
166 | /** | |
167 | * check with No array | |
168 | */ | |
169 | function testPaymentProcessorTypeUpdateParamsNotArray() { | |
d0e1eff2 | 170 | $result = $this->callAPIFailure('payment_processor_type', 'create', 'string'); |
6a488035 TO |
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, | |
fa7b9efb | 187 | 'is_recur' => 0, ); |
6a488035 | 188 | |
fa7b9efb | 189 | $result = $this->callAPISuccess('payment_processor_type', 'create', $params); |
6a488035 | 190 | $this->assertNotNull($result['id']); |
6a488035 TO |
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() { | |
fa7b9efb | 201 | $results = $this->callAPISuccess('payment_processor_type', 'get', array( )); |
6a488035 TO |
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, | |
fa7b9efb | 209 | 'is_recur' => 0, ); |
6a488035 | 210 | |
fa7b9efb | 211 | $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); |
6a488035 TO |
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, | |
fa7b9efb | 218 | 'is_recur' => 0, ); |
219 | $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); | |
220 | $result = $this->callAPISuccess('payment_processor_type', 'get', array( )); | |
6a488035 | 221 | |
48ab68c7 | 222 | $this->assertEquals($baselineCount + 2, $result['count']); |
223 | $this->assertAPISuccess($result); | |
6a488035 TO |
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, | |
fa7b9efb | 235 | 'is_recur' => 0, ); |
6a488035 | 236 | |
fa7b9efb | 237 | $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); |
6a488035 TO |
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, | |
fa7b9efb | 244 | 'is_recur' => 0, ); |
245 | $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); | |
6a488035 TO |
246 | |
247 | $params = array( | |
fa7b9efb | 248 | 'name' => 'API_Test_PP_12', ); |
249 | $result = $this->callAPISuccess('payment_processor_type', 'get', $params); | |
6a488035 | 250 | |
48ab68c7 | 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__); | |
6a488035 TO |
254 | } |
255 | } | |
256 |