Commit | Line | Data |
---|---|---|
21150aae | 1 | <?php |
21150aae CW |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
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. | | |
14 | | | | |
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. | | |
19 | | | | |
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 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | ||
31 | /** | |
32 | * Class contains api test cases for "civicrm_payment_processor" | |
33 | * | |
34 | */ | |
35 | class api_v3_PaymentProcessorTest extends CiviUnitTestCase { | |
36 | protected $_paymentProcessorType; | |
37 | protected $_apiversion; | |
38 | protected $_params; | |
39 | public $_eNoticeCompliant = TRUE; | |
40 | function get_info() { | |
41 | return array( | |
42 | 'name' => 'PaymentProcessor Create', | |
43 | 'description' => 'Test all PaymentProcessor Create API methods.', | |
44 | 'group' => 'CiviCRM API Tests', | |
45 | ); | |
46 | } | |
47 | ||
48 | function setUp() { | |
49 | parent::setUp(); | |
50 | $this->_apiversion = 3; | |
51 | // Create dummy processor | |
52 | $params = array( | |
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', | |
58 | 'is_recur' => 0, | |
59 | ); | |
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', | |
67 | 'is_recur' => 0, | |
68 | 'domain_id' => 1, | |
69 | ); | |
70 | } | |
71 | ||
72 | function tearDown() { | |
73 | ||
74 | $tablesToTruncate = array( | |
75 | 'civicrm_payment_processor', | |
76 | 'civicrm_payment_processor_type', | |
77 | ); | |
78 | $this->quickCleanup($tablesToTruncate); | |
79 | } | |
80 | ||
81 | ///////////////// civicrm_payment_processor_add methods | |
82 | ||
83 | /** | |
84 | * check with no name | |
85 | */ | |
86 | function testPaymentProcessorCreateWithoutName() { | |
87 | $payProcParams = array( | |
88 | 'is_active' => 1, | |
89 | 'version' => $this->_apiversion, | |
90 | ); | |
d0e1eff2 | 91 | $result = $this->callAPIFailure('payment_processor', 'create', $payProcParams); |
21150aae CW |
92 | } |
93 | ||
94 | /** | |
95 | * create payment processor | |
96 | */ | |
97 | function testPaymentProcessorCreate() { | |
98 | $params = $this->_params; | |
99 | $result = civicrm_api('payment_processor', 'create', $params); | |
48ab68c7 | 100 | $this->assertAPISuccess($result); |
21150aae CW |
101 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); |
102 | $this->assertNotNull($result['id'], 'in line ' . __LINE__); | |
103 | ||
104 | // mutate $params to match expected return value | |
105 | unset($params['version']); | |
106 | //assertDBState compares expected values in $result to actual values in the DB | |
107 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params); | |
108 | return $result['id']; | |
109 | } | |
110 | ||
111 | /** | |
112 | * Test using example code | |
113 | */ | |
114 | function testPaymentProcessorCreateExample() { | |
115 | require_once 'api/v3/examples/PaymentProcessorCreate.php'; | |
116 | $result = payment_processor_create_example(); | |
117 | $expectedResult = payment_processor_create_expectedresult(); | |
791c263c | 118 | $this->assertAPISuccess($result); |
21150aae CW |
119 | } |
120 | ||
121 | ///////////////// civicrm_payment_processor_delete methods | |
122 | ||
123 | /** | |
124 | * check payment processor type delete | |
125 | */ | |
126 | function testPaymentProcessorDelete() { | |
127 | $id = $this->testPaymentProcessorCreate(); | |
128 | // create sample payment processor type. | |
129 | $params = array( | |
130 | 'id' => $id, | |
131 | 'version' => $this->_apiversion, | |
132 | ); | |
133 | ||
134 | $result = civicrm_api('payment_processor', 'delete', $params); | |
135 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
791c263c | 136 | $this->assertAPISuccess($result); |
21150aae CW |
137 | } |
138 | ||
139 | ///////////////// civicrm_payment_processors_get methods | |
140 | ||
141 | /** | |
142 | * check with valid params array. | |
143 | */ | |
144 | function testPaymentProcessorsGet() { | |
145 | $params = $this->_params; | |
146 | $params['user_name'] = 'test@test.com'; | |
147 | civicrm_api('payment_processor', 'create', $params); | |
148 | ||
149 | $params = array( | |
150 | 'user_name' => 'test@test.com', | |
151 | 'version' => $this->_apiversion, | |
152 | ); | |
153 | $results = civicrm_api('payment_processor', 'get', $params); | |
154 | ||
155 | $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__); | |
156 | $this->assertEquals(1, $results['count'], ' in line ' . __LINE__); | |
157 | $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__); | |
158 | } | |
159 | } | |
160 |