From c933e25b6f226eb2536761f04b5fc6608c7f80c4 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 14 Aug 2020 12:57:25 +0000 Subject: [PATCH] Bug 23695: (follow-up) Add exceptions for missing branch parameters 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 --- C4/Circulation.pm | 8 ++++++++ t/db_dependent/Circulation.t | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7f75e89004..2b1d2d0730 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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; diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index a9fa393fc6..bf729494d4 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -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(); -- 2.39.5