From 36ff6d223797b4577f784b6ab284795d5f78f030 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 21 Jul 2025 16:02:49 +0200 Subject: [PATCH] Bug 37651: (follow-up) Add GetAvailability test case for future hold Test plan: Run t/db_dependent/ILSDI_Services.t Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens --- t/db_dependent/ILSDI_Services.t | 47 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index e439df02baa..0a75e7dd748 100755 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -20,7 +20,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use Test::NoWarnings; -use Test::More tests => 15; +use Test::More tests => 16; use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; @@ -1147,6 +1147,51 @@ subtest 'GetAvailability itemcallnumber' => sub { $schema->storage->txn_rollback; }; +subtest 'GetAvailability availabilitystatus' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + my $item = $builder->build_sample_item; + + my ( $cgi, $reply, $xml, $status, $message ); + $cgi = CGI->new; + $cgi->param( service => 'GetAvailability' ); + $cgi->param( id => $item->biblionumber ); + $cgi->param( id_type => 'biblio' ); + $reply = C4::ILSDI::Services::GetAvailability($cgi); + $xml = XML::LibXML->load_xml( string => $reply ); + $status = $xml->findnodes('//dlf:availabilitystatus')->to_literal(); + is( $status, 'available', 'GetAvailability returns available' ); + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + $patron->branchcode( $item->holdingbranch )->store; + AddReserve( + { + reservation_date => dt_from_string()->add( days => 1 ), + branchcode => $item->holdingbranch, + borrowernumber => $patron->id, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + } + ); + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 0 ); + $reply = C4::ILSDI::Services::GetAvailability($cgi); + $xml = XML::LibXML->load_xml( string => $reply ); + $status = $xml->findnodes('//dlf:availabilitystatus')->to_literal(); + is( $status, 'available', 'GetAvailability returns available, ignoring future hold' ); + + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 2 ); + $reply = C4::ILSDI::Services::GetAvailability($cgi); + $xml = XML::LibXML->load_xml( string => $reply ); + $status = $xml->findnodes('//dlf:availabilitystatus')->to_literal(); + $message = $xml->findnodes('//dlf:availabilitymsg')->to_literal(); + is( $status, 'not available', 'GetAvailability returns not available status for future hold' ); + is( $message, 'On hold', 'GetAvailability returns on hold message for future hold' ); + + t::lib::Mocks::mock_preference( 'ConfirmFutureHolds', 0 ); + $schema->storage->txn_rollback; +}; + subtest 'Bug 34893: ILS-DI can return the wrong patron for AuthenticatePatron' => sub { plan tests => 2; -- 2.39.5