Bug 42394: Add regression test for userenv mutation during enqueue

Verifies that BackgroundJob->enqueue() does not mutate the
C4::Context userenv hashref as a side-effect.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2026-04-16 09:37:43 +02:00 committed by Lucas Gass
parent 5288847641
commit 5cef972961
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 25 additions and 1 deletions

View File

@ -20,14 +20,16 @@
use Modern::Perl;
use Test::NoWarnings;
use Test::More tests => 15;
use Test::More tests => 16;
use Test::MockModule;
use List::MoreUtils qw(any);
use Storable qw( dclone );
use Koha::Database;
use Koha::BackgroundJobs;
use Koha::DateUtils qw( dt_from_string );
use Koha::Session;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -147,3 +149,25 @@ subtest 'search_limited' => sub {
$schema->storage->txn_rollback;
};
subtest 'Do not mutate userenv' => sub {
plan tests => 1;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } );
my $session = Koha::Session->get_session();
C4::Context->set_userenv_from_session($session);
my $pre_userenv = dclone( C4::Context->userenv );
my $job_id = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue(
{
size => $job_size,
%$data
}
);
my $post_userenv = C4::Context->userenv;
is_deeply( $pre_userenv, $post_userenv );
$schema->storage->txn_rollback;
};