Add tests which should fail, but don't.
[catagits/Catalyst-Action-REST.git] / t / data-serializer.t
CommitLineData
7ad87df9 1use strict;
2use warnings;
6646fdc2 3use Test::More tests => 29;
7ad87df9 4use FindBin;
5
e601adda 6use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
7ad87df9 7use Test::Rest;
8
e601adda 9use_ok 'Catalyst::Test', 'Test::Serialize';
10
11my %ctypes =(
12 'text/x-data-dumper' => 'Data::Dumper' ,
13 'text/x-data-denter' => 'Data::Denter' ,
14 'text/x-data-taxi' => 'Data::Taxi' ,
15 'application/x-storable' => 'Storable' ,
16 'application/x-freezethaw' => 'FreezeThaw' ,
17 'text/x-config-general' => 'Config::General' ,
18 'text/x-php-serialization' => 'PHP::Serialization' ,
19 );
20
21my $has_serializer = eval "require Data::Serializer";
22
23foreach my $content_type (keys(%ctypes)) {
24 my $dso;
25 my $skip = 0;
26 my $loadclass = $ctypes{$content_type};
27 $loadclass =~ s/::/\//g;
28 $loadclass .= '.pm';
29 eval {
30 require $loadclass
31 };
32 if ($@) {
33 $skip = 1;
34 }
35 SKIP: {
36 skip "$ctypes{$content_type} not installed", 4 if $skip;
37 $dso = Data::Serializer->new( serializer => $ctypes{$content_type} );
38 my $t = Test::Rest->new( 'content_type' => $content_type );
39
40 my $monkey_template = { monkey => 'likes chicken!', };
41 my $mres = request( $t->get( url => '/monkey_get' ) );
42 ok( $mres->is_success, "GET $content_type succeeded" );
43 is_deeply( $dso->raw_deserialize( $mres->content ),
44 $monkey_template, "GET $content_type has the right data" );
45
46 my $post_data = { 'sushi' => 'is good for monkey', };
47 my $mres_post = request(
48 $t->post(
49 url => '/monkey_put',
50 data => $dso->raw_serialize($post_data)
51 )
52 );
53 ok( $mres_post->is_success, "POST $content_type succeeded" );
54 is_deeply(
55 $mres_post->content,
56 "is good for monkey",
57 "POST $content_type data matches"
58 );
59 }
60}
7ad87df9 61
621;