Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-11-23-22-46-27
[civicrm-core.git] / tests / phpunit / CRM / Financial / BAO / PaymentProcessorTypeTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 /**
33 * Class CRM_Financial_BAO_PaymentProcessorTypeTest
34 */
35 class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase {
36
37 public function setUp() {
38 parent::setUp();
39 }
40
41 /**
42 * Check method create()
43 */
44 public function testCreate() {
45 $params = array(
46 'name' => 'Test_Payment_Processor',
47 'title' => 'Test Payment Processor',
48 'billing_mode' => 1,
49 );
50 $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
51 $result = $this->assertDBNotNull(
52 'CRM_Financial_DAO_PaymentProcessorType',
53 $paymentProcessor->name,
54 'title',
55 'name',
56 'Database check on added payment processor type record.'
57 );
58 $this->assertEquals($result, 'Test Payment Processor', 'Verify Payment Processor Type');
59 }
60
61 /**
62 * Check method retrieve()
63 */
64 public function testRetrieve() {
65 $params = array(
66 'name' => 'Test_Retrieve_Payment_Processor',
67 'title' => 'Test Retrieve Payment Processor',
68 'billing_mode' => 1,
69 );
70 $defaults = array();
71 CRM_Financial_BAO_PaymentProcessorType::create($params);
72 $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
73 $this->assertEquals($result->name, 'Test_Retrieve_Payment_Processor', 'Verify Payment Processor Type');
74 }
75
76 /**
77 * Check method setIsActive()
78 */
79 public function testSetIsActive() {
80 $params = array(
81 'name' => 'Test_Set_Payment_Processor',
82 'title' => 'Test Set Payment Processor',
83 'billing_mode' => 1,
84 'is_active' => 1,
85 );
86
87 $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
88 $result = CRM_Financial_BAO_PaymentProcessorType::setIsActive($paymentProcessor->id, 0);
89 $this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.');
90
91 $isActive = $this->assertDBNotNull(
92 'CRM_Financial_DAO_PaymentProcessorType',
93 $paymentProcessor->id,
94 'is_active',
95 'id',
96 'Database check on updated for payment processor type is_active.'
97 );
98 $this->assertEquals($isActive, 0, 'Verify payment processor types is_active.');
99 }
100
101 /**
102 * Check method getDefault()
103 */
104 public function testGetDefault() {
105 $params = array('is_default' => 1);
106 $defaults = array();
107 $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
108
109 $default = CRM_Financial_BAO_PaymentProcessorType::getDefault();
110 $this->assertEquals($result->name, $default->name, 'Verify default payment processor.');
111 }
112
113 /**
114 * Check method del()
115 */
116 public function testDel() {
117 $params = array(
118 'name' => 'Test_Del_Payment_Processor',
119 'title' => 'Test Del Payment Processor',
120 'billing_mode' => 1,
121 'is_active' => 1,
122 );
123
124 $defaults = array();
125 $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
126 CRM_Financial_BAO_PaymentProcessorType::del($paymentProcessor->id);
127
128 $params = array('id' => $paymentProcessor->id);
129 $result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
130 $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
131 }
132
133 }