3 # Copyright 2020 Koha Development team
5 # This file is part of Koha
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.
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.
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>.
22 use Test::More tests => 2;
25 use Koha::AdditionalContents;
26 use Koha::SMTP::Servers;
28 use t::lib::TestBuilder;
30 my $schema = Koha::Database->new->schema;
31 my $builder = t::lib::TestBuilder->new;
33 subtest 'smtp_server() tests' => sub {
37 $schema->storage->txn_begin;
39 my $library = $builder->build_object({ class => 'Koha::Libraries' });
40 my $smtp_server_1 = $builder->build_object({ class => 'Koha::SMTP::Servers' });
41 my $smtp_server_2 = $builder->build_object({ class => 'Koha::SMTP::Servers' });
43 is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
46 $library->smtp_server->unblessed,
47 Koha::SMTP::Servers->get_default->unblessed,
48 'Fresh library is set the default'
51 my $return = $library->smtp_server({ smtp_server => $smtp_server_1 });
52 $library->discard_changes;
54 is( ref($return), 'Koha::Library', 'The setter is chainable' );
55 is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
57 $library->smtp_server->unblessed,
58 $smtp_server_1->unblessed,
59 'SMTP server correctly set for library'
62 $return = $library->smtp_server({ smtp_server => $smtp_server_2 });
63 $library->discard_changes;
65 is( ref($return), 'Koha::Library', 'The setter is chainable' );
66 is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
68 $library->smtp_server->unblessed,
69 $smtp_server_2->unblessed,
70 'SMTP server correctly set for library'
73 $return = $library->smtp_server({ smtp_server => undef });
74 $library->discard_changes;
76 is( ref($return), 'Koha::Library', 'The setter is chainable' );
77 is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
79 $library->smtp_server->unblessed,
80 Koha::SMTP::Servers->get_default->unblessed,
81 'Resetting makes it return the default'
84 $return = $library->smtp_server({ smtp_server => undef });
85 $library->discard_changes;
87 is( ref($return), 'Koha::Library', 'The setter is chainable' );
88 is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' );
90 $library->smtp_server->unblessed,
91 Koha::SMTP::Servers->get_default->unblessed,
92 q{Resetting twice doesn't explode and has the expected results}
95 $schema->storage->txn_rollback;
98 subtest 'opac_info tests' => sub {
100 $schema->storage->txn_begin;
101 my $library01 = $builder->build_object({ class => 'Koha::Libraries' });
102 my $library02 = $builder->build_object({ class => 'Koha::Libraries' });
104 my $html01 = $builder->build_object({
105 class => 'Koha::AdditionalContents',
106 value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'default', content => '1', expirationdate => undef },
108 my $html02 = $builder->build_object({
109 class => 'Koha::AdditionalContents',
110 value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'default', content => '2', expirationdate => undef },
112 my $html03 = $builder->build_object({
113 class => 'Koha::AdditionalContents',
114 value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'nl-NL', content => '3', expirationdate => undef },
116 my $html04 = $builder->build_object({
117 class => 'Koha::AdditionalContents',
118 value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'fr-FR', content => '4', expirationdate => undef },
122 is( $library01->opac_info->content, '2', 'specific library, default language' );
123 is( $library01->opac_info({ lang => 'nl-NL' })->content, '3', 'specific library, specific language' );
124 is( $library01->opac_info({ lang => 'nl-BE' })->content, '2', 'specific library, unknown language' );
125 is( $library02->opac_info->content, '1', 'unknown library, default language' );
126 is( $library02->opac_info({ lang => 'fr-FR' })->content, '4', 'unknown library, specific language' );
127 is( $library02->opac_info({ lang => 'de-DE' })->content, '1', 'unknown library, unknown language' );
129 is( $library02->opac_info, undef, 'unknown library, default language (after removing html01)' );
130 is( $library02->opac_info({ lang => 'de-DE' }), undef, 'unknown library, unknown language (after removing html01)' );
132 $schema->storage->txn_rollback;