Bug 23695: (follow-up) Add exceptions for missing branch parameters
authorNick Clemens <nick@bywatersolutions.com>
Fri, 14 Aug 2020 12:57:25 +0000 (12:57 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Aug 2020 13:45:48 +0000 (15:45 +0200)
JD: amended patch
Remove QA issues:
 FAIL   t/db_dependent/Circulation.t
   FAIL   valid
                "my" variable $doreturn masks earlier declaration in same scope
                "my" variable $messages masks earlier declaration in same scope

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Circulation.pm
t/db_dependent/Circulation.t

index 7f75e89..2b1d2d0 100644 (file)
@@ -322,6 +322,14 @@ sub transferbook {
     my $dotransfer      = 1;
     my $item = Koha::Items->find( { barcode => $barcode } );
 
+    Koha::Exceptions::MissingParameter->throw(
+        "Missing mandatory parameter: from_branch")
+      unless $fbr;
+
+    Koha::Exceptions::MissingParameter->throw(
+        "Missing mandatory parameter: to_branch")
+      unless $tbr;
+
     # bad barcode..
     unless ( $item ) {
         $messages->{'BadBarcode'} = $barcode;
index a9fa393..bf72949 100755 (executable)
@@ -18,7 +18,8 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 49;
+use Test::More tests => 50;
+use Test::Exception;
 use Test::MockModule;
 use Test::Deep qw( cmp_deeply );
 
@@ -4449,6 +4450,36 @@ subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub {
     };
 };
 
+subtest 'transferbook tests' => sub {
+    plan tests => 9;
+
+    throws_ok
+    { C4::Circulation::transferbook({}); }
+    'Koha::Exceptions::MissingParameter',
+    'Koha::Patron->store raises an exception on missing params';
+
+    throws_ok
+    { C4::Circulation::transferbook({to_branch=>'anything'}); }
+    'Koha::Exceptions::MissingParameter',
+    'Koha::Patron->store raises an exception on missing params';
+
+    throws_ok
+    { C4::Circulation::transferbook({from_branch=>'anything'}); }
+    'Koha::Exceptions::MissingParameter',
+    'Koha::Patron->store raises an exception on missing params';
+
+    my ($doreturn,$messages) = C4::Circulation::transferbook({to_branch=>'there',from_branch=>'here'});
+    is( $doreturn, 0, "No return without barcode");
+    ok( exists $messages->{BadBarcode}, "We get a BadBarcode message if no barcode passed");
+    is( $messages->{BadBarcode}, undef, "No barcode passed means undef BadBarcode" );
+
+    ($doreturn,$messages) = C4::Circulation::transferbook({to_branch=>'there',from_branch=>'here',barcode=>'BadBarcode'});
+    is( $doreturn, 0, "No return without barcode");
+    ok( exists $messages->{BadBarcode}, "We get a BadBarcode message if no barcode passed");
+    is( $messages->{BadBarcode}, 'BadBarcode', "No barcode passed means undef BadBarcode" );
+
+};
+
 $schema->storage->txn_rollback;
 C4::Context->clear_syspref_cache();
 $branches = Koha::Libraries->search();