|
Lines 16-21
Link Here
|
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
|
|
19 |
use utf8; |
| 20 |
use Encode; |
| 19 |
|
21 |
|
| 20 |
use Test::More tests => 5; |
22 |
use Test::More tests => 5; |
| 21 |
use Test::MockModule; |
23 |
use Test::MockModule; |
|
Lines 242-256
subtest 'process tests' => sub {
Link Here
|
| 242 |
|
244 |
|
| 243 |
subtest 'decoded_data() and set_encoded_data() tests' => sub { |
245 |
subtest 'decoded_data() and set_encoded_data() tests' => sub { |
| 244 |
|
246 |
|
| 245 |
plan tests => 3; |
247 |
plan tests => 8; |
|
|
248 |
$schema->storage->txn_begin; |
| 246 |
|
249 |
|
| 247 |
my $job = Koha::BackgroundJob::BatchUpdateItem->new->set_encoded_data( undef ); |
250 |
my $job = Koha::BackgroundJob::BatchUpdateItem->new->set_encoded_data( undef ); |
| 248 |
is( $job->decoded_data, undef ); |
251 |
is( $job->decoded_data, undef, 'undef is undef' ); |
| 249 |
|
252 |
|
| 250 |
my $data = { some => 'data' }; |
253 |
my $data = { some => 'data' }; |
| 251 |
|
254 |
|
| 252 |
$job->set_encoded_data( $data ); |
255 |
$job->set_encoded_data( $data ); |
| 253 |
|
256 |
|
| 254 |
is_deeply( $job->json->decode($job->data), $data ); |
257 |
is_deeply( $job->json->decode($job->data), $data, 'decode what we sent' ); |
| 255 |
is_deeply( $job->decoded_data, $data ); |
258 |
is_deeply( $job->decoded_data, $data, 'check with decoded_data' ); |
|
|
259 |
|
| 260 |
# Let's get some Unicode stuff into the game |
| 261 |
$data = { favorite_Chinese => [ '葑', '癱' ], latin_dancing => [ '¢', '¥', 'á', 'û' ] }; |
| 262 |
$job->set_encoded_data( $data )->store; |
| 263 |
|
| 264 |
$job->discard_changes; # refresh |
| 265 |
is_deeply( $job->decoded_data, $data, 'Deep compare with Unicode data' ); |
| 266 |
# To convince you even more |
| 267 |
is( ord( $job->decoded_data->{favorite_Chinese}->[0] ), 33873, 'We still found Unicode \x8451' ); |
| 268 |
is( ord( $job->decoded_data->{latin_dancing}->[0] ), 162, 'We still found the equivalent of Unicode \x00A2' ); |
| 269 |
|
| 270 |
# Testing with sending encoded data (which we normally shouldnt do) |
| 271 |
my $utf8_data; |
| 272 |
foreach my $k ( 'favorite_Chinese', 'latin_dancing' ) { |
| 273 |
foreach my $c ( @{$data->{$k}} ) { |
| 274 |
push @{$utf8_data->{$k}}, Encode::encode('UTF-8', $c); |
| 275 |
} |
| 276 |
} |
| 277 |
$job->set_encoded_data( $utf8_data )->store; |
| 278 |
$job->discard_changes; # refresh |
| 279 |
is_deeply( $job->decoded_data, $utf8_data, 'Deep compare with utf8_data' ); |
| 280 |
# Need more evidence? |
| 281 |
is( ord( $job->decoded_data->{favorite_Chinese}->[0] ), 232, 'We still found a UTF8 encoded byte' ); # ord does not need substr here |
| 282 |
|
| 283 |
$schema->storage->txn_rollback; |
| 256 |
}; |
284 |
}; |
| 257 |
- |
|
|