tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / api / v3 / PaymentProcessorTest.php
CommitLineData
21150aae 1<?php
21150aae
CW
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
21150aae 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
21150aae
CW
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
21150aae 27
21150aae
CW
28/**
29 * Class contains api test cases for "civicrm_payment_processor"
30 *
31 */
32class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
33 protected $_paymentProcessorType;
fa7b9efb 34 protected $_apiversion = 3;
21150aae 35 protected $_params;
b7c9bc4c 36
00be9182 37 public function setUp() {
21150aae 38 parent::setUp();
208f71f0 39 $this->useTransaction(TRUE);
21150aae
CW
40 // Create dummy processor
41 $params = array(
21150aae
CW
42 'name' => 'API_Test_PP_Type',
43 'title' => 'API Test Payment Processor Type',
44 'class_name' => 'CRM_Core_Payment_APITest',
45 'billing_mode' => 'form',
46 'is_recur' => 0,
47 );
fa7b9efb 48 $result = $this->callAPISuccess('payment_processor_type', 'create', $params);
21150aae
CW
49 $this->_paymentProcessorType = $result['id'];
50 $this->_params = array(
21150aae
CW
51 'name' => 'API Test PP',
52 'payment_processor_type_id' => $this->_paymentProcessorType,
53 'class_name' => 'CRM_Core_Payment_APITest',
54 'is_recur' => 0,
55 'domain_id' => 1,
56 );
57 }
58
21150aae
CW
59 ///////////////// civicrm_payment_processor_add methods
60
61 /**
eceb18cc 62 * Check with no name.
21150aae 63 */
00be9182 64 public function testPaymentProcessorCreateWithoutName() {
21150aae
CW
65 $payProcParams = array(
66 'is_active' => 1,
21150aae 67 );
d0e1eff2 68 $result = $this->callAPIFailure('payment_processor', 'create', $payProcParams);
21150aae
CW
69 }
70
71 /**
eceb18cc 72 * Create payment processor.
21150aae 73 */
00be9182 74 public function testPaymentProcessorCreate() {
21150aae 75 $params = $this->_params;
fa7b9efb 76 $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__);
ba4a1892 77 $this->assertNotNull($result['id']);
21150aae 78
21150aae
CW
79 //assertDBState compares expected values in $result to actual values in the DB
80 $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
81 return $result['id'];
82 }
83
84 /**
eceb18cc 85 * Test using example code.
21150aae 86 */
00be9182 87 public function testPaymentProcessorCreateExample() {
3ec6e38d 88 require_once 'api/v3/examples/PaymentProcessor/Create.php';
21150aae
CW
89 $result = payment_processor_create_example();
90 $expectedResult = payment_processor_create_expectedresult();
791c263c 91 $this->assertAPISuccess($result);
21150aae
CW
92 }
93
94 ///////////////// civicrm_payment_processor_delete methods
95
96 /**
eceb18cc 97 * Check payment processor delete.
21150aae 98 */
00be9182 99 public function testPaymentProcessorDelete() {
21150aae 100 $id = $this->testPaymentProcessorCreate();
21150aae
CW
101 $params = array(
102 'id' => $id,
21150aae
CW
103 );
104
fa7b9efb 105 $result = $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
21150aae
CW
106 }
107
108 ///////////////// civicrm_payment_processors_get methods
109
110 /**
100fef9d 111 * Check with valid params array.
21150aae 112 */
00be9182 113 public function testPaymentProcessorsGet() {
21150aae
CW
114 $params = $this->_params;
115 $params['user_name'] = 'test@test.com';
fa7b9efb 116 $this->callAPISuccess('payment_processor', 'create', $params);
21150aae
CW
117
118 $params = array(
119 'user_name' => 'test@test.com',
21150aae 120 );
fa7b9efb 121 $results = $this->callAPISuccess('payment_processor', 'get', $params);
21150aae 122
21150aae
CW
123 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__);
124 $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__);
125 }
96025800 126
21150aae 127}