View | Details | Raw Unified | Return to bug 9129
Collapse All | Expand All

(-)a/t/db_dependent/Circulation/CalcFine.t (-1 / +146 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
7
use C4::Context;
8
use C4::Overdues;
9
10
use Koha::DateUtils qw( dt_from_string );
11
12
use t::lib::TestBuilder;
13
use t::lib::Mocks;
14
15
our $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
$dbh->{RaiseError} = 1;
18
19
$dbh->do(q|DELETE FROM issues|);
20
21
my $builder = t::lib::TestBuilder->new();
22
23
my $branch = $builder->build(
24
    {
25
        source => 'Branch',
26
    }
27
);
28
29
my $category = $builder->build(
30
    {
31
        source => 'Category',
32
    }
33
);
34
35
my $patron = $builder->build(
36
    {
37
        source => 'Borrower',
38
        value  => {
39
            categorycode => $category->{categorycode},
40
            branchcode   => $branch->{branchcode},
41
        },
42
    }
43
);
44
45
my $biblio = $builder->build(
46
    {
47
        source => 'Biblio',
48
        value  => {
49
            branchcode => $branch->{branchcode},
50
        },
51
    }
52
);
53
54
my $item = $builder->build(
55
    {
56
        source => 'Item',
57
        value  => {
58
            biblionumber     => $biblio->{biblionumber},
59
            homebranch       => $branch->{branchcode},
60
            holdingbranch    => $branch->{branchcode},
61
            replacementprice => '5.00',
62
        },
63
    }
64
);
65
66
subtest 'Test basic functionality' => sub {
67
    plan tests => 1;
68
    my $issuingrule = $builder->build(
69
        {
70
            source => 'Issuingrule',
71
            value  => {
72
                branchcode                    => '*',
73
                categorycode                  => '*',
74
                itemtype                      => '*',
75
                fine                          => '1.00',
76
                lengthunit                    => 'days',
77
                finedays                      => 0,
78
                firstremind                   => 0,
79
                chargeperiod                  => 1,
80
                overduefinescap               => undef,
81
                cap_fine_to_replacement_price => 0,
82
            },
83
        }
84
    );
85
86
    my $start_dt = DateTime->new(
87
        year       => 2000,
88
        month      => 01,
89
        day        => 01,
90
    );
91
92
    my $end_dt = DateTime->new(
93
        year       => 2000,
94
        month      => 01,
95
        day        => 30,
96
    );
97
98
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
99
100
    is( $amount, 29, 'Amount is calculated correctly' );
101
102
    teardown();
103
};
104
105
subtest 'Test cap_fine_to_replacement_price' => sub {
106
    plan tests => 1;
107
    my $issuingrule = $builder->build(
108
        {
109
            source => 'Issuingrule',
110
            value  => {
111
                branchcode                    => '*',
112
                categorycode                  => '*',
113
                itemtype                      => '*',
114
                fine                          => '1.00',
115
                lengthunit                    => 'days',
116
                finedays                      => 0,
117
                firstremind                   => 0,
118
                chargeperiod                  => 1,
119
                overduefinescap               => undef,
120
                cap_fine_to_replacement_price => 1,
121
            },
122
        }
123
    );
124
125
    my $start_dt = DateTime->new(
126
        year       => 2000,
127
        month      => 01,
128
        day        => 01,
129
    );
130
131
    my $end_dt = DateTime->new(
132
        year       => 2000,
133
        month      => 01,
134
        day        => 30,
135
    );
136
137
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
138
139
    is( $amount, '5.00', 'Amount is calculated correctly' );
140
141
    teardown();
142
};
143
144
sub teardown {
145
    $dbh->do(q|DELETE FROM issuingrules|);
146
}

Return to bug 9129