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