X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-REST.git;a=blobdiff_plain;f=t%2F02-data-serializer.t;h=740a24e66912a4f04140cb63111dc6d219fece3a;hp=ffb8cdd200df78bf89a246971d85c9e8778e0cf0;hb=e601addaf89882fccbc824c1a53328f0d049b32b;hpb=17d910bd120ee243917756ae8c4281e621a4f986 diff --git a/t/02-data-serializer.t b/t/02-data-serializer.t index ffb8cdd..740a24e 100644 --- a/t/02-data-serializer.t +++ b/t/02-data-serializer.t @@ -1,34 +1,62 @@ use strict; use warnings; use Test::More qw(no_plan); -use Data::Serializer; use FindBin; -use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib"); +use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" ); use Test::Rest; -my $dso = Data::Serializer->new(serializer => 'Data::Dumper'); - -# Should use Data::Dumper, via Data::Serializer -my $t = Test::Rest->new('content_type' => 'text/x-data-dumper'); - -BEGIN { use_ok 'Catalyst::Test', 'SampleREST' } - -my $mres = request($t->get(url => '/monkey')); -# We should find the monkey -ok( $mres->is_success, 'GET the monkey succeeded' ); - -my $monkey_template = { - monkey => 'likes chicken!', -}; -my $monkey_data = $dso->raw_deserialize($mres->content); -is_deeply($monkey_data, $monkey_template, "GET returned the right data"); - -my $post_data = { - 'sushi' => 'is good for monkey', -}; -my $mres_post = request($t->post(url => '/monkey', data => $dso->raw_serialize($post_data))); -ok( $mres_post->is_success, "POST to the monkey succeeded"); -is_deeply($mres_post->content, $dso->raw_serialize($post_data), "POST data matches"); +use_ok 'Catalyst::Test', 'Test::Serialize'; + +my %ctypes =( + 'text/x-data-dumper' => 'Data::Dumper' , + 'text/x-data-denter' => 'Data::Denter' , + 'text/x-data-taxi' => 'Data::Taxi' , + 'application/x-storable' => 'Storable' , + 'application/x-freezethaw' => 'FreezeThaw' , + 'text/x-config-general' => 'Config::General' , + 'text/x-php-serialization' => 'PHP::Serialization' , + ); + +my $has_serializer = eval "require Data::Serializer"; + +foreach my $content_type (keys(%ctypes)) { + my $dso; + my $skip = 0; + my $loadclass = $ctypes{$content_type}; + $loadclass =~ s/::/\//g; + $loadclass .= '.pm'; + eval { + require $loadclass + }; + if ($@) { + $skip = 1; + } + SKIP: { + skip "$ctypes{$content_type} not installed", 4 if $skip; + $dso = Data::Serializer->new( serializer => $ctypes{$content_type} ); + my $t = Test::Rest->new( 'content_type' => $content_type ); + + my $monkey_template = { monkey => 'likes chicken!', }; + my $mres = request( $t->get( url => '/monkey_get' ) ); + ok( $mres->is_success, "GET $content_type succeeded" ); + is_deeply( $dso->raw_deserialize( $mres->content ), + $monkey_template, "GET $content_type has the right data" ); + + my $post_data = { 'sushi' => 'is good for monkey', }; + my $mres_post = request( + $t->post( + url => '/monkey_put', + data => $dso->raw_serialize($post_data) + ) + ); + ok( $mres_post->is_success, "POST $content_type succeeded" ); + is_deeply( + $mres_post->content, + "is good for monkey", + "POST $content_type data matches" + ); + } +} 1;