Bug 24606: Regression tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2022-11-11 15:14:52 -03:00
parent cc1502033c
commit 1d65a71cf6
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 26 additions and 7 deletions

View File

@ -19,6 +19,9 @@
use Modern::Perl;
use Encode;
use JSON;
use Koha::Database;
use t::lib::TestBuilder;
@ -31,18 +34,34 @@ my $builder = t::lib::TestBuilder->new;
use_ok("Koha::Item::Template");
subtest 'Serializing and deserializing contents' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $data = { location => 'test' };
my $template = Koha::Item::Template->new({
name => 'My template',
contents => $data,
})->store();
my $data = {
location => 'test',
cost => "2\x{20ac}",
};
is( $template->contents, '{"location":"test"}', 'Contents serialized correctly' );
is( $template->decoded_contents->{location}, 'test', 'Contents deserialized correctly' );
my $template = Koha::Item::Template->new(
{ name => 'My template',
contents => $data,
}
)->store();
my $encoded_data;
foreach my $key ( keys %{$data} ) {
$encoded_data->{$key} = Encode::encode('UTF-8', $data->{$key});
}
is( $template->contents, JSON->new->utf8->encode($data), 'Contents serialized correctly' );
is_deeply(
$template->decoded_contents,
$encoded_data,
'Contents deserialized and UTF-8 encoded correctly'
);
$schema->storage->txn_rollback;
};