@@ -, +, @@ $ kshell k$ prove t/db_dependent/Circulation/MarkIssueReturned.t --- C4/Circulation.pm | 13 +------------ t/db_dependent/Circulation/MarkIssueReturned.t | 11 ++++++++--- 2 files changed, 9 insertions(+), 15 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2359,17 +2359,6 @@ sub MarkIssueReturned { my $issue_id = $issue->issue_id; - my $anonymouspatron; - if ( $privacy && $privacy == 2 ) { - # The default of 0 will not work due to foreign key constraints - # The anonymisation will fail if AnonymousPatron is not a valid entry - # We need to check if the anonymous patron exist, Koha will fail loudly if it does not - # Note that a warning should appear on the about page (System information tab). - $anonymouspatron = C4::Context->preference('AnonymousPatron'); - die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly." - unless Koha::Patrons->find( $anonymouspatron ); - } - my $schema = Koha::Database->schema; # FIXME Improve the return value and handle it from callers @@ -2390,7 +2379,7 @@ sub MarkIssueReturned { # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber if ( $privacy && $privacy == 2) { - $old_checkout->borrowernumber($anonymouspatron)->store; + $old_checkout->anonymize; } # And finally delete the issue --- a/t/db_dependent/Circulation/MarkIssueReturned.t +++ a/t/db_dependent/Circulation/MarkIssueReturned.t @@ -76,7 +76,7 @@ subtest 'Failure tests' => sub { subtest 'Anonymous patron tests' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; @@ -99,8 +99,13 @@ subtest 'Anonymous patron tests' => sub { t::lib::Mocks::mock_preference( 'AnonymousPatron', '' ); my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); - eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) }; - like ( $@, qr, 'AnonymousPatron is not set - Fatal error on anonymization' ); + + throws_ok + { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); } + 'Koha::Exceptions::SysPref::NotSet', + 'AnonymousPatron not set causes an exception'; + + is( $@->syspref, 'AnonymousPatron', 'AnonymousPatron is not set - Fatal error on anonymization' ); Koha::Checkouts->find( $issue->issue_id )->delete; # Create a valid anonymous user --