Merge branch 'master' into master-civimail-abtest
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Class contains api test cases for "civicrm_payment_processor"
32 *
33 */
34 class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
35 protected $_paymentProcessorType;
36 protected $_apiversion = 3;
37 protected $_params;
38
39 /**
40 * @return array
41 */
42 function get_info() {
43 return array(
44 'name' => 'PaymentProcessor Create',
45 'description' => 'Test all PaymentProcessor Create API methods.',
46 'group' => 'CiviCRM API Tests',
47 );
48 }
49
50 function setUp() {
51 parent::setUp();
52 // Create dummy processor
53 $params = array(
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 = $this->callAPISuccess('payment_processor_type', 'create', $params);
61 $this->_paymentProcessorType = $result['id'];
62 $this->_params = array(
63 'name' => 'API Test PP',
64 'payment_processor_type_id' => $this->_paymentProcessorType,
65 'class_name' => 'CRM_Core_Payment_APITest',
66 'is_recur' => 0,
67 'domain_id' => 1,
68 );
69 }
70
71 function tearDown() {
72
73 $tablesToTruncate = array(
74 'civicrm_payment_processor',
75 'civicrm_payment_processor_type',
76 );
77 $this->quickCleanup($tablesToTruncate);
78 }
79
80 ///////////////// civicrm_payment_processor_add methods
81
82 /**
83 * Check with no name
84 */
85 function testPaymentProcessorCreateWithoutName() {
86 $payProcParams = array(
87 'is_active' => 1,
88 );
89 $result = $this->callAPIFailure('payment_processor', 'create', $payProcParams);
90 }
91
92 /**
93 * Create payment processor
94 */
95 function testPaymentProcessorCreate() {
96 $params = $this->_params;
97 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__);
98 $this->assertNotNull($result['id'], 'in line ' . __LINE__);
99
100 //assertDBState compares expected values in $result to actual values in the DB
101 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
102 return $result['id'];
103 }
104
105 /**
106 * Test using example code
107 */
108 function testPaymentProcessorCreateExample() {
109 require_once 'api/v3/examples/PaymentProcessor/Create.php';
110 $result = payment_processor_create_example();
111 $expectedResult = payment_processor_create_expectedresult();
112 $this->assertAPISuccess($result);
113 }
114
115 ///////////////// civicrm_payment_processor_delete methods
116
117 /**
118 * Check payment processor delete
119 */
120 function testPaymentProcessorDelete() {
121 $id = $this->testPaymentProcessorCreate();
122 $params = array(
123 'id' => $id,
124 );
125
126 $result = $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
127 }
128
129 ///////////////// civicrm_payment_processors_get methods
130
131 /**
132 * Check with valid params array.
133 */
134 function testPaymentProcessorsGet() {
135 $params = $this->_params;
136 $params['user_name'] = 'test@test.com';
137 $this->callAPISuccess('payment_processor', 'create', $params);
138
139 $params = array(
140 'user_name' => 'test@test.com',
141 );
142 $results = $this->callAPISuccess('payment_processor', 'get', $params);
143
144 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__);
145 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__);
146 }
147 }
148