Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
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 | ||
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 | |
4cbe18b8 EM |
38 | /** |
39 | * @return array | |
40 | */ | |
6a488035 TO |
41 | function get_info() { |
42 | return array( | |
43 | 'name' => 'PaymentProcessorType Create', | |
44 | 'description' => 'Test all PaymentProcessorType Create API methods.', | |
45 | 'group' => 'CiviCRM API Tests', | |
46 | ); | |
47 | } | |
48 | ||
49 | function setUp() { | |
50 | ||
51 | parent::setUp(); | |
52 | $this->_apiversion = 3; | |
6a488035 TO |
53 | } |
54 | ||
55 | function tearDown() { | |
56 | ||
57 | $tablesToTruncate = array( | |
6a488035 TO |
58 | 'civicrm_payment_processor_type', |
59 | ); | |
60 | $this->quickCleanup($tablesToTruncate); | |
61 | } | |
62 | ||
63 | ///////////////// civicrm_payment_processor_type_add methods | |
64 | ||
65 | /** | |
66 | * check with no name | |
67 | */ | |
68 | function testPaymentProcessorTypeCreateWithoutName() { | |
69 | $payProcParams = array( | |
fa7b9efb | 70 | 'is_active' => 1, ); |
d0e1eff2 | 71 | $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams); |
6a488035 TO |
72 | $this->assertEquals($result['error_message'], |
73 | 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode' | |
74 | ); | |
75 | } | |
76 | ||
77 | /** | |
78 | * create payment processor type | |
79 | */ | |
80 | function testPaymentProcessorTypeCreate() { | |
fa7b9efb | 81 | $params = array( 'sequential' => 1, |
6a488035 TO |
82 | 'name' => 'API_Test_PP', |
83 | 'title' => 'API Test Payment Processor', | |
84 | 'class_name' => 'CRM_Core_Payment_APITest', | |
85 | 'billing_mode' => 'form', | |
86 | 'is_recur' => 0, | |
87 | ); | |
fa7b9efb | 88 | $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
89 | $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); |
90 | ||
91 | // mutate $params to match expected return value | |
6a488035 TO |
92 | unset($params['sequential']); |
93 | $params['billing_mode'] = CRM_Core_Payment::BILLING_MODE_FORM; | |
94 | //assertDBState compares expected values in $result to actual values in the DB | |
95 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Test using example code | |
100 | */ | |
101 | function testPaymentProcessorTypeCreateExample() { | |
3ec6e38d | 102 | require_once 'api/v3/examples/PaymentProcessorType/Create.php'; |
6a488035 TO |
103 | $result = payment_processor_type_create_example(); |
104 | $expectedResult = payment_processor_type_create_expectedresult(); | |
48ab68c7 | 105 | $this->assertAPISuccess($result); |
6a488035 TO |
106 | } |
107 | ||
108 | ///////////////// civicrm_payment_processor_type_delete methods | |
109 | ||
110 | /** | |
111 | * check with empty array | |
112 | */ | |
113 | function testPaymentProcessorTypeDeleteEmpty() { | |
114 | $params = array(); | |
d0e1eff2 | 115 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
6a488035 TO |
116 | } |
117 | ||
118 | /** | |
119 | * check with No array | |
120 | */ | |
121 | function testPaymentProcessorTypeDeleteParamsNotArray() { | |
d0e1eff2 | 122 | $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string'); |
6a488035 TO |
123 | } |
124 | ||
125 | /** | |
126 | * check if required fields are not passed | |
127 | */ | |
128 | function testPaymentProcessorTypeDeleteWithoutRequired() { | |
129 | $params = array( | |
130 | 'name' => 'API_Test_PP', | |
131 | 'title' => 'API Test Payment Processor', | |
132 | 'class_name' => 'CRM_Core_Payment_APITest', | |
133 | ); | |
134 | ||
d0e1eff2 CW |
135 | $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); |
136 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); | |
6a488035 TO |
137 | } |
138 | ||
139 | /** | |
140 | * check with incorrect required fields | |
141 | */ | |
142 | function testPaymentProcessorTypeDeleteWithIncorrectData() { | |
fa7b9efb | 143 | $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd')); |
6a488035 TO |
144 | } |
145 | ||
146 | /** | |
147 | * check payment processor type delete | |
148 | */ | |
149 | function testPaymentProcessorTypeDelete() { | |
150 | $payProcType = $this->paymentProcessorTypeCreate(); | |
6a488035 TO |
151 | $params = array( |
152 | 'id' => $payProcType, | |
6a488035 TO |
153 | ); |
154 | ||
fa7b9efb | 155 | $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
156 | } |
157 | ||
158 | ///////////////// civicrm_payment_processor_type_update | |
159 | ||
160 | /** | |
161 | * check with empty array | |
162 | */ | |
163 | function testPaymentProcessorTypeUpdateEmpty() { | |
164 | $params = array(); | |
d0e1eff2 CW |
165 | $result = $this->callAPIFailure('payment_processor_type', 'create', $params); |
166 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'); | |
6a488035 TO |
167 | } |
168 | ||
169 | /** | |
170 | * check with No array | |
171 | */ | |
172 | function testPaymentProcessorTypeUpdateParamsNotArray() { | |
d0e1eff2 | 173 | $result = $this->callAPIFailure('payment_processor_type', 'create', 'string'); |
6a488035 TO |
174 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
175 | } | |
176 | ||
177 | /** | |
178 | * check with all parameters | |
179 | */ | |
180 | function testPaymentProcessorTypeUpdate() { | |
181 | // create sample payment processor type. | |
182 | $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL); | |
183 | ||
184 | $params = array( | |
185 | 'id' => $this->_ppTypeID, | |
186 | 'name' => 'API_Test_PP', // keep the same | |
187 | 'title' => 'API Test Payment Processor 2', | |
188 | 'class_name' => 'CRM_Core_Payment_APITest 2', | |
189 | 'billing_mode' => 2, | |
fa7b9efb | 190 | 'is_recur' => 0, ); |
6a488035 | 191 | |
fa7b9efb | 192 | $result = $this->callAPISuccess('payment_processor_type', 'create', $params); |
6a488035 | 193 | $this->assertNotNull($result['id']); |
6a488035 TO |
194 | // assertDBState compares expected values in $result to actual values in the DB |
195 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params); | |
196 | } | |
197 | ||
198 | ///////////////// civicrm_payment_processor_types_get methods | |
199 | ||
200 | /** | |
201 | * check with empty array | |
202 | */ | |
203 | function testPaymentProcessorTypesGetEmptyParams() { | |
fa7b9efb | 204 | $results = $this->callAPISuccess('payment_processor_type', 'get', array( )); |
6a488035 TO |
205 | $baselineCount = $results['count']; |
206 | ||
207 | $firstRelTypeParams = array( | |
208 | 'name' => 'API_Test_PP', | |
209 | 'title' => 'API Test Payment Processor', | |
210 | 'class_name' => 'CRM_Core_Payment_APITest', | |
211 | 'billing_mode' => 1, | |
fa7b9efb | 212 | 'is_recur' => 0, ); |
6a488035 | 213 | |
fa7b9efb | 214 | $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); |
6a488035 TO |
215 | |
216 | $secondRelTypeParams = array( | |
217 | 'name' => 'API_Test_PP2', | |
218 | 'title' => 'API Test Payment Processor 2', | |
219 | 'class_name' => 'CRM_Core_Payment_APITest 2', | |
220 | 'billing_mode' => 2, | |
fa7b9efb | 221 | 'is_recur' => 0, ); |
222 | $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); | |
223 | $result = $this->callAPISuccess('payment_processor_type', 'get', array( )); | |
6a488035 | 224 | |
48ab68c7 | 225 | $this->assertEquals($baselineCount + 2, $result['count']); |
226 | $this->assertAPISuccess($result); | |
6a488035 TO |
227 | } |
228 | ||
229 | /** | |
230 | * check with valid params array. | |
231 | */ | |
232 | function testPaymentProcessorTypesGet() { | |
233 | $firstRelTypeParams = array( | |
234 | 'name' => 'API_Test_PP_11', | |
235 | 'title' => 'API Test Payment Processor 11', | |
236 | 'class_name' => 'CRM_Core_Payment_APITest_11', | |
237 | 'billing_mode' => 1, | |
fa7b9efb | 238 | 'is_recur' => 0, ); |
6a488035 | 239 | |
fa7b9efb | 240 | $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); |
6a488035 TO |
241 | |
242 | $secondRelTypeParams = array( | |
243 | 'name' => 'API_Test_PP_12', | |
244 | 'title' => 'API Test Payment Processor 12', | |
245 | 'class_name' => 'CRM_Core_Payment_APITest_12', | |
246 | 'billing_mode' => 2, | |
fa7b9efb | 247 | 'is_recur' => 0, ); |
248 | $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); | |
6a488035 TO |
249 | |
250 | $params = array( | |
fa7b9efb | 251 | 'name' => 'API_Test_PP_12', ); |
252 | $result = $this->callAPISuccess('payment_processor_type', 'get', $params); | |
6a488035 | 253 | |
48ab68c7 | 254 | $this->assertAPISuccess($result); |
255 | $this->assertEquals(1, $result['count'], ' in line ' . __LINE__); | |
256 | $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__); | |
6a488035 TO |
257 | } |
258 | } | |
259 |