@@ -, +, @@ batch mod biblio --- Koha/BackgroundJob/BatchUpdateBiblio.pm | 2 +- .../Koha/BackgroundJobs/BatchUpdateBiblio.t | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ a/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -100,7 +100,7 @@ sub process { type => 'error', code => 'biblio_not_modified', biblionumber => $biblionumber, - error => ($@ ? $@ : $error), + error => ($@ ? "$@" : $error), }; } else { push @messages, { --- a/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t +++ a/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +# Copyright 2021 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 1; +use Test::MockModule; +use JSON qw( encode_json decode_json ); + +use Koha::Database; +use Koha::BackgroundJobs; +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; + +my $builder = t::lib::TestBuilder->new; + +subtest "Exceptions must be stringified" => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $C4_biblio_module = Test::MockModule->new('C4::Biblio'); + $C4_biblio_module->mock( 'ModBiblio', + sub { Koha::Exceptions::Exception->throw("It didn't work"); } ); + + my $biblio = $builder->build_sample_biblio; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $job = Koha::BackgroundJob::BatchUpdateBiblio->new( + { + status => 'new', + size => 1, + borrowernumber => $patron->borrowernumber, + type => 'batch_biblio_record_modification', + data => encode_json { + record_ids => [ $biblio->biblionumber ], + } + } + )->store; + $job = Koha::BackgroundJobs->find( $job->id ); + $job->process( + { job_id => $job->id, record_ids => [ $biblio->biblionumber ] } ); + + my $data = decode_json $job->get_from_storage->data; + is_deeply( + $data->{messages}->[0], + { + biblionumber => $biblio->biblionumber, + code => 'biblio_not_modified', + error => "It didn't work", + type => "error" + } + ); + + $schema->storage->txn_rollback; +}; --