add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / CRM / Financial / BAO / FinancialAccountTest.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
29 class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
30
31 function get_info() {
32 return array(
33 'name' => 'FinancialAccount BAOs',
34 'description' => 'Test all Contribute_BAO_Contribution methods.',
35 'group' => 'CiviCRM BAO Tests',
36 );
37 }
38
39 function setUp() {
40 parent::setUp();
41 $this->organizationCreate();
42 }
43
44 function teardown() {
45 $this->financialAccountDelete('Donations');
46 }
47
48 /**
49 * check method add()
50 */
51 function testAdd() {
52 $params = array(
53 'name' => 'Donations',
54 'is_deductible' => 0,
55 'is_active' => 1,
56 );
57 $ids = array();
58 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
59
60 $result = $this->assertDBNotNull(
61 'CRM_Financial_BAO_FinancialAccount',
62 $contributionType->id,
63 'name',
64 'id',
65 'Database check on updated financial type record.'
66 );
67
68 $this->assertEquals($result, 'Donations', 'Verify financial type name.');
69 }
70
71 /**
72 * check method retrive()
73 */
74 function testRetrieve() {
75 $params = array(
76 'name' => 'Donations',
77 'is_deductible' => 0,
78 'is_active' => 1,
79 );
80 $ids = $defaults = array();
81 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
82
83 $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
84
85 $this->assertEquals($result->name, 'Donations', 'Verify financial type name.');
86 }
87
88 /**
89 * check method setIsActive()
90 */
91 function testSetIsActive() {
92 $params = array(
93 'name' => 'Donations',
94 'is_deductible' => 0,
95 'is_active' => 1,
96 );
97 $ids = array();
98 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
99 $result = CRM_Financial_BAO_FinancialAccount::setIsActive($contributionType->id, 0);
100 $this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.');
101
102 $isActive = $this->assertDBNotNull(
103 'CRM_Financial_BAO_FinancialAccount',
104 $contributionType->id,
105 'is_active',
106 'id',
107 'Database check on updated for financial type is_active.'
108 );
109 $this->assertEquals($isActive, 0, 'Verify financial types is_active.');
110 }
111
112 /**
113 * check method del()
114 */
115 function testdel() {
116 $params = array(
117 'name' => 'Donations',
118 'is_deductible' => 0,
119 'is_active' => 1,
120 );
121 $ids = array();
122 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
123
124 CRM_Financial_BAO_FinancialAccount::del($contributionType->id);
125 $params = array('id' => $contributionType->id);
126 $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
127 $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
128 }
129
130 /**
131 * check method getAccountingCode()
132 */
133 function testGetAccountingCode() {
134 $params = array(
135 'name' => 'Donations',
136 'is_active' => 1,
137 'is_reserved' => 0,
138 );
139
140 $ids = array();
141 $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
142 $financialAccountid = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Donations', 'id', 'name');
143 CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountid, 'accounting_code', '4800');
144 $accountingCode = CRM_Financial_BAO_FinancialAccount::getAccountingCode($financialType->id);
145 $this->assertEquals( $accountingCode, 4800, 'Verify accounting code.');
146 }
147 }