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

(-)a/Koha/BackgroundJob.pm (+28 lines)
Lines 234-239 sub finish { Link Here
234
    )->store;
234
    )->store;
235
}
235
}
236
236
237
=head3 decoded_data
238
239
    my $job_data = $self->decoded_data;
240
241
Returns the decoded JSON contents from $self->data.
242
243
=cut
244
245
sub decoded_data {
246
    my ($self) = @_;
247
248
    return decode_json($self->data);
249
}
250
251
=head3 set_encoded_data
252
253
    $self->set_encoded_data( $data );
254
255
Serializes I<$data> as a JSON string and sets the I<data> attribute with it.
256
257
=cut
258
259
sub set_encoded_data {
260
    my ( $self, $data ) = @_;
261
262
    return $self->data( encode_json($data) );
263
}
264
237
=head3 job_type
265
=head3 job_type
238
266
239
Return the job type of the job. Must be a string.
267
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 152-154 subtest 'start(), step() and finish() tests' => sub { Link Here
152
152
153
    $schema->storage->txn_rollback;
153
    $schema->storage->txn_rollback;
154
};
154
};
155
- 
155
156
subtest 'decoded_data() and set_encoded_data() tests' => sub {
157
158
    plan tests => 3;
159
160
    my $job = Koha::BackgroundJob::BatchUpdateItem->new->set_encoded_data( undef );
161
    is( $job->decoded_data, undef );
162
163
    my $data = { some => 'data' };
164
165
    $job->set_encoded_data( $data );
166
167
    is_deeply( decode_json($job->data), $data );
168
    is_deeply( $job->decoded_data, $data );
169
};

Return to bug 30360