5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
30 require_once 'CiviTest/CiviUnitTestCase.php';
33 * Class contains api test cases for "civicrm_payment_processor"
36 class api_v3_PaymentProcessorTest
extends CiviUnitTestCase
{
37 protected $_paymentProcessorType;
38 protected $_apiversion;
40 public $_eNoticeCompliant = TRUE;
43 'name' => 'PaymentProcessor Create',
44 'description' => 'Test all PaymentProcessor Create API methods.',
45 'group' => 'CiviCRM API Tests',
51 $this->_apiversion
= 3;
52 // Create dummy processor
54 'version' => $this->_apiversion
,
55 'name' => 'API_Test_PP_Type',
56 'title' => 'API Test Payment Processor Type',
57 'class_name' => 'CRM_Core_Payment_APITest',
58 'billing_mode' => 'form',
61 $result = civicrm_api('payment_processor_type', 'create', $params);
62 $this->_paymentProcessorType
= $result['id'];
63 $this->_params
= array(
64 'version' => $this->_apiversion
,
65 'name' => 'API Test PP',
66 'payment_processor_type_id' => $this->_paymentProcessorType
,
67 'class_name' => 'CRM_Core_Payment_APITest',
75 $tablesToTruncate = array(
76 'civicrm_payment_processor',
77 'civicrm_payment_processor_type',
79 $this->quickCleanup($tablesToTruncate);
82 ///////////////// civicrm_payment_processor_add methods
87 function testPaymentProcessorCreateWithoutName() {
88 $payProcParams = array(
90 'version' => $this->_apiversion
,
92 $result = civicrm_api('payment_processor', 'create', $payProcParams);
94 $this->assertEquals($result['is_error'], 1);
98 * create payment processor
100 function testPaymentProcessorCreate() {
101 $params = $this->_params
;
102 $result = civicrm_api('payment_processor', 'create', $params);
103 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
104 $this->assertNotNull($result['id'], 'in line ' . __LINE__
);
106 // mutate $params to match expected return value
107 unset($params['version']);
108 //assertDBState compares expected values in $result to actual values in the DB
109 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
110 return $result['id'];
114 * Test using example code
116 function testPaymentProcessorCreateExample() {
117 require_once 'api/v3/examples/PaymentProcessorCreate.php';
118 $result = payment_processor_create_example();
119 $expectedResult = payment_processor_create_expectedresult();
120 $this->assertEquals($result['is_error'], 0);
123 ///////////////// civicrm_payment_processor_delete methods
126 * check payment processor type delete
128 function testPaymentProcessorDelete() {
129 $id = $this->testPaymentProcessorCreate();
130 // create sample payment processor type.
133 'version' => $this->_apiversion
,
136 $result = civicrm_api('payment_processor', 'delete', $params);
137 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
138 $this->assertEquals($result['is_error'], 0);
141 ///////////////// civicrm_payment_processors_get methods
144 * check with valid params array.
146 function testPaymentProcessorsGet() {
147 $params = $this->_params
;
148 $params['user_name'] = 'test@test.com';
149 civicrm_api('payment_processor', 'create', $params);
152 'user_name' => 'test@test.com',
153 'version' => $this->_apiversion
,
155 $results = civicrm_api('payment_processor', 'get', $params);
157 $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__
);
158 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
159 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__
);