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