Skip to content
This repository
tree: a67fa01f97
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 59 lines (43 sloc) 1.64 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
use Test::More import => ['!pass'];
use strict;
use warnings;
use Dancer;

plan skip_all => "XML::Simple is needed to run this tests"
    unless Dancer::ModuleLoader->load('XML::Simple');

plan skip_all => "XML::Parser or XML::SAX are needed to run this tests"
    unless Dancer::ModuleLoader->load('XML::Parser') or
           Dancer::ModuleLoader->load('XML::SAX');

plan tests => 13;

ok(setting('serializer' => 'XML'), "serializer XML loaded");
my $s = Dancer::Serializer->engine;

isa_ok($s, $_) for qw(
Dancer::Engine
Dancer::Serializer::Abstract
Dancer::Serializer::XML);

can_ok $s, qw(serialize deserialize);

my $data = { foo => 42 };
my $xml = $s->serialize($data);
like $xml, qr/foo="42"/, "data is correctly serialized";
my $data2 = $s->deserialize($xml);
is_deeply $data2, $data, "data is correctly deserialized";

is $s->content_type, 'text/xml', 'content type is ok';

# helpers

$xml = to_xml($data);
like $xml, qr/data foo="42"/, "data is correctly serialized";

$data2 = from_xml($xml);
is_deeply $data, {foo => 42}, "data is correctly deserialized";

$xml = to_xml($data, RootName => undef);
like $xml, qr/<foo>42<\/foo>/, "data is correctly serialized";

$data2 = from_xml($xml);
is $data2, 42, "data is correctly serialized";

$data = {
    task => {
        type => "files",
        continue => 1,
        action => 123,
        content => '46210660-b78f-11df-8d81-0800200c9a66',
        files => { file => [2131231231] }
    },
};

$xml = to_xml($data, RootName => undef, AttrIndent => 1);
like $xml, qr/type="files">46210660-b78f-11df-8d81-0800200c9a66<files>/, 'xml attributes are indented';
Something went wrong with that request. Please try again.