Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 4; |
20 |
use Test::More tests => 5; |
|
|
21 |
use Test::MockModule; |
21 |
use Test::Exception; |
22 |
use Test::Exception; |
22 |
|
23 |
|
23 |
use Koha::Database; |
24 |
use Koha::Database; |
Lines 28-33
use JSON qw( decode_json encode_json );
Link Here
|
28 |
|
29 |
|
29 |
use t::lib::Mocks; |
30 |
use t::lib::Mocks; |
30 |
use t::lib::TestBuilder; |
31 |
use t::lib::TestBuilder; |
|
|
32 |
use t::lib::Koha::BackgroundJob::BatchTest; |
31 |
|
33 |
|
32 |
my $schema = Koha::Database->new->schema; |
34 |
my $schema = Koha::Database->new->schema; |
33 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $builder = t::lib::TestBuilder->new; |
Lines 172-177
subtest 'start(), step() and finish() tests' => sub {
Link Here
|
172 |
$schema->storage->txn_rollback; |
174 |
$schema->storage->txn_rollback; |
173 |
}; |
175 |
}; |
174 |
|
176 |
|
|
|
177 |
subtest 'process tests' => sub { |
178 |
|
179 |
plan tests => 4; |
180 |
|
181 |
$schema->storage->txn_begin; |
182 |
|
183 |
C4::Context->interface('intranet'); |
184 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
185 |
t::lib::Mocks::mock_userenv( { patron => $patron } ); |
186 |
my $job_context = { |
187 |
number => $patron->borrowernumber, |
188 |
id => $patron->userid, |
189 |
cardnumber => $patron->cardnumber, |
190 |
firstname => $patron->firstname, |
191 |
surname => $patron->surname, |
192 |
branch => $patron->library->branchcode, |
193 |
branchname => $patron->library->branchname, |
194 |
flags => $patron->flags, |
195 |
emailaddress => $patron->email, |
196 |
register_id => undef, |
197 |
register_name => undef, |
198 |
shibboleth => undef, |
199 |
desk_id => undef, |
200 |
desk_name => undef, |
201 |
}; |
202 |
|
203 |
my $background_job_module = Test::MockModule->new('Koha::BackgroundJob'); |
204 |
$background_job_module->mock( |
205 |
'type_to_class_mapping', |
206 |
sub { |
207 |
return { batch_test => 't::lib::Koha::BackgroundJob::BatchTest' }; |
208 |
} |
209 |
); |
210 |
|
211 |
my $job_id = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue( |
212 |
{ size => 10, a => 'aaa', b => 'bbb' } ); |
213 |
my $job = Koha::BackgroundJobs->find($job_id); |
214 |
|
215 |
C4::Context->_new_userenv(-1); |
216 |
C4::Context->interface('opac'); |
217 |
is( C4::Context->userenv, undef, "Userenv unset prior to calling process"); |
218 |
is( C4::Context->interface, 'opac', "Interface set to opac prior to calling process"); |
219 |
|
220 |
$job->process(); |
221 |
is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" ); |
222 |
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); |
223 |
|
224 |
$schema->storage->txn_rollback; |
225 |
}; |
226 |
|
175 |
subtest 'decoded_data() and set_encoded_data() tests' => sub { |
227 |
subtest 'decoded_data() and set_encoded_data() tests' => sub { |
176 |
|
228 |
|
177 |
plan tests => 3; |
229 |
plan tests => 3; |
178 |
- |
|
|