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; |