View | Details | Raw Unified | Return to bug 14708
Collapse All | Expand All

(-)a/Koha/Exceptions/Patron.pm (+3 lines)
Lines 9-14 use Exception::Class ( Link Here
9
    'Koha::Exceptions::Patron::FailedDelete' => {
9
    'Koha::Exceptions::Patron::FailedDelete' => {
10
        description => "Deleting patron failed"
10
        description => "Deleting patron failed"
11
    },
11
    },
12
    'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron' => {
13
        description => "Deleting patron failed, AnonymousPatron is not deleteable"
14
    },
12
);
15
);
13
16
14
1;
17
1;
(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 361-367 sub delete { Link Here
361
    my ($self) = @_;
361
    my ($self) = @_;
362
362
363
    my $anonymous_patron = C4::Context->preference("AnonymousPatron");
363
    my $anonymous_patron = C4::Context->preference("AnonymousPatron");
364
    return $self if $anonymous_patron && $self->id eq $anonymous_patron;
364
    Koha::Exceptions::Patron::FailedDeleteAnonymousPatron->throw() if $anonymous_patron && $self->id eq $anonymous_patron;
365
365
366
    $self->_result->result_source->schema->txn_do(
366
    $self->_result->result_source->schema->txn_do(
367
        sub {
367
        sub {
(-)a/t/db_dependent/Koha/Patrons.t (-3 / +7 lines)
Lines 1037-1047 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1037
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} );
1037
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} );
1038
1038
1039
    subtest 'Anonymous Patron should be undeleteable' => sub {
1039
    subtest 'Anonymous Patron should be undeleteable' => sub {
1040
        plan tests => 1;
1040
        plan tests => 2;
1041
1041
1042
        my $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} );
1042
        my $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} );
1043
        $anonymous_patron->delete();
1043
        warn "X" x 100;
1044
        throws_ok { $anonymous_patron->delete(); }
1045
            'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron',
1046
            'Attempt to delete anonymous patron throws exception.';
1047
        warn "Y" x 100;
1044
        $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} );
1048
        $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} );
1049
        warn "X" x 100;
1045
        is( $anonymous_patron->id, $anonymous->{borrowernumber}, "Anonymous Patron was not deleted" );
1050
        is( $anonymous_patron->id, $anonymous->{borrowernumber}, "Anonymous Patron was not deleted" );
1046
    };
1051
    };
1047
1052
1048
- 

Return to bug 14708