3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class contains api test cases for "civicrm_payment_processor_type"
34 class api_v3_PaymentProcessorTypeTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
38 public function setUp() {
41 $this->useTransaction(TRUE);
42 $this->_apiversion
= 3;
45 // function tearDown() {
47 // $tablesToTruncate = array(
48 // 'civicrm_payment_processor_type',
50 // $this->quickCleanup($tablesToTruncate);
53 ///////////////// civicrm_payment_processor_type_add methods
58 public function testPaymentProcessorTypeCreateWithoutName() {
59 $payProcParams = array(
61 $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
62 $this->assertEquals($result['error_message'],
63 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
68 * Create payment processor type
70 public function testPaymentProcessorTypeCreate() {
71 $params = array( 'sequential' => 1,
72 'name' => 'API_Test_PP',
73 'title' => 'API Test Payment Processor',
74 'class_name' => 'CRM_Core_Payment_APITest',
75 'billing_mode' => 'form',
78 $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__
, __FILE__
);
79 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
81 // mutate $params to match expected return value
82 unset($params['sequential']);
83 $params['billing_mode'] = CRM_Core_Payment
::BILLING_MODE_FORM
;
84 //assertDBState compares expected values in $result to actual values in the DB
85 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $result['id'], $params);
89 * Test using example code
91 public function testPaymentProcessorTypeCreateExample() {
92 require_once 'api/v3/examples/PaymentProcessorType/Create.php';
93 $result = payment_processor_type_create_example();
94 $expectedResult = payment_processor_type_create_expectedresult();
95 $this->assertAPISuccess($result);
98 ///////////////// civicrm_payment_processor_type_delete methods
101 * Check with empty array
103 public function testPaymentProcessorTypeDeleteEmpty() {
105 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
109 * Check with No array
111 public function testPaymentProcessorTypeDeleteParamsNotArray() {
112 $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string');
116 * Check if required fields are not passed
118 public function testPaymentProcessorTypeDeleteWithoutRequired() {
120 'name' => 'API_Test_PP',
121 'title' => 'API Test Payment Processor',
122 'class_name' => 'CRM_Core_Payment_APITest',
125 $result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
126 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
130 * Check with incorrect required fields
132 public function testPaymentProcessorTypeDeleteWithIncorrectData() {
133 $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
137 * Check payment processor type delete
139 public function testPaymentProcessorTypeDelete() {
140 $payProcType = $this->paymentProcessorTypeCreate();
142 'id' => $payProcType,
145 $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__
, __FILE__
);
148 ///////////////// civicrm_payment_processor_type_update
151 * Check with empty array
153 public function testPaymentProcessorTypeUpdateEmpty() {
155 $result = $this->callAPIFailure('payment_processor_type', 'create', $params);
156 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
160 * Check with No array
162 public function testPaymentProcessorTypeUpdateParamsNotArray() {
163 $result = $this->callAPIFailure('payment_processor_type', 'create', 'string');
164 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
168 * Check with all parameters
170 public function testPaymentProcessorTypeUpdate() {
171 // create sample payment processor type.
172 $this->_ppTypeID
= $this->paymentProcessorTypeCreate(NULL);
175 'id' => $this->_ppTypeID
,
176 'name' => 'API_Test_PP', // keep the same
177 'title' => 'API Test Payment Processor 2',
178 'class_name' => 'CRM_Core_Payment_APITest 2',
182 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
183 $this->assertNotNull($result['id']);
184 // assertDBState compares expected values in $result to actual values in the DB
185 $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID
, $params);
188 ///////////////// civicrm_payment_processor_types_get methods
191 * Check with empty array
193 public function testPaymentProcessorTypesGetEmptyParams() {
194 $results = $this->callAPISuccess('payment_processor_type', 'get', array( ));
195 $baselineCount = $results['count'];
197 $firstRelTypeParams = array(
198 'name' => 'API_Test_PP',
199 'title' => 'API Test Payment Processor',
200 'class_name' => 'CRM_Core_Payment_APITest',
204 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
206 $secondRelTypeParams = array(
207 'name' => 'API_Test_PP2',
208 'title' => 'API Test Payment Processor 2',
209 'class_name' => 'CRM_Core_Payment_APITest 2',
212 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
213 $result = $this->callAPISuccess('payment_processor_type', 'get', array( ));
215 $this->assertEquals($baselineCount +
2, $result['count']);
216 $this->assertAPISuccess($result);
220 * Check with valid params array.
222 public function testPaymentProcessorTypesGet() {
223 $firstRelTypeParams = array(
224 'name' => 'API_Test_PP_11',
225 'title' => 'API Test Payment Processor 11',
226 'class_name' => 'CRM_Core_Payment_APITest_11',
230 $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
232 $secondRelTypeParams = array(
233 'name' => 'API_Test_PP_12',
234 'title' => 'API Test Payment Processor 12',
235 'class_name' => 'CRM_Core_Payment_APITest_12',
238 $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
241 'name' => 'API_Test_PP_12', );
242 $result = $this->callAPISuccess('payment_processor_type', 'get', $params);
244 $this->assertAPISuccess($result);
245 $this->assertEquals(1, $result['count'], ' in line ' . __LINE__
);
246 $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__
);