From 5fdd436558c4a9c84e4cfac2a4d6663ee41adc9a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Apr 2020 12:45:04 +0200 Subject: [PATCH] Bug 23495: Fix if no sms provider defined Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- Koha/Patron.pm | 4 +++- t/db_dependent/Koha/Patrons.t | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 486406842a..5436ccc448 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -439,7 +439,9 @@ Returns a Koha::SMS::Provider object representing the patron's SMS provider. sub sms_provider { my ( $self ) = @_; - return Koha::SMS::Provider->_new_from_dbic($self->_result->sms_provider); + my $sms_provider_rs = $self->_result->sms_provider; + return unless $sms_provider_rs; + return Koha::SMS::Provider->_new_from_dbic($sms_provider_rs); } =head3 guarantor_relationships diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 3461bee9f4..4f434adc3c 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -89,8 +89,9 @@ subtest 'library' => sub { }; subtest 'sms_provider' => sub { - plan tests => 2; + plan tests => 3; my $sms_provider = $builder->build({source => 'SmsProvider' }); + is( $retrieved_patron_1->sms_provider, undef, '->sms_provider should return undef if none defined' ); $retrieved_patron_1->sms_provider_id( $sms_provider->{id} )->store; is_deeply( $retrieved_patron_1->sms_provider->unblessed, $sms_provider, 'Koha::Patron->sms_provider returns the correct SMS provider' ); is( ref($retrieved_patron_1->sms_provider), 'Koha::SMS::Provider', 'Koha::Patron->sms_provider should return a Koha::SMS::Provider object' ); -- 2.39.5