From 39ef054feb5852cbc744abb9bac3935fff8debe9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 16 Oct 2019 11:44:11 +0100 Subject: [PATCH] Bug 23382: (follow-up) Further improve test coverage --- t/db_dependent/Circulation.t | 48 +++++++++++++++++++++++------- t/db_dependent/Koha/Charges/Fees.t | 21 +++++++++---- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 33cef21eb3..0c184807a8 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -3074,7 +3074,7 @@ subtest 'ProcessOfflinePayment() tests' => sub { }; subtest 'Incremented fee tests' => sub { - plan tests => 16; + plan tests => 20; my $dt = dt_from_string(); Time::Fake->offset( $dt->epoch ); @@ -3207,24 +3207,52 @@ subtest 'Incremented fee tests' => sub { is( $issuingrule->lengthunit, 'hours', 'Issuingrule updated and retrieved correctly' ); - $itemtype->rentalcharge_hourly('2.500000')->store(); + $itemtype->rentalcharge_hourly('0.25')->store(); is( $itemtype->rentalcharge_hourly, - '2.500000', 'Hourly rental charge stored and retreived correctly' ); + '0.25', 'Hourly rental charge stored and retreived correctly' ); - $dt_to = dt_from_string()->add( hours => 4 ); - $dt_to_renew = dt_from_string()->add( hours => 6 ); - $calendar->delete_holiday( weekday => 3); + $dt_to = dt_from_string()->add( hours => 168 ); + $dt_to_renew = dt_from_string()->add( hours => 312 ); + t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); - is( $accountline->amount, '10.000000', - "Hourly rental charge calculated correctly" ); + is( $accountline->amount + 0, 42, + "Hourly rental charge calculated correctly with finesCalendar = ignoreCalendar (168h * 0.25u)" ); $accountline->delete(); AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to ); $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); - is( $accountline->amount, '5.000000', - "Hourly rental charge calculated correctly, for renewal" ); + is( $accountline->amount + 0, 36, + "Hourly rental charge calculated correctly with finesCalendar = ignoreCalendar, for renewal (312h - 168h * 0.25u)" ); + $accountline->delete(); + $issue->delete(); + + t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' ); + $issue = + AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); + $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); + is( $accountline->amount + 0, 36, + "Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays (168h - 24h * 0.25u)" ); + $accountline->delete(); + AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to ); + $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); + is( $accountline->amount + 0, 30, + "Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal (312h - 168h - 24h * 0.25u" ); + $accountline->delete(); + $issue->delete(); + + $calendar->delete_holiday( weekday => 3 ); + $issue = + AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); + $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); + is( $accountline->amount + 0, 42, + "Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed (168h - 0h * 0.25u" ); + $accountline->delete(); + AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to ); + $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); + is( $accountline->amount + 0, 36, + "Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed, for renewal (312h - 168h - 0h * 0.25u)" ); $accountline->delete(); $issue->delete(); $issuingrule->lengthunit('days')->store(); diff --git a/t/db_dependent/Koha/Charges/Fees.t b/t/db_dependent/Koha/Charges/Fees.t index db7e219538..65b7b23cac 100644 --- a/t/db_dependent/Koha/Charges/Fees.t +++ b/t/db_dependent/Koha/Charges/Fees.t @@ -307,7 +307,7 @@ subtest 'from_date accessor' => sub { }; subtest 'accumulate_rentalcharge tests' => sub { - plan tests => 5; + plan tests => 7; my $fees = Koha::Charges::Fees->new( { @@ -358,10 +358,10 @@ subtest 'accumulate_rentalcharge tests' => sub { ); $issuingrule->lengthunit('hours'); $issuingrule->store(); - $itemtype->rentalcharge_hourly("2.50"); + $itemtype->rentalcharge_hourly("0.25"); $itemtype->store(); - $dt_from = dt_from_string(); - $dt_to = dt_from_string()->add( hours => 4 ); + + $dt_to = $dt_from->clone->add( hours => 96 ); $fees = Koha::Charges::Fees->new( { patron => $patron, @@ -372,8 +372,19 @@ subtest 'accumulate_rentalcharge tests' => sub { } ); + t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); + $charge = $fees->accumulate_rentalcharge(); + is( $charge, 24.00, 'Hourly rental charge calculated correctly (96h * 0.25u)' ); + + t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' ); + $charge = $fees->accumulate_rentalcharge(); + is( $charge, 18.00, +'Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays (96h - 24h * 0.25u)' + ); + + $calendar->delete_holiday( weekday => 3); $charge = $fees->accumulate_rentalcharge(); - is( $charge, 10.00, 'Hourly rental charge calculated correctly' ); + is( $charge, 24.00, 'Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed (96h - 0h * 0.25u)' ); }; $schema->storage->txn_rollback; -- 2.20.1