View | Details | Raw Unified | Return to bug 11921
Collapse All | Expand All

(-)a/Koha/Config.pm (-1 / +18 lines)
Lines 34-40 my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml'; Link Here
34
# use C4::Context->config instead
34
# use C4::Context->config instead
35
sub read_from_file {
35
sub read_from_file {
36
    my ( $class, $file ) = @_;
36
    my ( $class, $file ) = @_;
37
    return XMLin($file, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
37
38
    return if not defined $file;
39
40
    my $xml;
41
    eval {
42
        $xml = XMLin(
43
            $file,
44
            keyattr => ['id'],
45
            forcearray => ['listen', 'server', 'serverinfo'],
46
            suppressempty => ''
47
        );
48
    };
49
50
    if ($@) {
51
        warn "Error reading file $file";
52
    }
53
54
    return $xml;
38
}
55
}
39
56
40
# Koha's main configuration file koha-conf.xml
57
# Koha's main configuration file koha-conf.xml
(-)a/t/Koha/Config.t (-1 / +62 lines)
Line 0 Link Here
0
- 
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 Test::MockModule;
22
use Test::Warn;
23
24
use Carp;
25
26
my $parsing_result = 'ok';
27
28
my $xml_simple = Test::MockModule->new('XML::Simple');
29
$xml_simple->mock(
30
    XMLin => sub {
31
        if ( $parsing_result eq 'error' ) {
32
            croak "Something";
33
        } else {
34
            return "XML data";
35
        }
36
    }
37
);
38
39
use_ok('Koha::Config');
40
41
subtest 'read_from_file() tests' => sub {
42
43
    plan tests => 4;
44
45
    is( Koha::Config->read_from_file(undef), undef,
46
        "Undef parameter makes function return undef");
47
48
    $parsing_result = 'ok';
49
50
    my $result = Koha::Config->read_from_file("SomeFile.xml");
51
    is( $result, 'XML data', 'File read correctly' );
52
53
    $parsing_result = 'error';
54
55
    warning_is
56
        {$result = Koha::Config->read_from_file("SomeFile.xml")}
57
        'Error reading file SomeFile.xml',
58
        'File failing to read raises warning';
59
    is( $result, undef, 'Returns undef on error confition' );
60
};
61
62
1;

Return to bug 11921