From 0f2d99debc95c9b83489ab406af5182c7ccc6ed1 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 19 Aug 2024 13:09:40 +0000 Subject: [PATCH] Bug 37651: Unit tests Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Holds.t (Without previous patches, it would fail.) Run t/db_dependent/Koha/Biblios.t --- t/db_dependent/Holds.t | 25 ++++++++++++++++++++++++- t/db_dependent/Koha/Biblios.t | 10 +++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 4c78b4c480..b2bdf4c8af 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 74; +use Test::More tests => 75; use Test::Exception; use MARC::Record; @@ -1887,3 +1887,26 @@ subtest 'EmailPatronWhenHoldIsPlaced tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'current_holds with future holds' => sub { + plan tests => 2; + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 2 ); + my $item = $builder->build_sample_item; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $hold_id = AddReserve( + { + reservation_date => dt_from_string()->add( days => 1 ), + branchcode => $item->homebranch, + borrowernumber => $patron->id, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + } + ); + is( $item->biblio->current_holds->count, 1, 'Future hold was counted' ); + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 0 ); + is( $item->biblio->current_holds->count, 0, 'No future hold was counted when ConfirmFutureHolds is zero' ); + + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index fde249ffe5..624e5b7328 100755 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -67,7 +67,7 @@ subtest 'store' => sub { }; subtest 'holds + current_holds' => sub { - plan tests => 5; + plan tests => 6; C4::Reserves::AddReserve( { branchcode => $patron->branchcode, @@ -90,12 +90,16 @@ subtest 'holds + current_holds' => sub { reservation_date => dt_from_string->add( days => 2 ), } ); + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 0 ); $holds = $biblio->holds; is( $holds->count, 1, '->holds should return future holds' ); $holds = $biblio->current_holds; - is( $holds->count, 0, '->current_holds should not return future holds' ); + is( $holds->count, 0, '->current_holds without lookahead should not return future holds' ); + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 2 ); + $holds = $biblio->current_holds; + is( $holds->count, 1, '->current_holds with lookahead returns future holds' ); $holds->delete; - + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 0 ); }; subtest 'waiting_or_in_transit' => sub { -- 2.30.2