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