From 93e32c77e9bd7f13ea0b0798690022dd3983737e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 2 Nov 2020 08:11:58 -0500 Subject: [PATCH] Bug 14708: (QA follow-up) Throw exception when deleting anonymous borrower Signed-off-by: Jonathan Druart (cherry picked from commit 709f307af7b51f42d79a68a09b31249daef32ec1) Signed-off-by: Andrew Fuerste-Henry --- Koha/Exceptions/Patron.pm | 3 +++ Koha/Patron.pm | 2 +- t/db_dependent/Koha/Patrons.t | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Koha/Exceptions/Patron.pm b/Koha/Exceptions/Patron.pm index 8eac9c9366..069ed942c2 100644 --- a/Koha/Exceptions/Patron.pm +++ b/Koha/Exceptions/Patron.pm @@ -9,6 +9,9 @@ use Exception::Class ( 'Koha::Exceptions::Patron::FailedDelete' => { description => "Deleting patron failed" }, + 'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron' => { + description => "Deleting patron failed, AnonymousPatron is not deleteable" + }, ); 1; diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 4b5b38664a..867a60cee3 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -362,7 +362,7 @@ sub delete { my ($self) = @_; my $anonymous_patron = C4::Context->preference("AnonymousPatron"); - return $self if $anonymous_patron && $self->id eq $anonymous_patron; + Koha::Exceptions::Patron::FailedDeleteAnonymousPatron->throw() if $anonymous_patron && $self->id eq $anonymous_patron; $self->_result->result_source->schema->txn_do( sub { diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 81914cfeb0..b13bc5d7f3 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1078,10 +1078,12 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); subtest 'Anonymous Patron should be undeleteable' => sub { - plan tests => 1; + plan tests => 2; my $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} ); - $anonymous_patron->delete(); + throws_ok { $anonymous_patron->delete(); } + 'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron', + 'Attempt to delete anonymous patron throws exception.'; $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} ); is( $anonymous_patron->id, $anonymous->{borrowernumber}, "Anonymous Patron was not deleted" ); }; -- 2.39.5