From 30681a58dc1678ee2ac5a884129a262bbe3349b6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 3 Nov 2023 16:45:22 +0000 Subject: [PATCH] Bug 21284: (QA follow-up) Fix QA script issues Signed-off-by: Kyle M Hall --- C4/ILSDI/Services.pm | 4 +- t/db_dependent/ILSDI_Services.t | 130 +++++++++++++++++++------------- 2 files changed, 78 insertions(+), 56 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 02ee66317eb..f01dd34770e 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -531,10 +531,10 @@ sub GetPatronInfo { delete $issue->{'more_subfields_xml'}; # Is the item already on hold by another user? - $issue->{'holds_on_item'} = Koha::Holds->search({ itemnumber => $issue->{'itemnumber'} })->count; + $issue->{'holds_on_item'} = Koha::Holds->search( { itemnumber => $issue->{'itemnumber'} } )->count; # Is the record (next available item) on hold by another user? - $issue->{'holds_on_record'} = Koha::Holds->search({ biblionumber => $issue->{'biblionumber'} })->count; + $issue->{'holds_on_record'} = Koha::Holds->search( { biblionumber => $issue->{'biblionumber'} } )->count; push @checkouts, $issue } diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 3ed6fc12cf9..7d22071c439 100755 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -127,93 +127,115 @@ subtest 'GetPatronInfo test for holds' => sub { plan tests => 8; $schema->storage->txn_begin; - $schema->resultset( 'Issue' )->delete_all; - $schema->resultset( 'Reserve' )->delete_all; - $schema->resultset( 'Borrower' )->delete_all; - $schema->resultset( 'Category' )->delete_all; - $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this - $schema->resultset( 'Branch' )->delete_all; + $schema->resultset('Issue')->delete_all; + $schema->resultset('Reserve')->delete_all; + $schema->resultset('Borrower')->delete_all; + $schema->resultset('Category')->delete_all; + $schema->resultset('Item')->delete_all; # 'Branch' deps. on this + $schema->resultset('Branch')->delete_all; # Configure Koha to enable ILS-DI server t::lib::Mocks::mock_preference( 'ILS-DI', 1 ); - my $library = $builder->build_object({ - class => 'Koha::Libraries', - }); + my $library = $builder->build_object( + { + class => 'Koha::Libraries', + } + ); # Create new users: - my $brwr = $builder->build_object( { - class => 'Koha::Patrons', - value => { - branchcode => $library->branchcode, + my $brwr = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } } - } ); - my $brwr2 = $builder->build_object( { - class => 'Koha::Patrons', - value => { - branchcode => $library->branchcode, + ); + my $brwr2 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } } - } ); - my $brwr3 = $builder->build_object( { - class => 'Koha::Patrons', - value => { - branchcode => $library->branchcode, + ); + my $brwr3 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } } - } ); + ); my $module = Test::MockModule->new('C4::Context'); - $module->mock('userenv', sub { { branch => $library->branchcode } }); + $module->mock( 'userenv', sub { { branch => $library->branchcode } } ); # Place a loan - my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); - my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); - my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber } } ); - my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library->branchcode, itype => $itemtype->itemtype }); - my $issue = AddIssue($brwr, $item->barcode); + my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); + my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } ); + my $biblioitem = + $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber } } ); + my $item = $builder->build_sample_item( + { biblionumber => $biblio->biblionumber, library => $library->branchcode, itype => $itemtype->itemtype } ); + my $issue = AddIssue( $brwr, $item->barcode ); # Prepare and send web request for IL-SDI server: - my $query = new CGI; - $query->param( 'service', 'GetPatronInfo' ); - $query->param( 'patron_id', $brwr->borrowernumber ); + my $query = CGI->new(); + $query->param( 'service', 'GetPatronInfo' ); + $query->param( 'patron_id', $brwr->borrowernumber ); $query->param( 'show_loans', '1' ); - my $reply = C4::ILSDI::Services::GetPatronInfo( $query ); + my $reply = C4::ILSDI::Services::GetPatronInfo($query); # Check that this loan is not on hold - is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "0", "Record is not on hold"); - is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "0", "Item is not on hold"); + is( $reply->{loans}->{loan}[0]->{holds_on_record}, "0", "Record is not on hold" ); + is( $reply->{loans}->{loan}[0]->{holds_on_item}, "0", "Item is not on hold" ); # Place a loan # Add a hold on the biblio - my $biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr2->borrowernumber, biblionumber => $biblio->biblionumber }); + my $biblioreserve = AddReserve( + { + branchcode => $library->branchcode, borrowernumber => $brwr2->borrowernumber, + biblionumber => $biblio->biblionumber + } + ); # Check that it is on hold on biblio level - $reply = C4::ILSDI::Services::GetPatronInfo( $query ); - is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold"); - is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "0", "Item is on hold"); + $reply = C4::ILSDI::Services::GetPatronInfo($query); + is( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold" ); + is( $reply->{loans}->{loan}[0]->{holds_on_item}, "0", "Item is on hold" ); # Delete holds - $schema->resultset( 'Reserve' )->delete_all; + $schema->resultset('Reserve')->delete_all; # Add a hold on the item - my $itemreserve = AddReserve({ - branchcode => $library->branchcode, - borrowernumber => $brwr2->borrowernumber, - biblionumber => $biblio->biblionumber, - itemnumber => $item->itemnumber - }); + my $itemreserve = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $brwr2->borrowernumber, + biblionumber => $biblio->biblionumber, + itemnumber => $item->itemnumber + } + ); # When a specific item has a reserve, the item is on hold as well as the record - $reply = C4::ILSDI::Services::GetPatronInfo( $query ); - is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold"); - is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "1", "Item is on hold"); + $reply = C4::ILSDI::Services::GetPatronInfo($query); + is( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold" ); + is( $reply->{loans}->{loan}[0]->{holds_on_item}, "1", "Item is on hold" ); # Add another hold on the biblio - $biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr3->borrowernumber, biblionumber => $biblio->biblionumber }); + $biblioreserve = AddReserve( + { + branchcode => $library->branchcode, borrowernumber => $brwr3->borrowernumber, + biblionumber => $biblio->biblionumber + } + ); # Check that there are 2 holds on the biblio and 1 on this specific item - $reply = C4::ILSDI::Services::GetPatronInfo( $query ); - is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "2", "Record is on hold twice"); - is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "1", "Item is on hold"); + $reply = C4::ILSDI::Services::GetPatronInfo($query); + is( $reply->{loans}->{loan}[0]->{holds_on_record}, "2", "Record is on hold twice" ); + is( $reply->{loans}->{loan}[0]->{holds_on_item}, "1", "Item is on hold" ); # Cleanup $schema->storage->txn_rollback; -- 2.30.2