Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[koha.git] / t / db_dependent / Koha / Library.t
1 #!/usr/bin/perl
2
3 # Copyright 2020 Koha Development team
4 #
5 # This file is part of Koha
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 1;
23
24 use Koha::Database;
25 use Koha::SMTP::Servers;
26
27 use t::lib::TestBuilder;
28
29 my $schema  = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
31
32 subtest 'smtp_server() tests' => sub {
33
34     plan tests => 14;
35
36     $schema->storage->txn_begin;
37
38     my $library       = $builder->build_object({ class => 'Koha::Libraries' });
39     my $smtp_server_1 = $builder->build_object({ class => 'Koha::SMTP::Servers' });
40     my $smtp_server_2 = $builder->build_object({ class => 'Koha::SMTP::Servers' });
41
42     is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
43
44     is_deeply(
45         $library->smtp_server->unblessed,
46         Koha::SMTP::Servers->get_default->unblessed,
47         'Fresh library is set the default'
48     );
49
50     my $return = $library->smtp_server({ smtp_server => $smtp_server_1 });
51     $library->discard_changes;
52
53     is( ref($return), 'Koha::Library', 'The setter is chainable' );
54     is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
55     is_deeply(
56         $library->smtp_server->unblessed,
57         $smtp_server_1->unblessed,
58         'SMTP server correctly set for library'
59     );
60
61     $return = $library->smtp_server({ smtp_server => $smtp_server_2 });
62     $library->discard_changes;
63
64     is( ref($return), 'Koha::Library', 'The setter is chainable' );
65     is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
66     is_deeply(
67         $library->smtp_server->unblessed,
68         $smtp_server_2->unblessed,
69         'SMTP server correctly set for library'
70     );
71
72     $return = $library->smtp_server({ smtp_server => undef });
73     $library->discard_changes;
74
75     is( ref($return), 'Koha::Library', 'The setter is chainable' );
76     is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
77     is_deeply(
78         $library->smtp_server->unblessed,
79         Koha::SMTP::Servers->get_default->unblessed,
80         'Resetting makes it return the default'
81     );
82
83     $return = $library->smtp_server({ smtp_server => undef });
84     $library->discard_changes;
85
86     is( ref($return), 'Koha::Library', 'The setter is chainable' );
87     is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
88     is_deeply(
89         $library->smtp_server->unblessed,
90         Koha::SMTP::Servers->get_default->unblessed,
91         q{Resetting twice doesn't explode and has the expected results}
92     );
93
94     $schema->storage->txn_rollback;
95 };