From ea33f1f2d251b827dd75bbd1d419cf2ede3671e3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 8 Oct 2019 12:51:52 -0300 Subject: [PATCH] Bug 23770: (follow-up) Add tests for Koha::Objects->TO_JSON Signed-off-by: Tomas Cohen Arazi Signed-off-by: Josef Moravec --- t/db_dependent/Koha/Objects.t | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index 8cd7c437ac..592ab40866 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -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; +}; -- 2.11.0