From d7fe723baf69dc5056d9aeb44793737f1d8c7972 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Sun, 12 Jul 2020 23:58:30 -0400 Subject: [PATCH] Bug 14784: Add tests This patch adds tests for PrevDebarred message of AddReturn when finesdays = 0. To test: 1. Apply patches 2. prove -v t/db_dependent/Circulation.t When applying only this patch, one test should fail. Signed-off-by: Arthur Suzuki --- C4/Circulation.pm | 2 +- t/db_dependent/Circulation.t | 65 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3571051e84..60a99be991 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2343,7 +2343,7 @@ sub _calculate_new_debar_dt { if ( C4::Context->preference('CumulativeRestrictionPeriods') and $borrower->{debarred} ) { my $debarment = @{ GetDebarments( { borrowernumber => $borrower->{borrowernumber}, type => 'SUSPENSION' } ) }[0]; if ( $debarment ) { - $return_date = dt_from_string( $debarment->{expiration}, 'sql' ); + $return_date = dt_from_string( $debarment->{return_date}, 'sql' ); $has_been_extended = 1; } } diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index f26f2f3255..ccb666fcb9 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -2088,7 +2088,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { is( scalar(@$debarments), 1 ); $expected_expiration = output_pref( { - dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), + dt => $now->clone->add( days => ( 10 - 1 ) * 2 ), dateformat => 'sql', dateonly => 1 } @@ -2097,7 +2097,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { }; subtest 'AddReturn + suspension_chargeperiod' => sub { - plan tests => 24; + plan tests => 26; my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); @@ -2136,6 +2136,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { # We want to charge 2 days every day, without grace # With 5 days of overdue: 5 * Z my $expected_expiration = $now->clone->add( days => ( 5 * 2 ) / 1 ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $expected_expiration } ); test_debarment_on_checkout( { item => $item_1, @@ -2159,6 +2163,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { ); $expected_expiration = $now->clone->add( days => floor( 5 * 2 ) / 2 ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $expected_expiration } ); test_debarment_on_checkout( { item => $item_1, @@ -2183,6 +2191,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { } ); $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $expected_expiration } ); test_debarment_on_checkout( { item => $item_1, @@ -2222,6 +2234,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { ); # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $expected_expiration } ); test_debarment_on_checkout( { item => $item_1, @@ -2244,6 +2260,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { # Same as above, but we should skip D+2 $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $expected_expiration } ); test_debarment_on_checkout( { item => $item_1, @@ -2264,6 +2284,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { description => 'holidayDesc on expiration date' ); # Expiration date will be the day after + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $expected_expiration->clone->add( days => 1 ) } ); test_debarment_on_checkout( { item => $item_1, @@ -2274,6 +2298,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { } ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $now->clone->add(days => 5 + (5 * 2 - 1) ) } ); test_debarment_on_checkout( { item => $item_1, @@ -2284,6 +2312,10 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { } ); + Koha::Patron::Debarments::AddUniqueDebarment( { + borrowernumber => $patron->{borrowernumber}, + type => 'SUSPENSION', + expiration => $now->clone->add(days => 5 + (4 * 2 - 1) ) } ); test_debarment_on_checkout( { item => $item_1, @@ -2295,6 +2327,35 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { } ); + # Debarred message when finesdays = 0 + + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + itemtype => undef, + rules => { + finedays => 0, + suspension_chargeperiod => 1, + } + } + ); + + Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->{borrowernumber}, type => 'MANUAL', expiration => $now->clone->add(days => 10) } ); + + AddIssue( $patron, $item_1->barcode, $now->clone->add(days => 1) ); + + my ( undef, $message ) = AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now->clone->subtract(days => 1) ); + is( $message->{WasReturned} && exists $message->{PrevDebarred}, 1, 'Previously debarred message for AddReturn when not overdue' ); + + AddIssue( $patron, $item_1->barcode, $now->clone->add(days => 1) ); + + ( undef, $message ) = AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now->clone->add(days => 5) ); + is( $message->{WasReturned} && exists $message->{PrevDebarred}, 1, 'Previously debarred message for AddReturn when overdue' ); + + Koha::Patron::Debarments::DelUniqueDebarment( + { borrowernumber => $patron->{borrowernumber}, type => 'MANUAL' } ); + }; subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { -- 2.11.0