1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/modules/accounting/Voucher.php'; |
3
|
|
|
require_once 'Intraface/modules/accounting/VoucherFile.php'; |
4
|
|
|
|
5
|
|
View Code Duplication |
class FakeVoucherYear |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
public $kernel; |
8
|
|
|
function __construct() |
9
|
|
|
{ |
10
|
|
|
$this->kernel = new Stub_Kernel; |
11
|
|
|
$this->kernel->setting->set('intranet', 'vatpercent', 25); |
12
|
|
|
} |
13
|
|
|
function get() |
14
|
|
|
{ |
15
|
|
|
return 1; |
16
|
|
|
} |
17
|
|
|
function vatAccountIsSet() |
18
|
|
|
{ |
19
|
|
|
return true; |
20
|
|
|
} |
21
|
|
|
function getSetting() |
22
|
|
|
{ |
23
|
|
|
return 1; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
class VoucherTest extends PHPUnit_Framework_TestCase |
28
|
|
|
{ |
29
|
|
|
private $year; |
30
|
|
|
|
31
|
|
|
function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->year = new FakeVoucherYear; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function testVoucherCreate() |
37
|
|
|
{ |
38
|
|
|
// TODO needs to be updated |
39
|
|
|
$voucher = new Voucher($this->year); |
40
|
|
|
$this->assertFalse($voucher->get('id') > 0); |
41
|
|
|
$voucher->save(array('text' => 'Description', 'date' => '2002-10-10')); |
42
|
|
|
$new_voucher = new Voucher($this->year, $voucher->get('id')); |
43
|
|
|
$new_voucher->save(array('text' => 'Description - edited', 'date' => '2002-10-10')); |
44
|
|
|
$this->assertTrue($voucher->get('id') == $new_voucher->get('id')); |
45
|
|
|
$this->assertTrue($new_voucher->get('text') == 'Description - edited'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function testVatCalculation() |
49
|
|
|
{ |
50
|
|
|
$this->assertTrue((80 + Voucher::calculateVat(100, 25)) == 100); |
|
|
|
|
51
|
|
|
$this->assertTrue((100 + Voucher::calculateVat(110, 10)) == 110); |
|
|
|
|
52
|
|
|
$this->assertTrue(round((93.40 + Voucher::calculateVat(100.41, 7.5)), 2) == 100.41); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function testDeleteReturnsTrue() |
56
|
|
|
{ |
57
|
|
|
$voucher = new Voucher($this->year); |
58
|
|
|
$voucher->save(array('text' => 'Description', 'date' => '2002-10-10')); |
59
|
|
|
$this->assertTrue($voucher->delete()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function testStateDraftReturnsFalseWhenNoPostsAreFound() |
63
|
|
|
{ |
64
|
|
|
$voucher = new Voucher($this->year); |
65
|
|
|
$voucher->save(array('text' => 'Description', 'date' => '2002-10-10')); |
66
|
|
|
$res = $voucher->stateDraft(); |
67
|
|
|
$this->assertFalse($res); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
function testStateVoucherReturnsTrueWhenNoPostsAreFound() |
71
|
|
|
{ |
72
|
|
|
$voucher = new Voucher($this->year); |
73
|
|
|
$voucher->save(array('text' => 'Description', 'date' => '2002-10-10')); |
74
|
|
|
$this->assertTrue($voucher->stateVoucher()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function testGetList() |
78
|
|
|
{ |
79
|
|
|
$voucher = new Voucher($this->year); |
80
|
|
|
$this->assertTrue(is_array($voucher->getList())); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.