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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2020-08-24 16:47:58 -03:00 committed by Jonathan Druart
parent 59c1151618
commit 1d1dcc3f41
2 changed files with 40 additions and 2 deletions

View File

@ -43,7 +43,16 @@ Returns the default I<Koha::SMTP::Server> 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;
}

View File

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