@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Library.t --- Koha/Library.pm | 17 +++++++++++++++++ t/db_dependent/Koha/Library.t | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) --- a/Koha/Library.pm +++ a/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; --- a/t/db_dependent/Koha/Library.t +++ a/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; +}; --