From f33879aa85a00b3f32817b10abf22503900c9041 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 9 May 2019 12:32:38 +0000 Subject: [PATCH] Bug 22877: Unit test to highlight problem Signed-off-by: Martin Renvoize Signed-off-by: Liz Rea --- t/db_dependent/Circulation.t | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 0c12efb34e..6269ea9b69 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -1980,7 +1980,7 @@ subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { subtest 'AddReturn | is_overdue' => sub { - plan tests => 5; + plan tests => 7; t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1); t::lib::Mocks::mock_preference('finesMode', 'production'); @@ -1992,6 +1992,17 @@ subtest 'AddReturn | is_overdue' => sub { t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode }); my $biblioitem = $builder->build( { source => 'Biblioitem' } ); + my $item_type = $builder->build_object( + { class => 'Koha::ItemTypes', + value => { + notforloan => undef, + rentalcharge => 0, + defaultreplacecost => undef, + processfee => 0, + rentalcharge_daily => 0, + } + } + ); my $item = $builder->build( { source => 'Item', @@ -2002,6 +2013,8 @@ subtest 'AddReturn | is_overdue' => sub { itemlost => 0, withdrawn => 0, biblionumber => $biblioitem->{biblionumber}, + replacementprice => 7, + itype => $item_type->itemtype } } ); @@ -2020,6 +2033,7 @@ subtest 'AddReturn | is_overdue' => sub { ); $rule->store(); + my $now = dt_from_string; my $one_day_ago = dt_from_string->subtract( days => 1 ); my $five_days_ago = dt_from_string->subtract( days => 5 ); my $ten_days_ago = dt_from_string->subtract( days => 10 ); @@ -2054,6 +2068,20 @@ subtest 'AddReturn | is_overdue' => sub { AddReturn( $item->{barcode}, $library->{branchcode}, $five_days_ago ); is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the OVERDUE fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; + + # Checkout an item 10 days ago + my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago + # Fake fines cronjob on this checkout + my ( $fine ) = CalcFine( $item , $patron->categorycode, $library->{branchcode}, $ten_days_ago, $now ); + UpdateFine({ issue_id => $issue->issue_id, itemnumber => $item->{itemnumber}, borrowernumber => $patron->borrowernumber, amount => $fine, due => output_pref($ten_days_ago) }); + is( int($patron->account->balance()),10, "Overdue fine of 10 days overdue"); + # Fake longoverdue with charge and not marking returned + LostItem( $item->{itemnumber}, 'cronjob',0 ); + is( int($patron->account->balance()),17, "Lost fine of 7 plus 10 days overdue"); + # Now we return it today + AddReturn( $item->{barcode}, $library->{branchcode} ); + is( int($patron->account->balance()),17, "Should have a single 10 days overdue fine and lost charge"); + }; subtest '_FixAccountForLostAndReturned' => sub { -- 2.11.0