From 717a4377bab484debde2b8fbdce6e78d97978b5a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 24 Mar 2020 09:23:37 -0300 Subject: [PATCH] Bug 24965: Regression tests To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail with "Can't call method "count" on an undefined value..." Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Object.t | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 73e4e10762..6858a1c34e 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -215,7 +215,7 @@ subtest 'TO_JSON tests' => sub { subtest "to_api() tests" => sub { - plan tests => 28; + plan tests => 29; $schema->storage->txn_begin; @@ -365,6 +365,19 @@ subtest "to_api() tests" => sub { 'Koha::Exceptions::Object::MethodNotCoveredByTests', 'Unknown method exception thrown if is_count not specified'; + # Simulate a situation in which the relation returns undef instead of an empty iterator + my $patron_class = Test::MockModule->new('Koha::Patron'); + $patron_class->mock( 'holds', sub { + return; + }); + + $patron_api = $patron->to_api( + { + embed => { holds_count => { is_count => 1 } } + } + ); + is( $patron_api->{holds_count}, 0, 'Count embeds returns 0 if the relation is undef' ); + $schema->storage->txn_rollback; }; -- 2.26.0