Bug 30889: Unit tests - process
This patch adds corresponding unit tests for the 'process' side of this patchset. We check that the Context for the job to run in as set from the Job context recorded at enqueue time. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
defcdd85a4
commit
a0000de817
1 changed files with 53 additions and 1 deletions
|
@ -17,7 +17,8 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
use Test::MockModule;
|
||||
use Test::Exception;
|
||||
|
||||
use Koha::Database;
|
||||
|
@ -28,6 +29,7 @@ use JSON qw( decode_json encode_json );
|
|||
|
||||
use t::lib::Mocks;
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Koha::BackgroundJob::BatchTest;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
|
@ -172,6 +174,56 @@ subtest 'start(), step() and finish() tests' => sub {
|
|||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'process tests' => sub {
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
C4::Context->interface('intranet');
|
||||
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
t::lib::Mocks::mock_userenv( { patron => $patron } );
|
||||
my $job_context = {
|
||||
number => $patron->borrowernumber,
|
||||
id => $patron->userid,
|
||||
cardnumber => $patron->cardnumber,
|
||||
firstname => $patron->firstname,
|
||||
surname => $patron->surname,
|
||||
branch => $patron->library->branchcode,
|
||||
branchname => $patron->library->branchname,
|
||||
flags => $patron->flags,
|
||||
emailaddress => $patron->email,
|
||||
register_id => undef,
|
||||
register_name => undef,
|
||||
shibboleth => undef,
|
||||
desk_id => undef,
|
||||
desk_name => undef,
|
||||
};
|
||||
|
||||
my $background_job_module = Test::MockModule->new('Koha::BackgroundJob');
|
||||
$background_job_module->mock(
|
||||
'type_to_class_mapping',
|
||||
sub {
|
||||
return { batch_test => 't::lib::Koha::BackgroundJob::BatchTest' };
|
||||
}
|
||||
);
|
||||
|
||||
my $job_id = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue(
|
||||
{ size => 10, a => 'aaa', b => 'bbb' } );
|
||||
my $job = Koha::BackgroundJobs->find($job_id);
|
||||
|
||||
C4::Context->_new_userenv(-1);
|
||||
C4::Context->interface('opac');
|
||||
is( C4::Context->userenv, undef, "Userenv unset prior to calling process");
|
||||
is( C4::Context->interface, 'opac', "Interface set to opac prior to calling process");
|
||||
|
||||
$job->process();
|
||||
is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" );
|
||||
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'decoded_data() and set_encoded_data() tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
|
|
Loading…
Reference in a new issue