Bug 9302: Use patron-title.inc
[koha.git] / t / Koha / Config.t
blobb4168b9528000ad902daa2fe7c4e18435c0c1b12
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 2;
21 use Test::MockModule;
22 use Test::Warn;
24 use Carp;
26 my $parsing_result = 'ok';
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";
39 use_ok('Koha::Config');
41 subtest 'read_from_file() tests' => sub {
43 plan tests => 4;
45 is( Koha::Config->read_from_file(undef), undef,
46 "Undef parameter makes function return undef");
48 $parsing_result = 'ok';
50 my $result = Koha::Config->read_from_file("SomeFile.xml");
51 is( $result, 'XML data', 'File read correctly' );
53 $parsing_result = 'error';
55 $result = eval {Koha::Config->read_from_file("SomeFile.xml")};
56 like( $@, qr{.*Error reading file.*}, 'File failing to read raises warning');
57 is( $result, undef, 'Returns undef on error confition' );