View | Details | Raw Unified | Return to bug 30360
Collapse All | Expand All

(-)a/Koha/BackgroundJob.pm (+28 lines)
Lines 232-237 sub finish { Link Here
232
    )->store;
232
    )->store;
233
}
233
}
234
234
235
=head3 decoded_data
236
237
    my $job_data = $self->decoded_data;
238
239
Returns the decoded JSON contents from $self->data.
240
241
=cut
242
243
sub decoded_data {
244
    my ($self) = @_;
245
246
    return decode_json($self->data);
247
}
248
249
=head3 set_encoded_data
250
251
    $self->set_encoded_data( $data );
252
253
Serializes I<$data> as a JSON string and sets the I<data> attribute with it.
254
255
=cut
256
257
sub set_encoded_data {
258
    my ( $self, $data ) = @_;
259
260
    return $self->data( encode_json($data) );
261
}
262
235
=head3 job_type
263
=head3 job_type
236
264
237
Return the job type of the job. Must be a string.
265
Return the job type of the job. Must be a string.
(-)a/t/db_dependent/Koha/BackgroundJob.t (-3 / +17 lines)
Lines 17-30 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 4;
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::BackgroundJobs;
24
use Koha::BackgroundJobs;
25
use Koha::BackgroundJob::BatchUpdateItem;
25
use Koha::BackgroundJob::BatchUpdateItem;
26
26
27
use JSON qw( decode_json );
27
use JSON qw( decode_json encode_json );
28
28
29
use t::lib::Mocks;
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
Lines 143-145 subtest 'start(), step() and finish() tests' => sub { Link Here
143
143
144
    $schema->storage->txn_rollback;
144
    $schema->storage->txn_rollback;
145
};
145
};
146
- 
146
147
subtest 'decoded_data() and set_encoded_data() tests' => sub {
148
149
    plan tests => 3;
150
151
    my $job = Koha::BackgroundJob::BatchUpdateItem->new->set_encoded_data( undef );
152
    is( $job->decoded_data, undef );
153
154
    my $data = { some => 'data' };
155
156
    $job->set_encoded_data( $data );
157
158
    is_deeply( decode_json($job->data), $data );
159
    is_deeply( $job->decoded_data, $data );
160
};

Return to bug 30360