5 use Test::More tests => 3;
10 use Koha::DateUtils qw( dt_from_string );
12 use t::lib::TestBuilder;
15 my $schema = Koha::Database->schema;
16 $schema->storage->txn_begin;
18 our $dbh = C4::Context->dbh;
19 $dbh->do(q|DELETE FROM issues|);
21 t::lib::Mocks::mock_preference('item-level_itypes', '1');
23 my $builder = t::lib::TestBuilder->new();
25 my $branch = $builder->build(
31 my $category = $builder->build(
37 my $patron = $builder->build(
41 categorycode => $category->{categorycode},
42 branchcode => $branch->{branchcode},
47 my $biblio = $builder->build(
51 branchcode => $branch->{branchcode},
56 my $itemtype = $builder->build(
60 defaultreplacecost => 6,
65 my $item = $builder->build(
69 biblionumber => $biblio->{biblionumber},
70 homebranch => $branch->{branchcode},
71 holdingbranch => $branch->{branchcode},
72 replacementprice => '5.00',
73 itype => $itemtype->{itemtype},
78 subtest 'Test basic functionality' => sub {
81 Koha::CirculationRules->set_rules(
92 overduefinescap => undef,
93 cap_fine_to_replacement_price => 0,
98 my $start_dt = DateTime->new(
104 my $end_dt = DateTime->new(
110 my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
112 is( $amount, 29, 'Amount is calculated correctly' );
117 subtest 'Test cap_fine_to_replacement_price' => sub {
120 t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
121 Koha::CirculationRules->set_rules(
128 lengthunit => 'days',
132 overduefinescap => undef,
133 cap_fine_to_replacement_price => 1,
138 my $start_dt = DateTime->new(
144 my $end_dt = DateTime->new(
150 my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
152 is( int($amount), 5, 'Amount is calculated correctly' );
155 # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
156 my $item_obj = Koha::Items->find($item->{itemnumber});
157 $item_obj->replacementprice(0)->store;
158 ($amount) = CalcFine( $item_obj->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
159 is( int($amount), 6, 'Amount is calculated correctly' );
164 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub {
167 t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
168 my $issuingrule = $builder->build_object(
170 class => 'Koha::IssuingRules',
176 lengthunit => 'days',
180 overduefinescap => 3,
181 cap_fine_to_replacement_price => 1,
186 my $start_dt = DateTime->new(
192 my $end_dt = DateTime->new(
198 my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
199 is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
201 $issuingrule->overduefinescap(6)->store();
202 ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
203 is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
209 $dbh->do(q|DELETE FROM circulation_rules|);