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