From a01abfc600146d4da5972a530a07c62eb4cc35b1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 30 Apr 2021 17:11:14 +0200 Subject: [PATCH] Bug 28278: Add unit test for Koha::Config::read_from_file Signed-off-by: Victor Grousset/tuxayo --- t/Koha/Config.t | 229 +++++++++++++++++++++++++++++++----- t/data/koha-conf.xml | 269 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 471 insertions(+), 27 deletions(-) create mode 100644 t/data/koha-conf.xml diff --git a/t/Koha/Config.t b/t/Koha/Config.t index b4168b9528..ceaab6edd7 100755 --- a/t/Koha/Config.t +++ b/t/Koha/Config.t @@ -18,42 +18,217 @@ use Modern::Perl; use Test::More tests => 2; -use Test::MockModule; -use Test::Warn; - -use Carp; - -my $parsing_result = 'ok'; - -my $xml_simple = Test::MockModule->new('XML::Simple'); -$xml_simple->mock( - XMLin => sub { - if ( $parsing_result eq 'error' ) { - croak "Something"; - } else { - return "XML data"; - } - } -); +use FindBin qw($Bin $Script); use_ok('Koha::Config'); -subtest 'read_from_file() tests' => sub { +my $config_filepath = "$Bin/../data/koha-conf.xml"; - plan tests => 4; +subtest 'read_from_file() tests' => sub { + plan tests => 3; is( Koha::Config->read_from_file(undef), undef, "Undef parameter makes function return undef"); - $parsing_result = 'ok'; - - my $result = Koha::Config->read_from_file("SomeFile.xml"); - is( $result, 'XML data', 'File read correctly' ); - - $parsing_result = 'error'; + my $got = eval { Koha::Config->read_from_file($config_filepath) }; + my $expected = { + 'listen' => { + 'biblioserver' => { + 'content' => 'unix:/home/koha/var/run/zebradb/bibliosocket', + }, + 'authorityserver' => { + 'content' => 'unix:/home/koha/var/run/zebradb/authoritysocket', + }, + }, + 'server' => { + 'biblioserver' => { + 'listenref' => 'biblioserver', + 'directory' => '/home/koha/var/lib/zebradb/biblios', + 'config' => '/home/koha/etc/zebradb/zebra-biblios-dom.cfg', + 'cql2rpn' => '/home/koha/etc/zebradb/pqf.properties', + 'xi:include' => [ + { + 'href' => '/home/koha/etc/zebradb/retrieval-info-bib-dom.xml', + 'xmlns:xi' => 'http://www.w3.org/2001/XInclude' + }, + { + 'xmlns:xi' => 'http://www.w3.org/2001/XInclude', + 'href' => '/home/koha/etc/zebradb/explain-biblios.xml' + } + ], + }, + 'authorityserver' => { + 'listenref' => 'authorityserver', + 'directory' => '/home/koha/var/lib/zebradb/authorities', + 'config' => '/home/koha/etc/zebradb/zebra-authorities-dom.cfg', + 'cql2rpn' => '/home/koha/etc/zebradb/pqf.properties', + 'xi:include' => [ + { + 'xmlns:xi' => 'http://www.w3.org/2001/XInclude', + 'href' => '/home/koha/etc/zebradb/retrieval-info-auth-dom.xml' + }, + { + 'href' => '/home/koha/etc/zebradb/explain-authorities.xml', + 'xmlns:xi' => 'http://www.w3.org/2001/XInclude' + } + ], + }, + }, + 'serverinfo' => { + 'biblioserver' => { + 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties', + 'user' => 'kohauser', + 'password' => 'zebrastripes', + }, + 'authorityserver' => { + 'ccl2rpn' => '/home/koha/etc/zebradb/ccl.properties', + 'user' => 'kohauser', + 'password' => 'zebrastripes', + } + }, + 'config' => { + 'db_scheme' => 'mysql', + 'database' => 'koha', + 'hostname' => 'localhost', + 'port' => '3306', + 'user' => 'kohaadmin', + 'pass' => 'katikoan', + 'tls' => 'no', + 'ca' => '', + 'cert' => '', + 'key' => '', + 'biblioserver' => 'biblios', + 'biblioservershadow' => '1', + 'authorityserver' => 'authorities', + 'authorityservershadow' => '1', + 'pluginsdir' => '/home/koha/var/lib/plugins', + 'enable_plugins' => '0', + 'upload_path' => '', + 'tmp_path' => '', + 'intranetdir' => '/home/koha/src', + 'opacdir' => '/home/koha/src/opac', + 'opachtdocs' => '/home/koha/src/koha-tmpl/opac-tmpl', + 'intrahtdocs' => '/home/koha/src/koha-tmpl/intranet-tmpl', + 'includes' => '/home/koha/src/koha-tmpl/intranet-tmpl/prog/en/includes/', + 'logdir' => '/home/koha/var/log', + 'docdir' => '/home/koha/doc', + 'backupdir' => '/home/koha/var/spool', + 'mana_config' => 'https://mana-kb.koha-community.org', + 'backup_db_via_tools' => '0', + 'backup_conf_via_tools' => '0', + 'install_log' => '/home/koha/misc/koha-install-log', + 'useldapserver' => '0', + 'useshibboleth' => '0', + 'zebra_lockdir' => '/home/koha/var/lock/zebradb', + 'lockdir' => '__LOCK_DIR__', + 'use_zebra_facets' => '1', + 'zebra_max_record_size' => '1024', + 'log4perl_conf' => '/home/koha/etc/log4perl.conf', + 'memcached_servers' => '127.0.0.1:11211', + 'memcached_namespace' => 'KOHA', + 'template_cache_dir' => '/tmp/koha', + 'api_secret_passphrase' => 'CHANGEME', + 'ttf' => { + 'font' => [ + { + 'type' => 'TR', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf', + }, + { + 'type' => 'TB', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf', + }, + { + 'type' => 'TI', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf', + }, + { + 'type' => 'TBI', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf', + }, + { + 'type' => 'C', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', + }, + { + 'type' => 'CB', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf', + }, + { + 'type' => 'CO', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf', + }, + { + 'type' => 'CBO', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf', + }, + { + 'type' => 'H', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', + }, + { + 'type' => 'HO', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf', + }, + { + 'type' => 'HB', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', + }, + { + 'type' => 'HBO', + 'content' => '/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf', + }, + ], + }, + 'sms_send_config' => '/home/koha/etc/sms_send/', + 'plack_max_requests' => '50', + 'plack_workers' => '2', + 'elasticsearch' => { + 'server' => [ + 'localhost:9200', + ], + 'index_name' => 'koha_master', + 'cxn_pool' => 'Static', + }, + 'interlibrary_loans' => { + 'backend_directory' => '/home/koha/src/Koha/Illbackends', + 'branch' => { + 'code' => 'CPL', + 'prefix' => 'ILL', + }, + 'staff_request_comments' => 'hide', + 'reply_date' => 'hide', + 'digital_recipient' => 'branch', + 'partner_code' => 'ILLLIBS', + }, + 'timezone' => '', + 'bcrypt_settings' => '__BCRYPT_SETTINGS__', + 'dev_install' => '0', + 'strict_sql_modes' => '0', + 'plugin_repos' => '', + 'koha_xslt_security' => '', + 'smtp_server' => { + 'host' => 'localhost', + 'port' => '25', + 'timeout' => '120', + 'ssl_mode' => 'disabled', + 'user_name' => '', + 'password' => '', + 'debug' => '0', + }, + 'message_broker' => { + 'hostname' => 'localhost', + 'port' => '61613', + 'username' => 'guest', + 'password' => 'guest', + 'vhost' => '', + }, + }, + }; + is_deeply( $got, $expected, 'File read correctly' ); - $result = eval {Koha::Config->read_from_file("SomeFile.xml")}; + # Reading a Perl script as XML should fail hopefully + eval { Koha::Config->read_from_file("$Bin/$Script") }; like( $@, qr{.*Error reading file.*}, 'File failing to read raises warning'); - is( $result, undef, 'Returns undef on error confition' ); }; diff --git a/t/data/koha-conf.xml b/t/data/koha-conf.xml new file mode 100644 index 0000000000..facbea97b3 --- /dev/null +++ b/t/data/koha-conf.xml @@ -0,0 +1,269 @@ + + + + + +unix:/home/koha/var/run/zebradb/bibliosocket +unix:/home/koha/var/run/zebradb/authoritysocket + + + + + + + /home/koha/var/lib/zebradb/biblios + /home/koha/etc/zebradb/zebra-biblios-dom.cfg + /home/koha/etc/zebradb/pqf.properties + + + + + /home/koha/etc/zebradb/ccl.properties + kohauser + zebrastripes + + + + + /home/koha/var/lib/zebradb/authorities + /home/koha/etc/zebradb/zebra-authorities-dom.cfg + /home/koha/etc/zebradb/pqf.properties + + + + + /home/koha/etc/zebradb/ccl.properties + kohauser + zebrastripes + + + + + + + + + + + mysql + koha + localhost + 3306 + kohaadmin + katikoan + no + + + + biblios + 1 + authorities + 1 + /home/koha/var/lib/plugins + 0 + + + /home/koha/src + /home/koha/src/opac + /home/koha/src/koha-tmpl/opac-tmpl + /home/koha/src/koha-tmpl/intranet-tmpl + /home/koha/src/koha-tmpl/intranet-tmpl/prog/en/includes/ + /home/koha/var/log + /home/koha/doc + /home/koha/var/spool + + + https://mana-kb.koha-community.org + + 0 + 0 + + + /home/koha/misc/koha-install-log + 0 + 0 + /home/koha/var/lock/zebradb + __LOCK_DIR__ + 1 + 1024 + /home/koha/etc/log4perl.conf + + + 127.0.0.1:11211 + KOHA + /tmp/koha + + + CHANGEME + + + + + + + /usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf + /usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf + + + + /home/koha/etc/sms_send/ + + + 50 + 2 + + + + + + + localhost:9200 + koha_master + + + Static + + + + + + + + + + + + + /home/koha/src/Koha/Illbackends + + + + CPL + + ILL + + + hide + + hide + + branch + + ILLLIBS + + + + + + + __BCRYPT_SETTINGS__ + + + 0 + 0 + + + + + + + + + + localhost + 25 + 120 + disabled + + + 0 + + + + localhost + 61613 + guest + guest + + + + + -- 2.31.1