1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/modules/accounting/Post.php'; |
3
|
|
|
|
4
|
|
|
class FakePostVoucher |
5
|
|
|
{ |
6
|
|
|
public $year; |
7
|
|
|
function __construct() |
8
|
|
|
{ |
9
|
|
|
$this->year = new FakePostYear; |
10
|
|
|
} |
11
|
|
|
function get() |
12
|
|
|
{ |
13
|
|
|
return 1; |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
|
17
|
|
View Code Duplication |
class FakePostYear |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
public $kernel; |
20
|
|
|
function __construct() |
21
|
|
|
{ |
22
|
|
|
$this->kernel = new Stub_Kernel; |
23
|
|
|
$this->kernel->setting->set('intranet', 'vatpercent', 25); |
24
|
|
|
} |
25
|
|
|
function get() |
26
|
|
|
{ |
27
|
|
|
return 1; |
28
|
|
|
} |
29
|
|
|
function vatAccountIsSet() |
30
|
|
|
{ |
31
|
|
|
return true; |
32
|
|
|
} |
33
|
|
|
function getSetting() |
34
|
|
|
{ |
35
|
|
|
return 1; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
class PostTest extends PHPUnit_Framework_TestCase |
40
|
|
|
{ |
41
|
|
|
private $voucher; |
42
|
|
|
|
43
|
|
|
function setUp() |
44
|
|
|
{ |
45
|
|
|
$this->voucher = new FakePostVoucher; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function tearDown() |
49
|
|
|
{ |
50
|
|
|
$db = MDB2::singleton(DB_DSN); |
51
|
|
|
$db->query('TRUNCATE accounting_post'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function testPostCreate() |
55
|
|
|
{ |
56
|
|
|
// TODO needs to be updated |
57
|
|
|
$post = new Post($this->voucher); |
58
|
|
|
$this->assertTrue(is_object($post)); |
59
|
|
|
$this->assertFalse($post->getId() > 0); |
60
|
|
|
$date = date('Y-m-d'); |
61
|
|
|
$account_id = 1; |
62
|
|
|
$text = 'test'; |
63
|
|
|
$debet = 1; |
64
|
|
|
$credit = 1; |
65
|
|
|
$skip_draft = false; |
66
|
|
|
$res = $post->save($date, $account_id, $text, $debet, $credit, $skip_draft); |
67
|
|
|
$this->assertTrue($res); |
68
|
|
|
|
69
|
|
|
/* |
|
|
|
|
70
|
|
|
$voucher->save(array('text' => 'Description', 'date' => '2002-10-10')); |
71
|
|
|
$new_voucher = new Voucher($this->year, $voucher->get('id')); |
72
|
|
|
$new_voucher->save(array('text' => 'Description - edited', 'date' => '2002-10-10')); |
73
|
|
|
$this->assertTrue($voucher->get('id') == $new_voucher->get('id')); |
74
|
|
|
$this->assertTrue($new_voucher->get('text') == 'Description - edited'); |
75
|
|
|
*/ |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
function testFactory() |
79
|
|
|
{ |
80
|
|
|
$post = new Post($this->voucher); |
81
|
|
|
$this->assertTrue(is_object($post->factory($this->voucher->year, 1))); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function testDelete() |
85
|
|
|
{ |
86
|
|
|
$post = new Post($this->voucher); |
87
|
|
|
$this->assertTrue(is_object($post)); |
88
|
|
|
$this->assertFalse($post->getId() > 0); |
89
|
|
|
$date = date('Y-m-d'); |
90
|
|
|
$account_id = 1; |
91
|
|
|
$text = 'test'; |
92
|
|
|
$debet = 1; |
93
|
|
|
$credit = 1; |
94
|
|
|
$skip_draft = true; |
95
|
|
|
$res = $post->save($date, $account_id, $text, $debet, $credit, $skip_draft); |
96
|
|
|
$this->assertTrue($res); |
97
|
|
|
$post->delete(); |
98
|
|
|
$this->assertEquals(0, count($post->getList())); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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.