Merge pull request #3223 from lcdservices/CRM-14672
[civicrm-core.git] / tests / phpunit / CRM / Financial / BAO / PaymentProcessorTypeTest.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 require_once 'CiviTest/CiviUnitTestCase.php';
28 require_once 'CRM/Financial/DAO/FinancialAccount.php';
29 require_once 'CRM/Financial/BAO/FinancialAccount.php';
30 require_once 'CRM/Financial/BAO/FinancialTypeAccount.php';
31
32 class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase {
33
34 function get_info() {
35 return array(
36 'name' => 'PaymentProcessorType BAOs',
37 'description' => 'Test all Contribute_BAO_Contribution methods.',
38 'group' => 'CiviCRM BAO Tests',
39 );
40 }
41
42 function setUp() {
43 parent::setUp();
44 }
45
46 /**
47 * check method create()
48 */
49 function testCreate() {
50 $params = array(
51 'name' => 'Test_Payment_Processor',
52 'title' => 'Test Payment Processor',
53 'billing_mode' => 1,
54 );
55 $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
56 $result = $this->assertDBNotNull(
57 'CRM_Financial_DAO_PaymentProcessorType',
58 $paymentProcessor->name,
59 'title',
60 'name',
61 'Database check on added payment processor type record.'
62 );
63 $this->assertEquals( $result, 'Test Payment Processor', 'Verify Payment Processor Type');
64 }
65
66 /**
67 * check method retrieve()
68 */
69 function testRetrieve() {
70 $params = array(
71 'name' => 'Test_Retrieve_Payment_Processor',
72 'title' => 'Test Retrieve Payment Processor',
73 'billing_mode' => 1,
74 );
75 $defaults = array();
76 CRM_Financial_BAO_PaymentProcessorType::create($params);
77 $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
78 $this->assertEquals( $result->name, 'Test_Retrieve_Payment_Processor', 'Verify Payment Processor Type');
79 }
80
81 /**
82 * check method setIsActive()
83 */
84 function testSetIsActive() {
85 $params = array(
86 'name' => 'Test_Set_Payment_Processor',
87 'title' => 'Test Set Payment Processor',
88 'billing_mode' => 1,
89 'is_active' => 1,
90 );
91
92 $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
93 $result = CRM_Financial_BAO_PaymentProcessorType::setIsActive($paymentProcessor->id, 0);
94 $this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.');
95
96 $isActive = $this->assertDBNotNull(
97 'CRM_Financial_DAO_PaymentProcessorType',
98 $paymentProcessor->id,
99 'is_active',
100 'id',
101 'Database check on updated for payment processor type is_active.'
102 );
103 $this->assertEquals($isActive, 0, 'Verify payment processor types is_active.');
104 }
105
106 /**
107 * check method getDefault()
108 */
109 function testGetDefault() {
110 $params = array('is_default' => 1);
111 $defaults = array();
112 $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
113
114 $default = CRM_Financial_BAO_PaymentProcessorType::getDefault();
115 $this->assertEquals($result->name, $default->name, 'Verify default payment processor.');
116 }
117
118 /**
119 * check method del()
120 */
121 function testDel() {
122 $params = array(
123 'name' => 'Test_Del_Payment_Processor',
124 'title' => 'Test Del Payment Processor',
125 'billing_mode' => 1,
126 'is_active' => 1,
127 );
128
129 $defaults = array();
130 $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
131 CRM_Financial_BAO_PaymentProcessorType::del($paymentProcessor->id);
132
133 $params = array('id' => $paymentProcessor->id);
134 $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
135 $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
136 }
137 }