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