From e8036c97949692838f1e7452b83b2d950b32e5f4 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 11 Mar 2016 18:35:47 +0000 Subject: [PATCH] Bug 15656 [QA Followup] - Return without searching if patron has no guarantor Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- Koha/Patron.pm | 7 +++++-- t/db_dependent/Koha/Patrons.t | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 4464731831..684f274cbf 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -45,6 +45,8 @@ Returns a Koha::Patron object for this patron's guarantor sub guarantor { my ( $self ) = @_; + return undef unless $self->guarantorid(); + return Koha::Patrons->find( $self->guarantorid() ); } @@ -76,13 +78,14 @@ sub siblings { my ( $self ) = @_; my $guarantor = $self->guarantor; - my $guarantorid = $guarantor ? $guarantor->borrowernumber : undef; + + return undef unless $guarantor; return Koha::Patrons->search( { guarantorid => { '!=' => undef, - '=' => $guarantorid, + '=' => $guarantor->id, }, borrowernumber => { '!=' => $self->borrowernumber, diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 46eed31cc9..fafd8294c0 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -80,7 +80,7 @@ subtest 'guarantees' => sub { subtest 'siblings' => sub { plan tests => 7; my $siblings = $new_patron_1->siblings; - is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should not crashed if the patron has not guarantor' ); + is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' ); my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } ); my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1); $siblings = $retrieved_guarantee_1->siblings; -- 2.39.5