From 1611c13e85fca43f24a75287b333ff71db2361b9 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 27 Sep 2017 15:32:53 +0200 Subject: [PATCH] Bug 19380: Add transfer informations in ILS-DI GetRecords response Test plan: 1. Put an item into a 'transfer' state a. Place a hold on an item in branch A for a patron of branch B b. Check in this item in branch A and confirm transfer 2. Go to http://opac/cgi-bin/koha/ilsdi.pl?service=GetRecords&id=XXX where XXX is the biblionumber of the biblio the item belongs to. 3. Verify you have a new element inside //record/items/item that contains , and 4. Check in the same item in branch B, so that the item is not flagged as being transferred 5. Repeat 2 6. Verify that the element is not there. 7. prove t/db_dependent/ILSDI_Services.t Followed test plan, patch worked as described. Also ran QA test tools and modified files passed Signed-off-by: Alex Buckley Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- C4/ILSDI/Services.pm | 9 +++++ t/db_dependent/ILSDI_Services.t | 62 +++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index a1e23cf5de..a629a1ce78 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -243,6 +243,15 @@ sub GetRecords { my $holding_library = Koha::Libraries->find( $item->{holdingbranch} ); $item->{'homebranchname'} = $home_library ? $home_library->branchname : ''; $item->{'holdingbranchname'} = $holding_library ? $holding_library->branchname : ''; + + my ($transferDate, $transferFrom, $transferTo) = GetTransfers($item->{itemnumber}); + if ($transferDate) { + $item->{transfer} = { + datesent => $transferDate, + frombranch => $transferFrom, + tobranch => $transferTo, + }; + } } # Hashref building... diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 1c93ba96e9..0e50c8e3ae 100644 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -19,11 +19,14 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use Test::More tests => 6; +use Test::More tests => 7; use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; +use C4::Items qw( ModItemTransfer ); +use C4::Circulation qw( GetTransfers ); + use Koha::AuthUtils; BEGIN { @@ -242,7 +245,6 @@ subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes $schema->storage->txn_rollback; }; - subtest 'LookupPatron test' => sub { plan tests => 9; @@ -540,4 +542,58 @@ subtest 'Holds test for branch transfer limits' => sub { is( $reply->{code}, undef, "Record hold, Item con be transferred" ); $schema->storage->txn_rollback; -} +}; + +subtest 'GetRecords' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'ILS-DI', 1 ); + + my $branch1 = $builder->build({ + source => 'Branch', + }); + my $branch2 = $builder->build({ + source => 'Branch', + }); + + my $biblio = $builder->build({ + source => 'Biblio', + }); + my $biblioitem = $builder->build({ + source => 'Biblioitem', + value => { + biblionumber => $biblio->{biblionumber}, + }, + }); + my $item = $builder->build({ + source => 'Item', + value => { + biblionumber => $biblio->{biblionumber}, + biblioitemnumber => $biblioitem->{biblioitemnumber}, + homebranch => $branch1->{branchcode}, + holdingbranch => $branch1->{branchcode}, + }, + }); + + ModItemTransfer($item->{itemnumber}, $branch1->{branchcode}, $branch2->{branchcode}); + + my $cgi = new CGI; + $cgi->param(service => 'GetRecords'); + $cgi->param(id => $biblio->{biblionumber}); + + my $reply = C4::ILSDI::Services::GetRecords($cgi); + + my ($datesent, $frombranch, $tobranch) = GetTransfers($item->{itemnumber}); + my $expected = { + datesent => $datesent, + frombranch => $frombranch, + tobranch => $tobranch, + }; + is_deeply($reply->{record}->[0]->{items}->{item}->[0]->{transfer}, $expected, + 'GetRecords returns transfer informations'); + + $schema->storage->txn_rollback; +}; -- 2.39.5