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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2020-10-01 12:06:13 -03:00 committed by Jonathan Druart
parent 98b584d97f
commit 0c4c9764db
2 changed files with 37 additions and 1 deletions

View File

@ -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;

View File

@ -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;
};