Lines 19-24
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
|
|
22 |
use Encode; |
23 |
use JSON; |
24 |
|
22 |
use Koha::Database; |
25 |
use Koha::Database; |
23 |
|
26 |
|
24 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
Lines 31-48
my $builder = t::lib::TestBuilder->new;
Link Here
|
31 |
use_ok("Koha::Item::Template"); |
34 |
use_ok("Koha::Item::Template"); |
32 |
|
35 |
|
33 |
subtest 'Serializing and deserializing contents' => sub { |
36 |
subtest 'Serializing and deserializing contents' => sub { |
|
|
37 |
|
34 |
plan tests => 2; |
38 |
plan tests => 2; |
35 |
|
39 |
|
36 |
$schema->storage->txn_begin; |
40 |
$schema->storage->txn_begin; |
37 |
|
41 |
|
38 |
my $data = { location => 'test' }; |
42 |
my $data = { |
39 |
my $template = Koha::Item::Template->new({ |
43 |
location => 'test', |
40 |
name => 'My template', |
44 |
cost => "2\x{20ac}", |
|
|
45 |
}; |
46 |
|
47 |
my $template = Koha::Item::Template->new( |
48 |
{ name => 'My template', |
41 |
contents => $data, |
49 |
contents => $data, |
42 |
})->store(); |
50 |
} |
|
|
51 |
)->store(); |
52 |
|
53 |
my $encoded_data; |
54 |
foreach my $key ( keys %{$data} ) { |
55 |
$encoded_data->{$key} = Encode::encode('UTF-8', $data->{$key}); |
56 |
} |
57 |
|
58 |
is( $template->contents, JSON->new->utf8->encode($data), 'Contents serialized correctly' ); |
43 |
|
59 |
|
44 |
is( $template->contents, '{"location":"test"}', 'Contents serialized correctly' ); |
60 |
is_deeply( |
45 |
is( $template->decoded_contents->{location}, 'test', 'Contents deserialized correctly' ); |
61 |
$template->decoded_contents, |
|
|
62 |
$encoded_data, |
63 |
'Contents deserialized and UTF-8 encoded correctly' |
64 |
); |
46 |
|
65 |
|
47 |
$schema->storage->txn_rollback; |
66 |
$schema->storage->txn_rollback; |
48 |
}; |
67 |
}; |
49 |
- |
|
|