Merge pull request #11086 from agileware/CRM-21277
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class contains api test cases for "civicrm_payment_processor"
30 *
31 * @group headless
32 */
33 class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
34 protected $_paymentProcessorType;
35 protected $_apiversion = 3;
36 protected $_params;
37
38 public function setUp() {
39 parent::setUp();
40 $this->useTransaction(TRUE);
41 // Create dummy processor
42 $params = array(
43 'name' => 'API_Test_PP_Type',
44 'title' => 'API Test Payment Processor Type',
45 'class_name' => 'CRM_Core_Payment_APITest',
46 'billing_mode' => 'form',
47 'is_recur' => 0,
48 );
49 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
50 $this->_paymentProcessorType = $result['id'];
51 $this->_params = array(
52 'name' => 'API Test PP',
53 'payment_processor_type_id' => $this->_paymentProcessorType,
54 'class_name' => 'CRM_Core_Payment_APITest',
55 'is_recur' => 0,
56 'domain_id' => 1,
57 );
58 }
59
60 /**
61 * Check with no name.
62 */
63 public function testPaymentProcessorCreateWithoutName() {
64 $payProcParams = array(
65 'is_active' => 1,
66 );
67 $this->callAPIFailure('payment_processor', 'create', $payProcParams);
68 }
69
70 /**
71 * Create payment processor.
72 */
73 public function testPaymentProcessorCreate() {
74 $params = $this->_params;
75 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__);
76 $this->assertNotNull($result['id']);
77 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
78 return $result['id'];
79 }
80
81 /**
82 * Update payment processor.
83 */
84 public function testPaymentProcessorUpdate() {
85 $params = $this->_params;
86 $result = $this->callAPISuccess('payment_processor', 'create', $params);
87 $this->assertNotNull($result['id']);
88
89 $updateParams = array(
90 'id' => $result['id'],
91 'name' => 'Update API Test',
92 );
93 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
94 $this->callAPISuccess('payment_processor', 'create', $updateParams);
95 $result = $this->callAPISuccess('payment_processor', 'get', array('id' => $result['id']));
96
97 $expectedResult = array(
98 'id' => $result['id'],
99 'domain_id' => $params['domain_id'],
100 'name' => $updateParams['name'],
101 'payment_processor_type_id' => $params['payment_processor_type_id'],
102 'is_default' => 0,
103 'is_test' => 0,
104 'class_name' => $params['class_name'],
105 'billing_mode' => 1,
106 'is_recur' => $params['is_recur'],
107 'payment_type' => 1,
108 'payment_instrument_id' => 1,
109 );
110 $this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
111 }
112
113 /**
114 * Test using example code.
115 */
116 public function testPaymentProcessorCreateExample() {
117 require_once 'api/v3/examples/PaymentProcessor/Create.php';
118 $result = payment_processor_create_example();
119 $expectedResult = payment_processor_create_expectedresult();
120 $this->assertAPISuccess($result);
121 }
122
123 /**
124 * Check payment processor delete.
125 */
126 public function testPaymentProcessorDelete() {
127 $id = $this->testPaymentProcessorCreate();
128 $params = array(
129 'id' => $id,
130 );
131
132 $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
133 }
134
135 /**
136 * Check with valid params array.
137 */
138 public function testPaymentProcessorsGet() {
139 $params = $this->_params;
140 $params['user_name'] = 'test@test.com';
141 $this->callAPISuccess('payment_processor', 'create', $params);
142
143 $params = array(
144 'user_name' => 'test@test.com',
145 );
146 $results = $this->callAPISuccess('payment_processor', 'get', $params);
147
148 $this->assertEquals(1, $results['count']);
149 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']);
150 }
151
152 }