Browse Source

Bug 14708: (QA follow-up) Throw exception when deleting anonymous borrower

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Kyle Hall 1 year ago
committed by Jonathan Druart
parent
commit
709f307af7
  1. 3
      Koha/Exceptions/Patron.pm
  2. 2
      Koha/Patron.pm
  3. 6
      t/db_dependent/Koha/Patrons.t

3
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;

2
Koha/Patron.pm

@ -361,7 +361,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 {

6
t/db_dependent/Koha/Patrons.t

@ -1037,10 +1037,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" );
};

Loading…
Cancel
Save