Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[koha.git] / t / db_dependent / Fines.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use C4::Context;
6 use C4::Overdues qw( CalcFine );
7 use Koha::Database;
8 use Koha::DateUtils qw( dt_from_string );
9
10 use Test::More tests => 5;
11
12 my $schema = Koha::Database->new->schema;
13 $schema->storage->txn_begin;
14 my $dbh = C4::Context->dbh;
15
16 $dbh->do(q|DELETE FROM circulation_rules|);
17
18 my $issuingrule = Koha::CirculationRules->set_rules(
19     {
20         categorycode => undef,
21         itemtype     => undef,
22         branchcode   => undef,
23         rules        => {
24             fine                   => 1,
25             finedays               => 0,
26             chargeperiod           => 7,
27             chargeperiod_charge_at => 0,
28             lengthunit             => 'days',
29             issuelength            => 1,
30         }
31     }
32 );
33
34 ok( $issuingrule, 'Issuing rule created' );
35
36 my $period_start = dt_from_string('2000-01-01');
37 my $period_end = dt_from_string('2000-01-05');
38
39 my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
40 is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
41
42 $period_end = dt_from_string('2000-01-10');
43 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
44 is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
45
46 # Test charging fine at the *beginning* of each charge period
47 $issuingrule = Koha::CirculationRules->set_rules(
48     {
49         categorycode => undef,
50         itemtype     => undef,
51         branchcode   => undef,
52         rules        => {
53             chargeperiod_charge_at => 1,
54         }
55     }
56 );
57
58 $period_end = dt_from_string('2000-01-05');
59 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
60 is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
61
62 $period_end = dt_from_string('2000-01-10');
63 ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
64 is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );