tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Financial / BAO / FinancialAccountTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035 27
e9479dcf
EM
28/**
29 * Class CRM_Financial_BAO_FinancialAccountTest
30 */
6a488035
TO
31class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
32
00be9182 33 public function setUp() {
6a488035 34 parent::setUp();
f17d75bb
PN
35 $this->organizationCreate();
36 }
37
00be9182 38 public function teardown() {
f17d75bb 39 $this->financialAccountDelete('Donations');
6a488035
TO
40 }
41
42 /**
100fef9d 43 * Check method add()
6a488035 44 */
00be9182 45 public function testAdd() {
6a488035
TO
46 $params = array(
47 'name' => 'Donations',
48 'is_deductible' => 0,
49 'is_active' => 1,
50 );
51 $ids = array();
52 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
53
54 $result = $this->assertDBNotNull(
55 'CRM_Financial_BAO_FinancialAccount',
56 $contributionType->id,
57 'name',
58 'id',
59 'Database check on updated financial type record.'
60 );
61
62 $this->assertEquals($result, 'Donations', 'Verify financial type name.');
63 }
64
65 /**
100fef9d 66 * Check method retrive()
6a488035 67 */
00be9182 68 public function testRetrieve() {
6a488035 69 $params = array(
f17d75bb 70 'name' => 'Donations',
6a488035
TO
71 'is_deductible' => 0,
72 'is_active' => 1,
73 );
74 $ids = $defaults = array();
75 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
76
77 $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
78
f17d75bb 79 $this->assertEquals($result->name, 'Donations', 'Verify financial type name.');
6a488035
TO
80 }
81
82 /**
100fef9d 83 * Check method setIsActive()
6a488035 84 */
00be9182 85 public function testSetIsActive() {
6a488035 86 $params = array(
f17d75bb 87 'name' => 'Donations',
6a488035
TO
88 'is_deductible' => 0,
89 'is_active' => 1,
90 );
91 $ids = array();
92 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
93 $result = CRM_Financial_BAO_FinancialAccount::setIsActive($contributionType->id, 0);
94 $this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.');
95
96 $isActive = $this->assertDBNotNull(
97 'CRM_Financial_BAO_FinancialAccount',
98 $contributionType->id,
99 'is_active',
100 'id',
101 'Database check on updated for financial type is_active.'
102 );
103 $this->assertEquals($isActive, 0, 'Verify financial types is_active.');
104 }
105
106 /**
100fef9d 107 * Check method del()
6a488035 108 */
00be9182 109 public function testdel() {
6a488035 110 $params = array(
f17d75bb 111 'name' => 'Donations',
6a488035
TO
112 'is_deductible' => 0,
113 'is_active' => 1,
114 );
115 $ids = array();
116 $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
117
118 CRM_Financial_BAO_FinancialAccount::del($contributionType->id);
119 $params = array('id' => $contributionType->id);
120 $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
121 $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
122 }
123
124 /**
100fef9d 125 * Check method getAccountingCode()
6a488035 126 */
00be9182 127 public function testGetAccountingCode() {
6a488035 128 $params = array(
f17d75bb 129 'name' => 'Donations',
6a488035
TO
130 'is_active' => 1,
131 'is_reserved' => 0,
132 );
133
134 $ids = array();
6a488035 135 $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
f17d75bb
PN
136 $financialAccountid = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Donations', 'id', 'name');
137 CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountid, 'accounting_code', '4800');
6a488035 138 $accountingCode = CRM_Financial_BAO_FinancialAccount::getAccountingCode($financialType->id);
481a74f4 139 $this->assertEquals($accountingCode, 4800, 'Verify accounting code.');
6a488035 140 }
96025800 141
6a488035 142}