From d4d55bf6f84ace323660244dd6b3fa8253e52288 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 25 Mar 2019 13:55:43 -0400 Subject: [PATCH] Bug 18344: Add unit tests Signed-off-by: Katrin Fischer --- t/db_dependent/Circulation/CalcFine.t | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t index 24cf5800b7..f9104fe491 100644 --- a/t/db_dependent/Circulation/CalcFine.t +++ b/t/db_dependent/Circulation/CalcFine.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use C4::Context; use C4::Overdues; @@ -169,6 +169,50 @@ subtest 'Test cap_fine_to_replacement_price' => sub { teardown(); }; +subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1'); + my $issuingrule = $builder->build_object( + { + class => 'Koha::IssuingRules', + value => { + branchcode => '*', + categorycode => '*', + itemtype => '*', + fine => '1.00', + lengthunit => 'days', + finedays => 0, + firstremind => 0, + chargeperiod => 1, + overduefinescap => 3, + cap_fine_to_replacement_price => 1, + }, + } + ); + + my $start_dt = DateTime->new( + year => 2000, + month => 1, + day => 1, + ); + + my $end_dt = DateTime->new( + year => 2000, + month => 1, + day => 30, + ); + + my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); + is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' ); + + $issuingrule->overduefinescap(6)->store(); + ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); + is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' ); + + teardown(); +}; + sub teardown { $dbh->do(q|DELETE FROM issuingrules|); } -- 2.11.0