Bugzilla – Attachment 110579 Details for
Bug 26509
Add Koha::Items->safe_delete
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26509: Add CannotBeDeleted object exception
Bug-26509-Add-CannotBeDeleted-object-exception.patch (text/plain), 3.13 KB, created by
Martin Renvoize (ashimema)
on 2020-09-23 08:32:45 UTC
(
hide
)
Description:
Bug 26509: Add CannotBeDeleted object exception
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-09-23 08:32:45 UTC
Size:
3.13 KB
patch
obsolete
>From 527395a11ca61a3a544513a373435d1932d28742 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 22 Sep 2020 12:29:26 -0300 >Subject: [PATCH] Bug 26509: Add CannotBeDeleted object exception > >This patch adds a new exception with tests for the stringification. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/Koha/Exceptions.t >=> SUCCESS: Tests pass >3. Sign off :-D > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Exceptions/Object.pm | 8 ++++++++ > t/Koha/Exceptions.t | 24 +++++++++++++++++++++++- > 2 files changed, 31 insertions(+), 1 deletion(-) > >diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm >index 688a97cd5a..b25745723e 100644 >--- a/Koha/Exceptions/Object.pm >+++ b/Koha/Exceptions/Object.pm >@@ -23,6 +23,11 @@ use Exception::Class ( > 'Koha::Exceptions::Object' => { > isa => 'Koha::Exceptions::Exception', > }, >+ 'Koha::Exceptions::Object::CannotBeDeleted' => { >+ isa => 'Koha::Exceptions::Object', >+ description => 'The object cannot be deleted', >+ fields => ['object', 'reason'], >+ }, > 'Koha::Exceptions::Object::DuplicateID' => { > isa => 'Koha::Exceptions::Object', > description => "Duplicate ID passed", >@@ -84,6 +89,9 @@ sub full_message { > elsif ( $self->isa('Koha::Exceptions::Object::NotInstantiated') ) { > $msg = sprintf("Tried to access the '%s' method, but %s is not instantiated", $self->method, $self->class ); > } >+ elsif ( $self->isa('Koha::Exceptions::Object::CannotBeDeleted') ) { >+ $msg = sprintf("Cannot delete %s object (id=%s). Reason: %s", $self->object->_get_object_class, $self->object->id, $self->reason ); >+ } > } > > return $msg; >diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t >index 13f83049ab..77fbb770c7 100755 >--- a/t/Koha/Exceptions.t >+++ b/t/Koha/Exceptions.t >@@ -17,10 +17,12 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 7; > use Test::MockObject; > use Test::Exception; > >+use Koha::Items; >+ > subtest 'Koha::Exceptions::Hold tests' => sub { > > plan tests => 5; >@@ -196,3 +198,23 @@ subtest 'Koha::Exceptions::Object::NotInstantiated tests' => sub { > 'Exception is thrown :-D'; > is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' ); > }; >+ >+subtest 'Koha::Exceptions::Object::CannotBeDeleted tests' => sub { >+ >+ plan tests => 4; >+ >+ throws_ok >+ { Koha::Exceptions::Object::CannotBeDeleted->throw( >+ object => Koha::Item->new({ itemnumber => 1234 }), reason => 'Some reason' ); } >+ 'Koha::Exceptions::Object::CannotBeDeleted', >+ 'Exception is thrown :-D'; >+ >+ # stringify the exception >+ like( "$@", qr/Cannot delete Koha::Item=HASH\(.*\) object \(id=1234\). Reason: Some reason/ ); >+ >+ throws_ok >+ { Koha::Exceptions::Object::CannotBeDeleted->throw( "Manual message exception" ) } >+ 'Koha::Exceptions::Object::CannotBeDeleted', >+ 'Exception is thrown :-D'; >+ is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' ); >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26509
:
110563
|
110564
|
110579
|
110580
|
110629
|
110630
|
111373