X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=t%2F54-xml.t;h=0fc6fd97cdb0c47476e1a898e78b6c9b8341c417;hp=c8f94e963be6dd401f416f6171a3b8a6b8ffaae1;hb=df8a40c5ea67b2d8a89d654bdda7c538afe8f6b6;hpb=572501abb2165014af8973bf9a4aa1f8a522356d diff --git a/t/54-xml.t b/t/54-xml.t index c8f94e9..0fc6fd9 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -1,11 +1,75 @@ -use Test::More tests => 2; - -use Config::Any::XML; - -my $config = eval { Config::Any::XML->load( 't/conf/conf.xml' ) }; - -SKIP: { - skip "Couldn't Load XML plugin", 2 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); -} +use strict; +use warnings; + +use Test::More; +use Config::Any; +use Config::Any::XML; + +if ( !Config::Any::XML->is_supported ) { + plan skip_all => 'XML format not supported'; +} +else { + plan tests => 7; +} + +{ + my $config = Config::Any::XML->load( 't/conf/conf.xml' ); + is_deeply $config, { + 'Component' => { + 'Controller::Foo' => { + 'foo' => 'bar' + }, + }, + 'name' => 'TestApp', + 'Model' => { + 'Model::Baz' => { + 'qux' => 'xyzzy', + }, + }, + }, 'config loaded'; +} + +# test invalid config +SKIP: { + my $broken_libxml + = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; }; + skip 'XML::LibXML < 1.58 has issues', 2 if $broken_libxml; + + local $SIG{ __WARN__ } = sub { }; # squash warnings from XML::Simple + my $file = 't/invalid/conf.xml'; + my $config = eval { Config::Any::XML->load( $file ) }; + + is $config, undef, 'config load failed'; + isnt $@, '', 'error thrown'; +} + +# test conf file with array ref +{ + my $file = 't/conf/conf_arrayref.xml'; + my $config = eval { Config::Any::XML->load( $file ) }; + + is_deeply $config, { + 'indicator' => 'submit', + 'elements' => [ + { + 'label' => 'Label1', + 'type' => 'Text', + }, + { + 'label' => 'Label2', + 'type' => 'Text', + }, + ], + }, 'config loaded'; + is $@, '', 'no error thrown'; +} + +# parse error generated on invalid config +{ + my $file = 't/invalid/conf.xml'; + my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; + + is $config, undef, 'config load failed'; + isnt $@, '', 'error thrown'; +} +