3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class contains api test cases for "civicrm_payment_processor_type"
17 class api_v3_PaymentProcessorTypeTest
extends CiviUnitTestCase
{
20 public function setUp() {
23 $this->useTransaction(TRUE);
26 // function tearDown() {
28 // $tablesToTruncate = array(
29 // 'civicrm_payment_processor_type',
31 // $this->quickCleanup($tablesToTruncate);
34 ///////////////// civicrm_payment_processor_type_add methods
38 * @dataProvider versionThreeAndFour
40 public function testPaymentProcessorTypeCreateWithoutName($version) {
41 $this->_apiversion
= $version;
45 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
46 $this->assertContains('name, title, class_name, billing_mode', $result['error_message']);
50 * Create payment processor type.
51 * @dataProvider versionThreeAndFour
53 public function testPaymentProcessorTypeCreate($version) {
54 $this->_apiversion
= $version;
57 'name' => 'API_Test_PP',
58 'title' => 'API Test Payment Processor',
59 'class_name' => 'CRM_Core_Payment_APITest',
60 'billing_mode' => 'form',
63 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
64 $this->assertNotNull($result['values'][0]['id']);
66 // mutate $params to match expected return value
67 unset($params['sequential']);
68 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
69 //assertDBState compares expected values in $result to actual values in the DB
70 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
74 * Test using example code.
76 public function testPaymentProcessorTypeCreateExample() {
77 require_once 'api/v3/examples/PaymentProcessorType/Create.ex.php';
78 $result = payment_processor_type_create_example();
79 $expectedResult = payment_processor_type_create_expectedresult();
80 $this->assertAPISuccess($result);
83 ///////////////// civicrm_payment_processor_type_delete methods
86 * Check with empty array.
87 * @dataProvider versionThreeAndFour
89 public function testPaymentProcessorTypeDeleteEmpty($version) {
90 $this->_apiversion
= $version;
92 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
96 * Check if required fields are not passed.
97 * @dataProvider versionThreeAndFour
99 public function testPaymentProcessorTypeDeleteWithoutRequired($version) {
100 $this->_apiversion
= $version;
102 'name' => 'API_Test_PP',
103 'title' => 'API Test Payment Processor',
104 'class_name' => 'CRM_Core_Payment_APITest',
107 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
108 $this->assertEquals(($version === 4 ?
'Parameter "where" is required.' : 'Mandatory key(s) missing from params array: id'), $result['error_message']);
112 * Check with incorrect required fields.
113 * @dataProvider versionThreeAndFour
115 public function testPaymentProcessorTypeDeleteWithIncorrectData($version) {
116 $this->_apiversion
= $version;
117 $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']);
121 * Check payment processor type delete.
122 * @dataProvider versionThreeAndFour
124 public function testPaymentProcessorTypeDelete($version) {
125 $this->_apiversion
= $version;
126 $payProcType = $this->paymentProcessorTypeCreate();
128 'id' => $payProcType,
131 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
134 ///////////////// civicrm_payment_processor_type_update
137 * Check with empty array.
138 * @dataProvider versionThreeAndFour
140 public function testPaymentProcessorTypeUpdateEmpty($version) {
141 $this->_apiversion
= $version;
143 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
144 $this->assertContains('name, title, class_name, billing_mode', $result['error_message']);
148 * Check with all parameters.
149 * @dataProvider versionThreeAndFour
151 public function testPaymentProcessorTypeUpdate($version) {
152 $this->_apiversion
= $version;
153 // create sample payment processor type.
154 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
157 'id' => $this->_ppTypeID
,
159 'name' => 'API_Test_PP',
160 'title' => 'API Test Payment Processor 2',
161 'class_name' => 'CRM_Core_Payment_APITest 2',
166 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
167 $this->assertNotNull($result['id']);
168 // assertDBState compares expected values in $result to actual values in the DB
169 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
172 ///////////////// civicrm_payment_processor_types_get methods
175 * Check with empty array.
176 * @dataProvider versionThreeAndFour
178 public function testPaymentProcessorTypesGetEmptyParams($version) {
179 $this->_apiversion
= $version;
180 $results = $this->callAPISuccess('payment_processor_type', 'get', []);
181 $baselineCount = $results['count'];
183 $firstRelTypeParams = [
184 'name' => 'API_Test_PP',
185 'title' => 'API Test Payment Processor',
186 'class_name' => 'CRM_Core_Payment_APITest',
191 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
193 $secondRelTypeParams = [
194 'name' => 'API_Test_PP2',
195 'title' => 'API Test Payment Processor 2',
196 'class_name' => 'CRM_Core_Payment_APITest 2',
200 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
201 $result = $this->callAPISuccess('payment_processor_type', 'get', []);
203 $this->assertEquals($baselineCount +
2, $result['count']);
204 $this->assertAPISuccess($result);
208 * Check with valid params array.
209 * @dataProvider versionThreeAndFour
211 public function testPaymentProcessorTypesGet($version) {
212 $this->_apiversion
= $version;
213 $firstRelTypeParams = [
214 'name' => 'API_Test_PP_11',
215 'title' => 'API Test Payment Processor 11',
216 'class_name' => 'CRM_Core_Payment_APITest_11',
221 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
223 $secondRelTypeParams = [
224 'name' => 'API_Test_PP_12',
225 'title' => 'API Test Payment Processor 12',
226 'class_name' => 'CRM_Core_Payment_APITest_12',
230 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
233 'name' => 'API_Test_PP_12',
235 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
237 $this->assertAPISuccess($result);
238 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
239 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);