Commit | Line | Data |
---|---|---|
21150aae | 1 | <?php |
21150aae CW |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
21150aae | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | * | |
acb109b7 | 31 | * @group headless |
21150aae CW |
32 | */ |
33 | class api_v3_PaymentProcessorTest extends CiviUnitTestCase { | |
34 | protected $_paymentProcessorType; | |
fa7b9efb | 35 | protected $_apiversion = 3; |
21150aae | 36 | protected $_params; |
b7c9bc4c | 37 | |
00be9182 | 38 | public function setUp() { |
21150aae | 39 | parent::setUp(); |
208f71f0 | 40 | $this->useTransaction(TRUE); |
21150aae CW |
41 | // Create dummy processor |
42 | $params = array( | |
21150aae CW |
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 | ); | |
fa7b9efb | 49 | $result = $this->callAPISuccess('payment_processor_type', 'create', $params); |
21150aae CW |
50 | $this->_paymentProcessorType = $result['id']; |
51 | $this->_params = array( | |
21150aae CW |
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 | ||
21150aae | 60 | /** |
eceb18cc | 61 | * Check with no name. |
21150aae | 62 | */ |
00be9182 | 63 | public function testPaymentProcessorCreateWithoutName() { |
21150aae CW |
64 | $payProcParams = array( |
65 | 'is_active' => 1, | |
21150aae | 66 | ); |
3c27d467 | 67 | $this->callAPIFailure('payment_processor', 'create', $payProcParams); |
21150aae CW |
68 | } |
69 | ||
70 | /** | |
eceb18cc | 71 | * Create payment processor. |
21150aae | 72 | */ |
00be9182 | 73 | public function testPaymentProcessorCreate() { |
21150aae | 74 | $params = $this->_params; |
fa7b9efb | 75 | $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__); |
ba4a1892 | 76 | $this->assertNotNull($result['id']); |
21150aae CW |
77 | $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params); |
78 | return $result['id']; | |
79 | } | |
80 | ||
81 | /** | |
eceb18cc | 82 | * Test using example code. |
21150aae | 83 | */ |
00be9182 | 84 | public function testPaymentProcessorCreateExample() { |
3ec6e38d | 85 | require_once 'api/v3/examples/PaymentProcessor/Create.php'; |
21150aae CW |
86 | $result = payment_processor_create_example(); |
87 | $expectedResult = payment_processor_create_expectedresult(); | |
791c263c | 88 | $this->assertAPISuccess($result); |
21150aae CW |
89 | } |
90 | ||
21150aae | 91 | /** |
eceb18cc | 92 | * Check payment processor delete. |
21150aae | 93 | */ |
00be9182 | 94 | public function testPaymentProcessorDelete() { |
21150aae | 95 | $id = $this->testPaymentProcessorCreate(); |
21150aae CW |
96 | $params = array( |
97 | 'id' => $id, | |
21150aae CW |
98 | ); |
99 | ||
3c27d467 | 100 | $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__); |
21150aae CW |
101 | } |
102 | ||
21150aae | 103 | /** |
100fef9d | 104 | * Check with valid params array. |
21150aae | 105 | */ |
00be9182 | 106 | public function testPaymentProcessorsGet() { |
21150aae CW |
107 | $params = $this->_params; |
108 | $params['user_name'] = 'test@test.com'; | |
fa7b9efb | 109 | $this->callAPISuccess('payment_processor', 'create', $params); |
21150aae CW |
110 | |
111 | $params = array( | |
112 | 'user_name' => 'test@test.com', | |
21150aae | 113 | ); |
fa7b9efb | 114 | $results = $this->callAPISuccess('payment_processor', 'get', $params); |
21150aae | 115 | |
3c27d467 | 116 | $this->assertEquals(1, $results['count']); |
117 | $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']); | |
21150aae | 118 | } |
96025800 | 119 | |
21150aae | 120 | } |