From 092df74120ee1e8cd30a03bc1174b34b05af94aa Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 10 Feb 2017 15:08:47 +0200 Subject: [PATCH] Bug 18072: (QA-follow-up) let Koha::Item->can_be_transferred take HASHref as param This patch changes Koha::Item->can_be_transferred to accept a HASHref as follows: $item->can_be_transferred({ to => $library, from => $library2 }) To test: 1. prove t/db_dependent/Koha/Items.t --- Koha/Item.pm | 8 +++++++- t/db_dependent/Koha/Items.t | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index afa0778..9b458a7 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -163,6 +163,7 @@ sub can_article_request { =head3 can_be_transferred +$item->can_be_transferred({ to => $to_library, from => $from_library }) Checks if an item can be transferred to given library. This feature is controlled by two system preferences: @@ -170,17 +171,22 @@ UseBranchTransferLimits to enable / disable the feature BranchTransferLimitsType to use either an itemnumber or ccode as an identifier for setting the limitations +Takes HASHref that can have the following parameters: MANDATORY PARAMETERS: $to : Koha::Library or branchcode string OPTIONAL PARAMETERS: $from : Koha::Library or branchcode string # if not given, item holdingbranch # will be used instead +Returns 1 if item can be transferred to $to_library, otherwise 0. + =cut sub can_be_transferred { - my ($self, $to, $from) = @_; + my ($self, $params) = @_; + my $to = $params->{'to'}; + my $from = $params->{'from'}; if (ref($to) ne 'Koha::Library') { my $tobranchcode = defined $to ? $to : ''; $to = Koha::Libraries->find($tobranchcode); diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index ed0f62d..715d864 100644 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -106,7 +106,7 @@ subtest 'can_be_transferred' => sub { fromBranch => $library1, toBranch => $library2, })->count, 0, 'There are no transfer limits between libraries.'); - ok($item->can_be_transferred($library2), + ok($item->can_be_transferred({ to => $library2 }), 'Item can be transferred between libraries.'); my $limit = Koha::Item::Transfer::Limit->new({ @@ -118,15 +118,15 @@ subtest 'can_be_transferred' => sub { fromBranch => $library1, toBranch => $library2, })->count, 1, 'Given we have added a transfer limit,'); - is($item->can_be_transferred($library2), 0, + is($item->can_be_transferred({ to => $library2 }), 0, 'Item can no longer be transferred between libraries.'); - is($item->can_be_transferred($library2, $library1), 0, + is($item->can_be_transferred({ to => $library2, $library1 }), 0, 'We get the same result also if we pass the from-library parameter.'); - eval { $item->can_be_transferred(); }; + eval { $item->can_be_transferred({ to => undef }); }; is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.'); - eval { $item->can_be_transferred('heaven'); }; + eval { $item->can_be_transferred({ to => 'heaven' }); }; is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); - eval { $item->can_be_transferred($library2, 'hell'); }; + eval { $item->can_be_transferred({ to => $library2, from => 'hell' }); }; is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.'); }; -- 1.9.1