From 0c4c9764db9c1946df0781227df6d3147c744301 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 1 Oct 2020 12:06:13 -0300 Subject: [PATCH] Bug 26595: Add Koha::Library->smtp_server_info This patch adds a method for retrieving brief information about the linked (or not) SMTP server for embedding on API requests. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Library.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- Koha/Library.pm | 17 +++++++++++++++++ t/db_dependent/Koha/Library.t | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Koha/Library.pm b/Koha/Library.pm index 165d974f44..90da8e2816 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -115,6 +115,23 @@ sub smtp_server { return $self; } +=head3 smtp_server_info + +Returns the SMTP server info for the library, or 'system_default' if it is the system default. + +=cut + +sub smtp_server_info { + my ($self) = @_; + + my $smtp_server = $self->smtp_server; + + return { name => 'system_default' } + if $smtp_server->is_system_default; + + return { name => $smtp_server->name, smtp_server_id => $smtp_server->id }; +} + =head3 inbound_email_address my $to_email = Koha::Library->inbound_email_address; diff --git a/t/db_dependent/Koha/Library.t b/t/db_dependent/Koha/Library.t index 23e88578b3..8c1d12ae28 100755 --- a/t/db_dependent/Koha/Library.t +++ b/t/db_dependent/Koha/Library.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Koha::Database; use Koha::SMTP::Servers; @@ -93,3 +93,22 @@ subtest 'smtp_server() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'smtp_server_info() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' }); + + # No SMTP server assigned to library, return system default + is_deeply( $library->smtp_server_info, { name => 'system_default' }, 'System default is returned' ); + + # Assign an SMTP server + $library->smtp_server({ smtp_server => $smtp_server }); + is_deeply( $library->smtp_server_info, { name => $smtp_server->name, smtp_server_id => $smtp_server->id }, 'The right information is returned when SMTP server is assigned' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5