From 23ea002c8517587cd47ef6bf81d491a172f5b9e1 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 24 Aug 2020 16:47:58 -0300 Subject: [PATCH] Bug 26290: Make Koha::SMTP::Servers->get_default use koha-conf.xml This patch makes the mentioned method use the configured entry in koha-conf.xml if present, instead of the hardcoded one, which is kept for people that carries an old koha-conf.xml --- Koha/SMTP/Servers.pm | 11 ++++++++++- t/db_dependent/Koha/SMTP/Servers.t | 31 +++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Koha/SMTP/Servers.pm b/Koha/SMTP/Servers.pm index a4354c3775..d7451e9a87 100644 --- a/Koha/SMTP/Servers.pm +++ b/Koha/SMTP/Servers.pm @@ -43,7 +43,16 @@ Returns the default I object. sub get_default { my ($self) = @_; - my $default = Koha::SMTP::Server->new( $self->default_setting ); + my $default; + my $smtp_config = C4::Context->config('smtp_server'); + + if ( $smtp_config ) { + $default = Koha::SMTP::Server->new( $smtp_config ); + } + else { + $default = Koha::SMTP::Server->new( $self->default_setting ); + } + $default->{_is_system_default} = 1; return $default; } diff --git a/t/db_dependent/Koha/SMTP/Servers.t b/t/db_dependent/Koha/SMTP/Servers.t index adefdaed12..b3506b76b1 100644 --- a/t/db_dependent/Koha/SMTP/Servers.t +++ b/t/db_dependent/Koha/SMTP/Servers.t @@ -29,10 +29,12 @@ my $builder = t::lib::TestBuilder->new; subtest 'get_default() tests' => sub { - plan tests => 3; + plan tests => 5; $schema->storage->txn_begin; + t::lib::Mocks::mock_config( 'smtp_server', undef ); + my $server = Koha::SMTP::Servers->get_default; is( ref($server), 'Koha::SMTP::Server', 'An object of the right type is returned' ); @@ -48,5 +50,32 @@ subtest 'get_default() tests' => sub { 'The default setting is returned if no user-defined default' ); + t::lib::Mocks::mock_config( + 'smtp_server', + { + host => 'localhost.midway', + port => 1234, + timeout => 121, + ssl_mode => 'starttls', + user_name => 'tomasito', + password => 'none', + debug => 1 + } + ); + + my $smtp_config = C4::Context->config('smtp_server'); + + $server = Koha::SMTP::Servers->get_default; + is( ref($server), 'Koha::SMTP::Server', + 'An object of the right type is returned' ); + + $unblessed_server = $server->unblessed; + delete $unblessed_server->{id}; + is_deeply( + $unblessed_server, + $smtp_config, + 'The default setting is overridden by the entry in koha-conf.xml' + ); + $schema->storage->txn_rollback; }; -- 2.28.0