Merge pull request #353 from eileenmcnaughton/trunk-kill-eval
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTest.php
1 <?php
2 // $Id$
3
4 /*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
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. |
15 | |
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. |
20 | |
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 +--------------------------------------------------------------------+
28 */
29
30 require_once 'CiviTest/CiviUnitTestCase.php';
31
32 /**
33 * Class contains api test cases for "civicrm_payment_processor"
34 *
35 */
36 class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
37 protected $_paymentProcessorType;
38 protected $_apiversion;
39 protected $_params;
40 public $_eNoticeCompliant = TRUE;
41 function get_info() {
42 return array(
43 'name' => 'PaymentProcessor Create',
44 'description' => 'Test all PaymentProcessor Create API methods.',
45 'group' => 'CiviCRM API Tests',
46 );
47 }
48
49 function setUp() {
50 parent::setUp();
51 $this->_apiversion = 3;
52 // Create dummy processor
53 $params = array(
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',
59 'is_recur' => 0,
60 );
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',
68 'is_recur' => 0,
69 'domain_id' => 1,
70 );
71 }
72
73 function tearDown() {
74
75 $tablesToTruncate = array(
76 'civicrm_payment_processor',
77 'civicrm_payment_processor_type',
78 );
79 $this->quickCleanup($tablesToTruncate);
80 }
81
82 ///////////////// civicrm_payment_processor_add methods
83
84 /**
85 * check with no name
86 */
87 function testPaymentProcessorCreateWithoutName() {
88 $payProcParams = array(
89 'is_active' => 1,
90 'version' => $this->_apiversion,
91 );
92 $result = civicrm_api('payment_processor', 'create', $payProcParams);
93
94 $this->assertEquals($result['is_error'], 1);
95 }
96
97 /**
98 * create payment processor
99 */
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__);
105
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'];
111 }
112
113 /**
114 * Test using example code
115 */
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);
121 }
122
123 ///////////////// civicrm_payment_processor_delete methods
124
125 /**
126 * check payment processor type delete
127 */
128 function testPaymentProcessorDelete() {
129 $id = $this->testPaymentProcessorCreate();
130 // create sample payment processor type.
131 $params = array(
132 'id' => $id,
133 'version' => $this->_apiversion,
134 );
135
136 $result = civicrm_api('payment_processor', 'delete', $params);
137 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
138 $this->assertEquals($result['is_error'], 0);
139 }
140
141 ///////////////// civicrm_payment_processors_get methods
142
143 /**
144 * check with valid params array.
145 */
146 function testPaymentProcessorsGet() {
147 $params = $this->_params;
148 $params['user_name'] = 'test@test.com';
149 civicrm_api('payment_processor', 'create', $params);
150
151 $params = array(
152 'user_name' => 'test@test.com',
153 'version' => $this->_apiversion,
154 );
155 $results = civicrm_api('payment_processor', 'get', $params);
156
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__);
160 }
161 }
162