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