Bug 28278: Add unit test for Koha::Config::read_from_file
[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 => 2;
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' => '0',
121             'useshibboleth' => '0',
122             'zebra_lockdir' => '/home/koha/var/lock/zebradb',
123             'lockdir' => '__LOCK_DIR__',
124             'use_zebra_facets' => '1',
125             'zebra_max_record_size' => '1024',
126             'log4perl_conf' => '/home/koha/etc/log4perl.conf',
127             'memcached_servers' => '127.0.0.1:11211',
128             'memcached_namespace' => 'KOHA',
129             'template_cache_dir' => '/tmp/koha',
130             'api_secret_passphrase' => 'CHANGEME',
131             'ttf' => {
132                 'font' => [
133                     {
134                         'type' => 'TR',
135                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
136                     },
137                     {
138                         'type' => 'TB',
139                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf',
140                     },
141                     {
142                         'type' => 'TI',
143                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf',
144                     },
145                     {
146                         'type' => 'TBI',
147                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf',
148                     },
149                     {
150                         'type' => 'C',
151                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',
152                     },
153                     {
154                         'type' => 'CB',
155                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf',
156                     },
157                     {
158                         'type' => 'CO',
159                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf',
160                     },
161                     {
162                         'type' => 'CBO',
163                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf',
164                     },
165                     {
166                         'type' => 'H',
167                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
168                     },
169                     {
170                         'type' => 'HO',
171                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf',
172                     },
173                     {
174                         'type' => 'HB',
175                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',
176                     },
177                     {
178                         'type' => 'HBO',
179                         'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf',
180                     },
181                 ],
182             },
183             'sms_send_config' => '/home/koha/etc/sms_send/',
184             'plack_max_requests' => '50',
185             'plack_workers' => '2',
186             'elasticsearch' => {
187                 'server' => [
188                     'localhost:9200',
189                 ],
190                 'index_name' => 'koha_master',
191                 'cxn_pool' => 'Static',
192             },
193             'interlibrary_loans' => {
194                 'backend_directory' => '/home/koha/src/Koha/Illbackends',
195                 'branch' => {
196                     'code' => 'CPL',
197                     'prefix' => 'ILL',
198                 },
199                 'staff_request_comments' => 'hide',
200                 'reply_date' => 'hide',
201                 'digital_recipient' => 'branch',
202                 'partner_code' => 'ILLLIBS',
203             },
204             'timezone' => '',
205             'bcrypt_settings' => '__BCRYPT_SETTINGS__',
206             'dev_install' => '0',
207             'strict_sql_modes' => '0',
208             'plugin_repos' => '',
209             'koha_xslt_security' => '',
210             'smtp_server' => {
211                 'host' => 'localhost',
212                 'port' => '25',
213                 'timeout' => '120',
214                 'ssl_mode' => 'disabled',
215                 'user_name' => '',
216                 'password' => '',
217                 'debug' => '0',
218             },
219             'message_broker' => {
220                 'hostname' => 'localhost',
221                 'port' => '61613',
222                 'username' => 'guest',
223                 'password' => 'guest',
224                 'vhost' => '',
225             },
226         },
227     };
228     is_deeply( $got, $expected, 'File read correctly' );
229
230     # Reading a Perl script as XML should fail hopefully
231     eval { Koha::Config->read_from_file("$Bin/$Script") };
232     like( $@, qr{.*Error reading file.*}, 'File failing to read raises warning');
233 };
234