From 5c5862e5d8be08ea662f5bbb274abf0dee73776c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 15 Jun 2023 15:32:58 +0000 Subject: [PATCH] Bug 33887: Unit tests prove -v t/db_dependent/Koha/Checkouts.t --- t/db_dependent/Koha/Checkouts.t | 51 ++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t index 4373904142..c3801d532e 100755 --- a/t/db_dependent/Koha/Checkouts.t +++ b/t/db_dependent/Koha/Checkouts.t @@ -22,9 +22,11 @@ use Modern::Perl; use Test::More tests => 11; use C4::Circulation qw( MarkIssueReturned AddReturn ); +use C4::Reserves qw( AddReserve ); use Koha::Checkouts; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); +use Koha::Holds; use t::lib::TestBuilder; use t::lib::Mocks; @@ -296,7 +298,7 @@ $schema->storage->txn_rollback; subtest 'automatic_checkin' => sub { - plan tests => 9; + plan tests => 10; $schema->storage->txn_begin; @@ -405,5 +407,52 @@ subtest 'automatic_checkin' => sub { $searched = Koha::Old::Checkouts->find( $checkout_odue_aci->issue_id ); is( dt_from_string($searched->returndate), $yesterday, 'old checkout for odue_ac_item has the right return date' ); + + subtest 'automatic_checkin AutomaticCheckinAutoFill tests' => sub { + + plan tests => 2; + + my $checkout_2_ac = Koha::Checkout->new( + { + borrowernumber => $patron->borrowernumber, + itemnumber => $due_ac_item->itemnumber, + branchcode => $patron->branchcode, + date_due => $today + } + )->store; + + my $patron_2 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $patron->branchcode} } ); + my $reserveid = AddReserve( + { + branchcode => $patron->branchcode, + borrowernumber => $patron_2->id, + biblionumber => $due_ac_item->biblionumber, + priority => 1 + } + ); + + t::lib::Mocks::mock_preference('AutomaticCheckinAutoFill', '0'); + + Koha::Checkouts->automatic_checkin; + my $reserve = Koha::Holds->find( $reserveid ); + + is( $reserve->found, undef, "Hold was not filled when AutomaticCheckinAutoFill disabled"); + + my $checkout_3_ac = Koha::Checkout->new( + { + borrowernumber => $patron->borrowernumber, + itemnumber => $due_ac_item->itemnumber, + branchcode => $patron->branchcode, + date_due => $today + } + )->store; + t::lib::Mocks::mock_preference('AutomaticCheckinAutoFill', '1'); + + Koha::Checkouts->automatic_checkin; + $reserve->discard_changes; + + is( $reserve->found, 'W', "Hold was filled when AutomaticCheckinAutoFill enabled"); + }; + $schema->storage->txn_rollback; } -- 2.30.2