d3aa3d48b26cc487408689e70216befc64ca4351
[p5sagit/Config-Any.git] / t / 54-xml.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Config::Any;
6 use Config::Any::XML;
7
8 if ( !Config::Any::XML->is_supported && !$ENV{RELEASE_TESTING} ) {
9     plan skip_all => 'XML format not supported';
10 }
11 else {
12     plan tests => 7;
13 }
14
15 {
16     my $config = Config::Any::XML->load( 't/conf/conf.xml' );
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';
30 }
31
32 # test invalid config
33 SKIP: {
34     my $broken_libxml
35         = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; };
36     skip 'XML::LibXML < 1.58 has issues', 2 if $broken_libxml;
37
38     local $SIG{ __WARN__ } = sub { };    # squash warnings from XML::Simple
39     my $file = 't/invalid/conf.xml';
40     my $config = eval { Config::Any::XML->load( $file ) };
41
42     is $config, undef, 'config load failed';
43     isnt $@, '', 'error thrown';
44 }
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
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';
65 }
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
72     is $config, undef, 'config load failed';
73     isnt $@, '', 'error thrown';
74 }
75