Lines 109-115
subtest 'enqueue() tests' => sub {
Link Here
|
109 |
is( $job->status, 'new', 'Initial status set correctly' ); |
109 |
is( $job->status, 'new', 'Initial status set correctly' ); |
110 |
is( $job->borrowernumber, $patron->id, 'Borrowernumber set from userenv' ); |
110 |
is( $job->borrowernumber, $patron->id, 'Borrowernumber set from userenv' ); |
111 |
is( $job->queue, 'long_tasks', 'BatchUpdateItem should use the long_tasks queue' ); |
111 |
is( $job->queue, 'long_tasks', 'BatchUpdateItem should use the long_tasks queue' ); |
112 |
is_deeply( $job->json->decode( $job->context ), $job_context, 'Context set from userenv + interface' ); |
112 |
is_deeply( $job->decode_json_field({ field => 'context' }), $job_context, 'Context set from userenv + interface' ); |
113 |
|
113 |
|
114 |
$schema->storage->txn_rollback; |
114 |
$schema->storage->txn_rollback; |
115 |
}; |
115 |
}; |
Lines 151-164
subtest 'start(), step() and finish() tests' => sub {
Link Here
|
151 |
|
151 |
|
152 |
is( $job->status, 'cancelled', "'finish' leaves 'cancelled' untouched" ); |
152 |
is( $job->status, 'cancelled', "'finish' leaves 'cancelled' untouched" ); |
153 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
153 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
154 |
is_deeply( $job->json->decode( $job->data ), $data ); |
154 |
is_deeply( $job->decode_json_field({ field => 'data' }), $data ); |
155 |
|
155 |
|
156 |
$job->status('started')->store; |
156 |
$job->status('started')->store; |
157 |
$job->finish( $data ); |
157 |
$job->finish( $data ); |
158 |
|
158 |
|
159 |
is( $job->status, 'finished' ); |
159 |
is( $job->status, 'finished' ); |
160 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
160 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
161 |
is_deeply( $job->json->decode( $job->data ), $data ); |
161 |
is_deeply( $job->decode_json_field({ field => 'data' }), $data ); |
162 |
|
162 |
|
163 |
throws_ok |
163 |
throws_ok |
164 |
{ $job->start; } |
164 |
{ $job->start; } |
Lines 225-231
subtest 'process tests' => sub {
Link Here
|
225 |
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); |
225 |
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); |
226 |
|
226 |
|
227 |
# Manually add a job (->new->store) without context |
227 |
# Manually add a job (->new->store) without context |
228 |
my $json = $job->json; # sorry, quickly borrowing your json object |
228 |
my $json = $job->_json; # sorry, quickly borrowing your json object |
229 |
my $data = $json->encode({ a => 'a', b => 'b' }); |
229 |
my $data = $json->encode({ a => 'a', b => 'b' }); |
230 |
my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new( |
230 |
my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new( |
231 |
{ status => 'new', |
231 |
{ status => 'new', |
Lines 243-266
subtest 'process tests' => sub {
Link Here
|
243 |
$schema->storage->txn_rollback; |
243 |
$schema->storage->txn_rollback; |
244 |
}; |
244 |
}; |
245 |
|
245 |
|
246 |
subtest 'decoded_data() and set_encoded_data() tests' => sub { |
246 |
subtest 'decoded_data() tests' => sub { |
247 |
|
247 |
|
248 |
plan tests => 8; |
248 |
plan tests => 8; |
249 |
$schema->storage->txn_begin; |
249 |
$schema->storage->txn_begin; |
250 |
|
250 |
|
251 |
my $job = Koha::BackgroundJob::BatchUpdateItem->new->set_encoded_data( undef ); |
251 |
my $job = Koha::BackgroundJob::BatchUpdateItem->new->set_encoded_json_field({ data => undef, field => 'data' }); |
252 |
is( $job->decoded_data, undef, 'undef is undef' ); |
252 |
is( $job->decoded_data, undef, 'undef is undef' ); |
253 |
|
253 |
|
254 |
my $data = { some => 'data' }; |
254 |
my $data = { some => 'data' }; |
255 |
|
255 |
|
256 |
$job->set_encoded_data( $data ); |
256 |
$job->set_encoded_json_field({ data => $data, field => 'data' }); |
257 |
|
257 |
|
258 |
is_deeply( $job->json->decode($job->data), $data, 'decode what we sent' ); |
258 |
is_deeply( $job->_json->decode($job->data), $data, 'decode what we sent' ); |
259 |
is_deeply( $job->decoded_data, $data, 'check with decoded_data' ); |
259 |
is_deeply( $job->decoded_data, $data, 'check with decoded_data' ); |
260 |
|
260 |
|
261 |
# Let's get some Unicode stuff into the game |
261 |
# Let's get some Unicode stuff into the game |
262 |
$data = { favorite_Chinese => [ '葑', '癱' ], latin_dancing => [ '¢', '¥', 'á', 'û' ] }; |
262 |
$data = { favorite_Chinese => [ '葑', '癱' ], latin_dancing => [ '¢', '¥', 'á', 'û' ] }; |
263 |
$job->set_encoded_data( $data )->store; |
263 |
$job->set_encoded_json_field({ data => $data, field => 'data' })->store; |
264 |
|
264 |
|
265 |
$job->discard_changes; # refresh |
265 |
$job->discard_changes; # refresh |
266 |
is_deeply( $job->decoded_data, $data, 'Deep compare with Unicode data' ); |
266 |
is_deeply( $job->decoded_data, $data, 'Deep compare with Unicode data' ); |
Lines 275-281
subtest 'decoded_data() and set_encoded_data() tests' => sub {
Link Here
|
275 |
push @{$utf8_data->{$k}}, Encode::encode('UTF-8', $c); |
275 |
push @{$utf8_data->{$k}}, Encode::encode('UTF-8', $c); |
276 |
} |
276 |
} |
277 |
} |
277 |
} |
278 |
$job->set_encoded_data( $utf8_data )->store; |
278 |
$job->set_encoded_json_field({ data => $utf8_data, field => 'data' })->store; |
279 |
$job->discard_changes; # refresh |
279 |
$job->discard_changes; # refresh |
280 |
is_deeply( $job->decoded_data, $utf8_data, 'Deep compare with utf8_data' ); |
280 |
is_deeply( $job->decoded_data, $utf8_data, 'Deep compare with utf8_data' ); |
281 |
# Need more evidence? |
281 |
# Need more evidence? |