1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/modules/accounting/Year.php'; |
3
|
|
|
require_once 'Intraface/functions.php'; |
4
|
|
|
|
5
|
|
|
class YearTest extends PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
function setUp() |
8
|
|
|
{ |
9
|
|
|
$this->kernel = new Stub_Kernel(); |
|
|
|
|
10
|
|
|
$this->kernel->setting->set('intranet', 'vatpercent', 25); |
11
|
|
|
$this->kernel->setting->set('user', 'accounting.active_year', 0); |
12
|
|
|
$this->kernel->setting->set('intranet', 'accounting.result_account_id', 25); |
13
|
|
|
$this->kernel->setting->set('intranet', 'accounting.debtor_account_id', 25); |
14
|
|
|
$this->kernel->setting->set('intranet', 'accounting.credit_account_id', 25); |
15
|
|
|
$this->kernel->setting->set('intranet', 'accounting.balance_accounts', serialize(array())); |
16
|
|
|
$this->kernel->setting->set('intranet', 'accounting.result_account_id_start', 0); |
17
|
|
|
$this->kernel->setting->set('intranet', 'accounting.result_account_id_end', 0); |
18
|
|
|
$this->kernel->setting->set('intranet', 'accounting.balance_account_id_start', 0); |
19
|
|
|
$this->kernel->setting->set('intranet', 'accounting.balance_account_id_end', 0); |
20
|
|
|
$this->kernel->setting->set('intranet', 'accounting.capital_account_id', 0); |
21
|
|
|
|
22
|
|
|
$this->kernel->setting->set('intranet', 'accounting.vat_in_account_id', 0); |
23
|
|
|
$this->kernel->setting->set('intranet', 'accounting.vat_out_account_id', 0); |
24
|
|
|
$this->kernel->setting->set('intranet', 'accounting.vat_abroad_account_id', 0); |
25
|
|
|
$this->kernel->setting->set('intranet', 'accounting.vat_balance_account_id', 0); |
26
|
|
|
$this->kernel->setting->set('intranet', 'accounting.vat_free_account_id', 0); |
27
|
|
|
$this->kernel->setting->set('intranet', 'accounting.eu_sale_account_id', 0); |
28
|
|
|
$this->kernel->setting->set('intranet', 'accounting.result_account_id', 0); |
29
|
|
|
$this->kernel->setting->set('intranet', 'accounting.debtor_account_id', 0); |
30
|
|
|
$this->kernel->setting->set('intranet', 'accounting.credit_account_id', 0); |
31
|
|
|
$this->kernel->setting->set('intranet', 'accounting.balance_accounts', serialize(array())); |
32
|
|
|
$this->kernel->setting->set('intranet', 'accounting.buy_eu_accounts', serialize(array())); |
33
|
|
|
$this->kernel->setting->set('intranet', 'accounting.buy_abroad_accounts', serialize(array())); |
34
|
|
|
|
35
|
|
|
$this->kernel->setting->set('intranet', 'accounting.result_account_id_start', 0); |
36
|
|
|
$this->kernel->setting->set('intranet', 'accounting.result_account_id_end', 0); |
37
|
|
|
$this->kernel->setting->set('intranet', 'accounting.balance_account_id_start', 0); |
38
|
|
|
$this->kernel->setting->set('intranet', 'accounting.balance_account_id_end', 0); |
39
|
|
|
|
40
|
|
|
$this->kernel->setting->set('intranet', 'accounting.capital_account_id', 0); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function tearDown() |
44
|
|
|
{ |
45
|
|
|
$db = MDB2::singleton(DB_DSN); |
46
|
|
|
$db->exec('TRUNCATE accounting_year'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function testSetYearReturnsFalseWhenYearObjectIsNotSet() |
50
|
|
|
{ |
51
|
|
|
$year = new Year($this->kernel); |
52
|
|
|
$this->assertFalse($year->setYear()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
function testSetYearReturnsTrueWhenYearObjectIsSet() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$year = new Year($this->kernel); |
58
|
|
|
$id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
59
|
|
|
$this->assertTrue($id > 0); |
60
|
|
|
$this->assertTrue($year->setYear()); |
61
|
|
|
$this->assertEquals($id, $year->getActiveYear()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
function testCheckYearReturnsTrueIfActiveYearIsset() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$year = new Year($this->kernel); |
67
|
|
|
$id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
68
|
|
|
$this->assertTrue($id > 0); |
69
|
|
|
$this->assertTrue($year->setYear()); |
70
|
|
|
$this->assertTrue($year->checkYear()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function testCheckYearReturnsFalseIfActiveYearIsNotset() |
74
|
|
|
{ |
75
|
|
|
$year = new Year($this->kernel); |
76
|
|
|
$id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
|
|
|
|
77
|
|
|
$this->assertFalse($year->checkYear(false)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
function testIsYearSetReturnsTrueWhenYearIsset() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$year = new Year($this->kernel); |
83
|
|
|
$id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
84
|
|
|
$this->assertTrue($id > 0); |
85
|
|
|
$this->assertTrue($year->setYear()); |
86
|
|
|
$this->assertTrue($year->isYearSet()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function testSaveMethod() |
90
|
|
|
{ |
91
|
|
|
// TODO needs to be updated |
92
|
|
|
$year = new Year($this->kernel); |
93
|
|
|
$this->assertFalse($year->get('id') > 0); |
94
|
|
|
$this->assertTrue($year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)) > 0); |
95
|
|
|
$this->assertEquals('2000', $year->get('label')); |
96
|
|
|
|
97
|
|
|
$new_year = new Year($this->kernel, $year->get('id'), false); |
98
|
|
|
$this->assertTrue($new_year->save(array('label' => '2000 - edited', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)) > 0); |
99
|
|
|
$this->assertEquals($new_year->get('id'), $year->get('id')); |
100
|
|
|
$this->assertEquals($new_year->get('label'), '2000 - edited'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
function testIsBalancedReturnsTrueWhenNoPostsHasBeenAdded() |
104
|
|
|
{ |
105
|
|
|
$year = new Year($this->kernel); |
106
|
|
|
$id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
|
|
|
|
107
|
|
|
$this->assertTrue($year->isBalanced()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
function testGetList() |
111
|
|
|
{ |
112
|
|
|
$year = new Year($this->kernel); |
113
|
|
|
$this->assertTrue(is_array($year->getList())); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
function testGetBalanceAccountsThrowsEceptionIfBalanceAccountsIsNotAnArray() |
117
|
|
|
{ |
118
|
|
|
$year = new Year($this->kernel); |
119
|
|
|
$id = $year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
|
|
|
|
120
|
|
|
|
121
|
|
|
try { |
122
|
|
|
$year->getBalanceAccounts(); |
123
|
|
|
$this->assertTrue(false); |
124
|
|
|
} catch (Exception $e) { |
125
|
|
|
$this->assertTrue(true); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function testCreateAccounts() |
130
|
|
|
{ |
131
|
|
|
$year = new Year($this->kernel); |
132
|
|
|
$year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
133
|
|
|
$res = $year->createAccounts('standard'); |
134
|
|
|
$this->assertTrue($res); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
function testIsSettingsSet() |
138
|
|
|
{ |
139
|
|
|
$year = new Year($this->kernel); |
140
|
|
|
$this->assertFalse($year->isSettingsSet()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
function testGetSettings() |
144
|
|
|
{ |
145
|
|
|
$year = new Year($this->kernel); |
146
|
|
|
$this->assertTrue(is_array($year->getSettings())); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
function testSetSettings() |
150
|
|
|
{ |
151
|
|
|
$year = new Year($this->kernel); |
152
|
|
|
$data = array(); |
153
|
|
|
$this->assertTrue($year->setSettings($data)); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
function testReadyForState() |
157
|
|
|
{ |
158
|
|
|
$year = new Year($this->kernel); |
159
|
|
|
$data = array(); |
|
|
|
|
160
|
|
|
$this->assertFalse($year->readyForState()); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
function testIsYearOpen() |
164
|
|
|
{ |
165
|
|
|
$year = new Year($this->kernel); |
166
|
|
|
$year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
167
|
|
|
$this->assertTrue($year->isYearOpen()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
function testIsDateInYear() |
171
|
|
|
{ |
172
|
|
|
$year = new Year($this->kernel); |
173
|
|
|
$year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
174
|
|
|
$this->assertFalse($year->isDateinYear(date('Y-m-d'))); |
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
function testVatAccountIsSetReturnsTrueWhenVatOnYearIsNotSet() |
178
|
|
|
{ |
179
|
|
|
$year = new Year($this->kernel); |
180
|
|
|
$year->save(array('label' => '2000', 'locked' => 0, 'from_date' => '2000-1-1', 'to_date' => '2000-12-31', 'last_year_id' => 0)); |
181
|
|
|
$this->assertTrue($year->vatAccountIsSet()); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: