From 25f979cc5ae37290e7af0bd7adc7820068708081 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 25 Jan 2019 12:48:04 -0300 Subject: [PATCH] Bug 21478: Add Koha::Exceptions::Hold Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens (cherry picked from commit 11ce911915a237047d8168876849de3df2b3b2e0) Signed-off-by: Martin Renvoize (cherry picked from commit ddbfc92aa601e672535c4478eb8e65e624a7d53f) Signed-off-by: Lucas Gass --- Koha/Exceptions/Hold.pm | 69 +++++++++++++++++++++++++++++++++++++++++ t/Koha/Exceptions.t | 23 +++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 Koha/Exceptions/Hold.pm diff --git a/Koha/Exceptions/Hold.pm b/Koha/Exceptions/Hold.pm new file mode 100644 index 0000000000..5e6eeb0f9e --- /dev/null +++ b/Koha/Exceptions/Hold.pm @@ -0,0 +1,69 @@ +package Koha::Exceptions::Hold; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Exceptions::Exception; + +use Exception::Class ( + 'Koha::Exceptions::Hold' => { + isa => 'Koha::Exceptions::Exception', + }, + 'Koha::Exceptions::Hold::CannotSuspendFound' => { + isa => 'Koha::Exceptions::Hold', + description => "Found holds cannot be suspended", + fields => ['status'] + } +); + +sub full_message { + my $self = shift; + + my $msg = $self->message; + + unless ( $msg) { + if ( $self->isa('Koha::Exceptions::Hold::CannotSuspendFound') ) { + $msg = sprintf("Found hold cannot be suspended. Status=%s", $self->status ); + } + } + + return $msg; +} + +=head1 NAME + +Koha::Exceptions::Hold - Base class for Hold exceptions + +=head1 Exceptions + +=head2 Koha::Exceptions::Hold + +Generic Hold exception + +=head2 Koha::Exceptions::Hold::CannotSuspendFound + +Exception to be used when suspension is requested on a found hold. + +=head1 Class methods + +=head2 full_message + +Overloaded method for exception stringifying. + +=cut + +1; diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t index c306d31cb9..efad47fa87 100644 --- a/t/Koha/Exceptions.t +++ b/t/Koha/Exceptions.t @@ -17,9 +17,30 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 3; use Test::Exception; +subtest 'Koha::Exceptions::Hold tests' => sub { + + plan tests => 5; + + use_ok('Koha::Exceptions::Hold'); + + throws_ok + { Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'W' ); } + 'Koha::Exceptions::Hold::CannotSuspendFound', + 'Exception is thrown :-D'; + + # stringify the exception + is( "$@", 'Found hold cannot be suspended. Status=W', 'Exception stringified correctly' ); + + throws_ok + { Koha::Exceptions::Hold::CannotSuspendFound->throw( "Manual message exception" ) } + 'Koha::Exceptions::Hold::CannotSuspendFound', + 'Exception is thrown :-D'; + is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' ); +}; + subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub { plan tests => 5; -- 2.39.5