4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Class contains api test cases for "civicrm_payment_processor"
35 class api_v3_PaymentProcessorTest
extends CiviUnitTestCase
{
36 protected $_paymentProcessorType;
37 protected $_apiversion;
39 public $_eNoticeCompliant = TRUE;
42 'name' => 'PaymentProcessor Create',
43 'description' => 'Test all PaymentProcessor Create API methods.',
44 'group' => 'CiviCRM API Tests',
50 $this->_apiversion
= 3;
51 // Create dummy processor
53 'version' => $this->_apiversion
,
54 'name' => 'API_Test_PP_Type',
55 'title' => 'API Test Payment Processor Type',
56 'class_name' => 'CRM_Core_Payment_APITest',
57 'billing_mode' => 'form',
60 $result = civicrm_api('payment_processor_type', 'create', $params);
61 $this->_paymentProcessorType
= $result['id'];
62 $this->_params
= array(
63 'version' => $this->_apiversion
,
64 'name' => 'API Test PP',
65 'payment_processor_type_id' => $this->_paymentProcessorType
,
66 'class_name' => 'CRM_Core_Payment_APITest',
74 $tablesToTruncate = array(
75 'civicrm_payment_processor',
76 'civicrm_payment_processor_type',
78 $this->quickCleanup($tablesToTruncate);
81 ///////////////// civicrm_payment_processor_add methods
86 function testPaymentProcessorCreateWithoutName() {
87 $payProcParams = array(
89 'version' => $this->_apiversion
,
91 $result = civicrm_api('payment_processor', 'create', $payProcParams);
93 $this->assertEquals($result['is_error'], 1);
97 * create payment processor
99 function testPaymentProcessorCreate() {
100 $params = $this->_params
;
101 $result = civicrm_api('payment_processor', 'create', $params);
102 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
103 $this->assertNotNull($result['id'], 'in line ' . __LINE__
);
105 // mutate $params to match expected return value
106 unset($params['version']);
107 //assertDBState compares expected values in $result to actual values in the DB
108 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
109 return $result['id'];
113 * Test using example code
115 function testPaymentProcessorCreateExample() {
116 require_once 'api/v3/examples/PaymentProcessorCreate.php';
117 $result = payment_processor_create_example();
118 $expectedResult = payment_processor_create_expectedresult();
119 $this->assertEquals($result['is_error'], 0);
122 ///////////////// civicrm_payment_processor_delete methods
125 * check payment processor type delete
127 function testPaymentProcessorDelete() {
128 $id = $this->testPaymentProcessorCreate();
129 // create sample payment processor type.
132 'version' => $this->_apiversion
,
135 $result = civicrm_api('payment_processor', 'delete', $params);
136 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
137 $this->assertEquals($result['is_error'], 0);
140 ///////////////// civicrm_payment_processors_get methods
143 * check with valid params array.
145 function testPaymentProcessorsGet() {
146 $params = $this->_params
;
147 $params['user_name'] = 'test@test.com';
148 civicrm_api('payment_processor', 'create', $params);
151 'user_name' => 'test@test.com',
152 'version' => $this->_apiversion
,
154 $results = civicrm_api('payment_processor', 'get', $params);
156 $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__
);
157 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
158 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__
);