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