Commit | Line | Data |
5a2e0210 |
1 | use strict; |
2 | use warnings; |
f0e3c221 |
3 | |
5a2e0210 |
4 | use Test::More; |
67a1cd50 |
5 | use Config::Any; |
f0e3c221 |
6 | use Config::Any::XML; |
7 | |
c2a19f63 |
8 | if ( !Config::Any::XML->is_supported && !$ENV{RELEASE_TESTING} ) { |
5a2e0210 |
9 | plan skip_all => 'XML format not supported'; |
10 | } |
11 | else { |
e0186698 |
12 | plan tests => 7; |
5a2e0210 |
13 | } |
f0e3c221 |
14 | |
5a2e0210 |
15 | { |
16 | my $config = Config::Any::XML->load( 't/conf/conf.xml' ); |
e0186698 |
17 | is_deeply $config, { |
18 | 'Component' => { |
19 | 'Controller::Foo' => { |
20 | 'foo' => 'bar' |
21 | }, |
22 | }, |
23 | 'name' => 'TestApp', |
24 | 'Model' => { |
25 | 'Model::Baz' => { |
26 | 'qux' => 'xyzzy', |
27 | }, |
28 | }, |
29 | }, 'config loaded'; |
f0e3c221 |
30 | } |
5770ffc0 |
31 | |
32 | # test invalid config |
9d569cf0 |
33 | SKIP: { |
dcfb1d1d |
34 | my $broken_libxml |
35 | = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; }; |
9d569cf0 |
36 | skip 'XML::LibXML < 1.58 has issues', 2 if $broken_libxml; |
37 | |
dcfb1d1d |
38 | local $SIG{ __WARN__ } = sub { }; # squash warnings from XML::Simple |
77f14cda |
39 | my $file = 't/invalid/conf.xml'; |
5770ffc0 |
40 | my $config = eval { Config::Any::XML->load( $file ) }; |
41 | |
e0186698 |
42 | is $config, undef, 'config load failed'; |
43 | isnt $@, '', 'error thrown'; |
5770ffc0 |
44 | } |
bb941906 |
45 | |
46 | # test conf file with array ref |
47 | { |
48 | my $file = 't/conf/conf_arrayref.xml'; |
49 | my $config = eval { Config::Any::XML->load( $file ) }; |
50 | |
e0186698 |
51 | is_deeply $config, { |
52 | 'indicator' => 'submit', |
53 | 'elements' => [ |
54 | { |
55 | 'label' => 'Label1', |
56 | 'type' => 'Text', |
57 | }, |
58 | { |
59 | 'label' => 'Label2', |
60 | 'type' => 'Text', |
61 | }, |
62 | ], |
63 | }, 'config loaded'; |
64 | is $@, '', 'no error thrown'; |
bb941906 |
65 | } |
67a1cd50 |
66 | |
67 | # parse error generated on invalid config |
68 | { |
69 | my $file = 't/invalid/conf.xml'; |
70 | my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; |
71 | |
e0186698 |
72 | is $config, undef, 'config load failed'; |
73 | isnt $@, '', 'error thrown'; |
67a1cd50 |
74 | } |
75 | |