From d939aad6505dd4e18bdf2c31ff8f054b32e0a989 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 13 May 2020 15:18:29 +0200 Subject: [PATCH] Bug 24413: Add tests Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Katrin Fischer --- t/db_dependent/Circulation/MarkIssueReturned.t | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation/MarkIssueReturned.t b/t/db_dependent/Circulation/MarkIssueReturned.t index 26c8a06291..af455e1349 100644 --- a/t/db_dependent/Circulation/MarkIssueReturned.t +++ b/t/db_dependent/Circulation/MarkIssueReturned.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Test::Exception; use t::lib::Mocks; @@ -27,8 +27,10 @@ use C4::Circulation; use C4::Context; use Koha::Checkouts; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); use Koha::Old::Checkouts; use Koha::Patrons; +use Koha::Patron::Debarments; my $schema = Koha::Database->schema; my $builder = t::lib::TestBuilder->new; @@ -188,3 +190,37 @@ subtest 'Manually pass a return date' => sub { $schema->storage->txn_rollback; }; + +subtest 'AutoRemoveOverduesRestrictions' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 1); + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); + my $item_1 = $builder->build_sample_item; + my $item_2 = $builder->build_sample_item; + my $item_3 = $builder->build_sample_item; + my $five_days_ago = dt_from_string->subtract( days => 5 ); + my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue + my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue + my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue + + Koha::Patron::Debarments::AddUniqueDebarment( + { + borrowernumber => $patron->borrowernumber, + type => 'OVERDUES', + comment => "OVERDUES_PROCESS simulation", + } + ); + + C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber ); + + my $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber }); + is( $debarments->[0]->{type}, 'OVERDUES', 'OVERDUES debarment is not removed if patron still has overdues' ); + + C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); + + $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber }); + is( scalar @$debarments, 0, 'OVERDUES debarment is removed if patron does not have overdues' ); +}; -- 2.11.0