3 # This file is part of Koha.
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.
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.
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>.
20 use Test::More tests => 4;
21 use FindBin qw($Bin $Script);
23 use_ok('Koha::Config');
25 my $config_filepath = "$Bin/../data/koha-conf.xml";
27 subtest 'read_from_file() tests' => sub {
30 is( Koha::Config->read_from_file(undef), undef,
31 "Undef parameter makes function return undef");
33 my $got = eval { Koha::Config->read_from_file($config_filepath) };
37 'content' => 'unix:/home/koha/var/run/zebradb/bibliosocket',
39 'authorityserver' => {
40 'content' => 'unix:/home/koha/var/run/zebradb/authoritysocket',
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',
51 'href' => '/home/koha/etc/zebradb/retrieval-info-bib-dom.xml',
52 'xmlns:xi' => 'http://www.w3.org/2001/XInclude'
55 'xmlns:xi' => 'http://www.w3.org/2001/XInclude',
56 'href' => '/home/koha/etc/zebradb/explain-biblios.xml'
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',
67 'xmlns:xi' => 'http://www.w3.org/2001/XInclude',
68 'href' => '/home/koha/etc/zebradb/retrieval-info-auth-dom.xml'
71 'href' => '/home/koha/etc/zebradb/explain-authorities.xml',
72 'xmlns:xi' => 'http://www.w3.org/2001/XInclude'
79 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties',
81 'password' => 'zebrastripes',
83 'authorityserver' => {
84 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties',
86 'password' => 'zebrastripes',
90 'db_scheme' => 'mysql',
92 'hostname' => 'localhost',
94 'user' => 'kohaadmin',
100 'biblioserver' => 'biblios',
101 'biblioservershadow' => '1',
102 'authorityserver' => 'authorities',
103 'authorityservershadow' => '1',
104 'pluginsdir' => '/home/koha/var/lib/plugins',
105 'enable_plugins' => '0',
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',
123 hostname => 'ldap://another_ldap_server:389',
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',
144 access_dir => [ '/dir_1', '/dir_2' ],
150 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
154 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf',
158 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf',
162 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf',
166 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',
170 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf',
174 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf',
178 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf',
182 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
186 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf',
190 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',
194 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf',
198 'sms_send_config' => '/home/koha/etc/sms_send/',
199 'plack_max_requests' => '50',
200 'plack_workers' => '2',
205 'index_name' => 'koha_master',
206 'cxn_pool' => 'Static',
208 'interlibrary_loans' => {
209 'backend_directory' => '/home/koha/src/Koha/Illbackends',
214 'staff_request_comments' => 'hide',
215 'reply_date' => 'hide',
216 'digital_recipient' => 'branch',
219 'bcrypt_settings' => '__BCRYPT_SETTINGS__',
220 'encryption_key' => '__ENCRYPTION_KEY__',
221 'dev_install' => '0',
222 'strict_sql_modes' => '0',
223 'plugin_repos' => '',
224 'koha_xslt_security' => '',
226 'host' => 'localhost',
229 'ssl_mode' => 'disabled',
234 'message_broker' => {
235 'hostname' => 'localhost',
237 'username' => 'guest',
238 'password' => 'guest',
243 is_deeply( $got, $expected, 'File read correctly' );
245 # Reading a Perl script as XML should fail hopefully
246 eval { Koha::Config->read_from_file("$Bin/$Script") };
247 like( $@, qr{.*Error reading file.*}, 'File failing to read raises warning');
250 subtest 'get_instance' => sub {
253 my $config = Koha::Config->get_instance($config_filepath);
254 isa_ok($config, 'Koha::Config', 'get_instance returns a Koha::Config object');
255 my $same_config = Koha::Config->get_instance($config_filepath);
256 is($config, $same_config, '2nd call to get_instance returns the same object');
258 local $ENV{KOHA_CONF} = $config_filepath;
259 my $default_config = Koha::Config->get_instance;
260 is($default_config, $config, 'get_instance without parameters reads $KOHA_CONF');
263 subtest 'get' => sub {
266 my $config = Koha::Config->get_instance($config_filepath);
269 $config->get('biblioserver', 'listen'),
270 { content => 'unix:/home/koha/var/run/zebradb/bibliosocket' },
274 $config->get('biblioserver', 'server'),
276 'listenref' => 'biblioserver',
277 'directory' => '/home/koha/var/lib/zebradb/biblios',
278 'config' => '/home/koha/etc/zebradb/zebra-biblios-dom.cfg',
279 'cql2rpn' => '/home/koha/etc/zebradb/pqf.properties',
282 'href' => '/home/koha/etc/zebradb/retrieval-info-bib-dom.xml',
283 'xmlns:xi' => 'http://www.w3.org/2001/XInclude'
286 'xmlns:xi' => 'http://www.w3.org/2001/XInclude',
287 'href' => '/home/koha/etc/zebradb/explain-biblios.xml'
294 $config->get('biblioserver', 'serverinfo'),
296 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties',
297 'user' => 'kohauser',
298 'password' => 'zebrastripes',
302 is($config->get('db_scheme'), 'mysql');
303 is($config->get('ca'), '');
305 is($config->get('unicorn'), undef, 'returns undef if key does not exist');
306 is_deeply([$config->get('unicorn')], [undef], 'returns undef even in list context');