Bug 28186: Use Koha::Authority in C4::AuthoritiesMarc::AddAuthority
[koha.git] / t / Koha / Config.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 => 4;
21 use FindBin qw($Bin $Script);
22
23 use_ok('Koha::Config');
24
25 my $config_filepath = "$Bin/../data/koha-conf.xml";
26
27 subtest 'read_from_file() tests' => sub {
28     plan tests => 3;
29
30     is( Koha::Config->read_from_file(undef), undef,
31         "Undef parameter makes function return undef");
32
33     my $got = eval { Koha::Config->read_from_file($config_filepath) };
34     my $expected = {
35         'listen' => {
36             'biblioserver' => {
37                 'content' => 'unix:/home/koha/var/run/zebradb/bibliosocket',
38             },
39             'authorityserver' => {
40                 'content' => 'unix:/home/koha/var/run/zebradb/authoritysocket',
41             },
42         },
43         'server' => {
44             'biblioserver' => {
45                 'listenref' => 'biblioserver',
46                 'directory' => '/home/koha/var/lib/zebradb/biblios',
47                 'config' => '/home/koha/etc/zebradb/zebra-biblios-dom.cfg',
48                 'cql2rpn' => '/home/koha/etc/zebradb/pqf.properties',
49                 'xi:include' => [
50                     {
51                         'href' => '/home/koha/etc/zebradb/retrieval-info-bib-dom.xml',
52                         'xmlns:xi' => 'http://www.w3.org/2001/XInclude'
53                     },
54                     {
55                         'xmlns:xi' => 'http://www.w3.org/2001/XInclude',
56                         'href' => '/home/koha/etc/zebradb/explain-biblios.xml'
57                     }
58                 ],
59             },
60             'authorityserver' => {
61                 'listenref' => 'authorityserver',
62                 'directory' => '/home/koha/var/lib/zebradb/authorities',
63                 'config' => '/home/koha/etc/zebradb/zebra-authorities-dom.cfg',
64                 'cql2rpn' => '/home/koha/etc/zebradb/pqf.properties',
65                 'xi:include' => [
66                     {
67                         'xmlns:xi' => 'http://www.w3.org/2001/XInclude',
68                         'href' => '/home/koha/etc/zebradb/retrieval-info-auth-dom.xml'
69                     },
70                     {
71                         'href' => '/home/koha/etc/zebradb/explain-authorities.xml',
72                         'xmlns:xi' => 'http://www.w3.org/2001/XInclude'
73                     }
74                 ],
75             },
76         },
77         'serverinfo' => {
78             'biblioserver' => {
79                 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties',
80                 'user' => 'kohauser',
81                 'password' => 'zebrastripes',
82             },
83             'authorityserver' => {
84                 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties',
85                 'user' => 'kohauser',
86                 'password' => 'zebrastripes',
87             }
88         },
89         'config' => {
90             'db_scheme' => 'mysql',
91             'database' => 'koha',
92             'hostname' => 'localhost',
93             'port' => '3306',
94             'user' => 'kohaadmin',
95             'pass' => 'katikoan',
96             'tls' => 'no',
97             'ca' => '',
98             'cert' => '',
99             'key' => '',
100             'biblioserver' => 'biblios',
101             'biblioservershadow' => '1',
102             'authorityserver' => 'authorities',
103             'authorityservershadow' => '1',
104             'pluginsdir' => '/home/koha/var/lib/plugins',
105             'enable_plugins' => '0',
106             'upload_path' => '',
107             'tmp_path' => '',
108             'intranetdir' => '/home/koha/src',
109             'opacdir' => '/home/koha/src/opac',
110             'opachtdocs' => '/home/koha/src/koha-tmpl/opac-tmpl',
111             'intrahtdocs' => '/home/koha/src/koha-tmpl/intranet-tmpl',
112             'includes' => '/home/koha/src/koha-tmpl/intranet-tmpl/prog/en/includes/',
113             'logdir' => '/home/koha/var/log',
114             'docdir' => '/home/koha/doc',
115             'backupdir' => '/home/koha/var/spool',
116             'mana_config' => 'https://mana-kb.koha-community.org',
117             'backup_db_via_tools' => '0',
118             'backup_conf_via_tools' => '0',
119             'install_log' => '/home/koha/misc/koha-install-log',
120             'useldapserver' => '1',
121             'ldapserver' => {
122                 ldapserver => {
123                     hostname => 'ldap://another_ldap_server:389',
124                     user     => 'user',
125                     pass     => 'password',
126                     mapping  => {
127                         firstname => {
128                             is => 'givenName'
129                         }
130                     }
131                 }
132             },
133             'useshibboleth' => '0',
134             'zebra_lockdir' => '/home/koha/var/lock/zebradb',
135             'lockdir' => '__LOCK_DIR__',
136             'use_zebra_facets' => '1',
137             'zebra_max_record_size' => '1024',
138             'log4perl_conf' => '/home/koha/etc/log4perl.conf',
139             'memcached_servers' => '127.0.0.1:11211',
140             'memcached_namespace' => 'KOHA',
141             'template_cache_dir' => '/tmp/koha',
142             'api_secret_passphrase' => 'CHANGEME',
143             'access_dirs' => {
144                 access_dir => [ '/dir_1', '/dir_2' ],
145             },
146             'ttf' => {
147                 'font' => [
148                     {
149                         'type' => 'TR',
150                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
151                     },
152                     {
153                         'type' => 'TB',
154                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf',
155                     },
156                     {
157                         'type' => 'TI',
158                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf',
159                     },
160                     {
161                         'type' => 'TBI',
162                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf',
163                     },
164                     {
165                         'type' => 'C',
166                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',
167                     },
168                     {
169                         'type' => 'CB',
170                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf',
171                     },
172                     {
173                         'type' => 'CO',
174                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf',
175                     },
176                     {
177                         'type' => 'CBO',
178                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf',
179                     },
180                     {
181                         'type' => 'H',
182                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
183                     },
184                     {
185                         'type' => 'HO',
186                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf',
187                     },
188                     {
189                         'type' => 'HB',
190                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',
191                     },
192                     {
193                         'type' => 'HBO',
194                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf',
195                     },
196                 ],
197             },
198             'sms_send_config' => '/home/koha/etc/sms_send/',
199             'plack_max_requests' => '50',
200             'plack_workers' => '2',
201             'elasticsearch' => {
202                 'server' => [
203                     'localhost:9200',
204                 ],
205                 'index_name' => 'koha_master',
206                 'cxn_pool' => 'Static',
207             },
208             'interlibrary_loans' => {
209                 'backend_directory' => '/home/koha/src/Koha/Illbackends',
210                 'branch' => {
211                     'code' => 'CPL',
212                     'prefix' => 'ILL',
213                 },
214                 'staff_request_comments' => 'hide',
215                 'reply_date' => 'hide',
216                 'digital_recipient' => 'branch',
217                 'partner_code' => 'ILLLIBS',
218             },
219             'timezone' => '',
220             'bcrypt_settings' => '__BCRYPT_SETTINGS__',
221             'encryption_key' => '__ENCRYPTION_KEY__',
222             'dev_install' => '0',
223             'strict_sql_modes' => '0',
224             'plugin_repos' => '',
225             'koha_xslt_security' => '',
226             'smtp_server' => {
227                 'host' => 'localhost',
228                 'port' => '25',
229                 'timeout' => '120',
230                 'ssl_mode' => 'disabled',
231                 'user_name' => '',
232                 'password' => '',
233                 'debug' => '0',
234             },
235             'message_broker' => {
236                 'hostname' => 'localhost',
237                 'port' => '61613',
238                 'username' => 'guest',
239                 'password' => 'guest',
240                 'vhost' => '',
241             },
242         },
243     };
244     is_deeply( $got, $expected, 'File read correctly' );
245
246     # Reading a Perl script as XML should fail hopefully
247     eval { Koha::Config->read_from_file("$Bin/$Script") };
248     like( $@, qr{.*Error reading file.*}, 'File failing to read raises warning');
249 };
250
251 subtest 'get_instance' => sub {
252     plan tests => 3;
253
254     my $config = Koha::Config->get_instance($config_filepath);
255     isa_ok($config, 'Koha::Config', 'get_instance returns a Koha::Config object');
256     my $same_config = Koha::Config->get_instance($config_filepath);
257     is($config, $same_config, '2nd call to get_instance returns the same object');
258
259     local $ENV{KOHA_CONF} = $config_filepath;
260     my $default_config = Koha::Config->get_instance;
261     is($default_config, $config, 'get_instance without parameters reads $KOHA_CONF');
262 };
263
264 subtest 'get' => sub {
265     plan tests => 7;
266
267     my $config = Koha::Config->get_instance($config_filepath);
268
269     is_deeply(
270         $config->get('biblioserver', 'listen'),
271         { content => 'unix:/home/koha/var/run/zebradb/bibliosocket' },
272     );
273
274     is_deeply(
275         $config->get('biblioserver', 'server'),
276         {
277             'listenref' => 'biblioserver',
278             'directory' => '/home/koha/var/lib/zebradb/biblios',
279             'config' => '/home/koha/etc/zebradb/zebra-biblios-dom.cfg',
280             'cql2rpn' => '/home/koha/etc/zebradb/pqf.properties',
281             'xi:include' => [
282                 {
283                     'href' => '/home/koha/etc/zebradb/retrieval-info-bib-dom.xml',
284                     'xmlns:xi' => 'http://www.w3.org/2001/XInclude'
285                 },
286                 {
287                     'xmlns:xi' => 'http://www.w3.org/2001/XInclude',
288                     'href' => '/home/koha/etc/zebradb/explain-biblios.xml'
289                 }
290             ],
291         },
292     );
293
294     is_deeply(
295         $config->get('biblioserver', 'serverinfo'),
296         {
297             'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties',
298             'user' => 'kohauser',
299             'password' => 'zebrastripes',
300         },
301     );
302
303     is($config->get('db_scheme'), 'mysql');
304     is($config->get('ca'), '');
305
306     is($config->get('unicorn'), undef, 'returns undef if key does not exist');
307     is_deeply([$config->get('unicorn')], [undef], 'returns undef even in list context');
308 };