Bug 23382: (follow-up) Further improve test coverage

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 8f3093c9a0)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2019-10-16 11:44:11 +01:00 committed by Lucas Gass
parent 4301f83278
commit f34f979aee
2 changed files with 54 additions and 15 deletions

View File

@ -3071,7 +3071,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 );
@ -3204,24 +3204,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();

View File

@ -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, 10.00, 'Hourly rental charge calculated correctly' );
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, 24.00, 'Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed (96h - 0h * 0.25u)' );
};
$schema->storage->txn_rollback;