From be46b0a57c28c43c956f35ee8d234a12e66751fe 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. --- t/db_dependent/Circulation.t | 67 +++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 51706fcf38..77e278a6f1 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -2103,7 +2103,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { }; subtest 'AddReturn + suspension_chargeperiod' => sub { - plan tests => 27; + plan tests => 29; my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); @@ -2142,6 +2142,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, @@ -2174,6 +2178,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, @@ -2197,6 +2205,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, @@ -2221,6 +2233,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, @@ -2260,6 +2276,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, @@ -2282,6 +2302,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, @@ -2302,6 +2326,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, @@ -2312,6 +2340,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, @@ -2322,6 +2354,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, @@ -2333,6 +2369,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.25.1