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