Lines 18-24
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 8; |
21 |
use Test::More tests => 18; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
Lines 44-50
can_ok( 'C4::Accounts',
Link Here
|
44 |
ReversePayment |
44 |
ReversePayment |
45 |
recordpayment_selectaccts |
45 |
recordpayment_selectaccts |
46 |
makepartialpayment |
46 |
makepartialpayment |
47 |
WriteOffFee ) |
47 |
WriteOffFee |
|
|
48 |
purge_zero_balance_fees ) |
48 |
); |
49 |
); |
49 |
|
50 |
|
50 |
my $builder = t::lib::TestBuilder->new(); |
51 |
my $builder = t::lib::TestBuilder->new(); |
Lines 69-74
$context->mock( 'userenv', sub {
Link Here
|
69 |
}; |
70 |
}; |
70 |
}); |
71 |
}); |
71 |
|
72 |
|
|
|
73 |
# Testing purge_zero_balance_fees |
74 |
|
75 |
# The 3rd value in the insert is 'days ago' -- |
76 |
# 0 => today |
77 |
# 1 => yesterday |
78 |
# etc. |
79 |
|
80 |
$sth = $dbh->prepare( |
81 |
"INSERT INTO accountlines ( |
82 |
borrowernumber, |
83 |
amountoutstanding, |
84 |
date, |
85 |
description |
86 |
) |
87 |
VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ? )" |
88 |
); |
89 |
|
90 |
my $days = 5; |
91 |
|
92 |
my @test_data = ( |
93 |
{ amount => 0 , days_ago => 0 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today' , delete => 0 } , |
94 |
{ amount => 0 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day' , delete => 0 } , |
95 |
{ amount => 0 , days_ago => $days , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day' , delete => 0 } , |
96 |
{ amount => 0 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day' , delete => 1 } , |
97 |
{ amount => 5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day' , delete => 0 } , |
98 |
{ amount => 5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day' , delete => 0 } , |
99 |
{ amount => 5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day' , delete => 0 } , |
100 |
{ amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } , |
101 |
{ amount => -5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day' , delete => 0 } , |
102 |
{ amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day' , delete => 0 } |
103 |
); |
104 |
|
105 |
for my $data ( @test_data ) { |
106 |
$sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}); |
107 |
} |
108 |
|
109 |
purge_zero_balance_fees( $days ); |
110 |
|
111 |
$sth = $dbh->prepare( |
112 |
"select count(*) = 0 as deleted |
113 |
from accountlines |
114 |
where description = ?" |
115 |
); |
116 |
|
117 |
# |
118 |
sub is_delete_correct { |
119 |
my $should_delete = shift; |
120 |
my $description = shift; |
121 |
$sth->execute( $description ); |
122 |
my $test = $sth->fetchrow_hashref(); |
123 |
is( $test->{deleted}, $should_delete, $description ) |
124 |
} |
125 |
|
126 |
for my $data (@test_data) { |
127 |
is_delete_correct( $data->{delete}, $data->{description}); |
128 |
} |
72 |
|
129 |
|
73 |
subtest "recordpayment() tests" => sub { |
130 |
subtest "recordpayment() tests" => sub { |
74 |
|
131 |
|
75 |
- |
|
|