Bug 23770: (follow-up) Add tests for Koha::Objects->TO_JSON

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomás Cohen Arazi 2019-10-08 12:51:52 -03:00 committed by Martin Renvoize
parent 7ce5cb0865
commit 1800a2e6b8
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 16;
use Test::More tests => 17;
use Test::Exception;
use Test::Warn;
@ -305,3 +305,28 @@ subtest "to_api() tests" => sub {
$schema->storage->txn_rollback;
};
subtest "TO_JSON() tests" => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $city_1 = $builder->build_object( { class => 'Koha::Cities' } );
my $city_2 = $builder->build_object( { class => 'Koha::Cities' } );
my $cities = Koha::Cities->search(
{
cityid => [ $city_1->cityid, $city_2->cityid ]
},
{ -orderby => { -desc => 'cityid' } }
);
is( $cities->count, 2, 'Count is correct' );
my $cities_json = $cities->TO_JSON;
is( ref($cities_json), 'ARRAY', 'to_api returns an array' );
is_deeply( $cities_json->[0], $city_1->TO_JSON, 'TO_JSON returns the individual objects with ->TO_JSON' );
is_deeply( $cities_json->[1], $city_2->TO_JSON,'TO_JSON returns the individual objects with ->TO_JSON' );
$schema->storage->txn_rollback;
};