Bug 30830: Add Koha Objects for Koha Import Items
[koha.git] / t / db_dependent / Koha / SMTP / Servers.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 1;
21
22 use Koha::SMTP::Servers;
23
24 use t::lib::TestBuilder;
25 use t::lib::Mocks;
26
27 my $schema  = Koha::Database->new->schema;
28 my $builder = t::lib::TestBuilder->new;
29
30 subtest 'get_default() tests' => sub {
31
32     plan tests => 5;
33
34     $schema->storage->txn_begin;
35
36     t::lib::Mocks::mock_config( 'smtp_server', undef );
37
38     my $server  = Koha::SMTP::Servers->get_default;
39     is( ref($server), 'Koha::SMTP::Server',
40         'An object of the right type is returned' );
41
42     ok( !$server->in_storage,
43         'The default server is correctly retrieved' );
44
45     my $unblessed_server = $server->unblessed;
46     delete $unblessed_server->{id};
47     is_deeply(
48         $unblessed_server,
49         Koha::SMTP::Servers::default_setting,
50         'The default setting is returned if no user-defined default'
51     );
52
53     t::lib::Mocks::mock_config(
54         'smtp_server',
55         {
56             host      => 'localhost.midway',
57             port      => 1234,
58             timeout   => 121,
59             ssl_mode  => 'starttls',
60             user_name => 'tomasito',
61             password  => 'none',
62             debug     => 1
63         }
64     );
65
66     my $smtp_config = C4::Context->config('smtp_server');
67
68     $server = Koha::SMTP::Servers->get_default;
69     is( ref($server), 'Koha::SMTP::Server',
70         'An object of the right type is returned' );
71
72     $unblessed_server = $server->unblessed;
73     delete $unblessed_server->{id};
74     is_deeply(
75         $unblessed_server,
76         $smtp_config,
77         'The default setting is overridden by the entry in koha-conf.xml'
78     );
79
80     $schema->storage->txn_rollback;
81 };