c951196f2d36112e3702b6b3a9c9077c4d671267
[srvgit] / t / db_dependent / Koha / SMTP / Server.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 => 3;
21 use Test::Exception;
22 use Test::Warn;
23
24 use Koha::SMTP::Servers;
25
26 use t::lib::TestBuilder;
27 use t::lib::Mocks;
28
29 my $schema  = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
31
32 subtest 'transport() tests' => sub {
33
34     plan tests => 6;
35
36     $schema->storage->txn_begin;
37
38     my $server = $builder->build_object(
39         {
40             class => 'Koha::SMTP::Servers',
41             value => { ssl_mode => 'disabled', debug => 0 }
42         }
43     );
44
45     my $transport = $server->transport;
46
47     is( ref($transport), 'Email::Sender::Transport::SMTP', 'Type is correct' );
48     is( $transport->ssl, 0, 'SSL is not set' );
49
50     $server->set({ ssl_mode => '1' })->store;
51     $transport = $server->transport;
52
53     is( ref($transport), 'Email::Sender::Transport::SMTP', 'Type is correct' );
54     is( $transport->ssl, '1', 'SSL is set' );
55     is( $transport->debug, '0', 'Debug setting honoured (disabled)' );
56
57     $server->set({ debug => 1 })->store;
58     $transport = $server->transport;
59
60     is( $transport->debug, '1', 'Debug setting honoured (enabled)' );
61
62     $schema->storage->txn_rollback;
63 };
64
65 subtest 'is_system_default() tests' => sub {
66
67     plan tests => 2;
68
69     $schema->storage->txn_begin;
70
71     my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' });
72     ok( !$smtp_server->is_system_default, 'A generated server is not the system default' );
73
74     my $system_default_server = Koha::SMTP::Servers->get_default;
75     ok( $system_default_server->is_system_default, 'The server returned by get_default is the system default' );
76
77     $schema->storage->txn_rollback;
78 };
79
80 subtest 'to_api() tests' => sub {
81
82     plan tests => 1;
83
84     $schema->storage->txn_begin;
85
86     my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' });
87     ok( !exists $smtp_server->to_api->{password}, 'Password is not part of the API representation' );
88
89     $schema->storage->txn_rollback;
90 };