From 4d55c85178aab4620741749ee7644db161ca1015 Mon Sep 17 00:00:00 2001
From: Lari Taskula <lari.taskula@jns.fi>
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

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 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 6d81cc5566..890ebbd127 100644
--- a/Koha/Item.pm
+++ b/Koha/Item.pm
@@ -194,6 +194,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:
@@ -201,17 +202,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 e40396b9e1..02272d219a 100644
--- a/t/db_dependent/Koha/Items.t
+++ b/t/db_dependent/Koha/Items.t
@@ -142,7 +142,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({
@@ -154,15 +154,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.');
 };
 
-- 
2.15.2 (Apple Git-101.1)