From c81a9e5fb0496a702bd7faaf8e19bc5a95c54ca4 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 --- 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 8cfcdb005b..b24ef6e90d 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..f621da5df6 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" ); + + my ($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.11.0