X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcatalyst-request-rest.t;h=44938973b27b31e62c689b8bfb7c322bedfa6c4b;hb=d6fb033c1dbd94c0d527ec53291af2c50a482e9d;hp=3fd4c092e504ad03935baee527000f33168153bd;hpb=9f16ba154ebe4bcdc84fa3a88782ea91a813b651;p=catagits%2FCatalyst-Action-Serialize-Data-Serializer.git diff --git a/t/catalyst-request-rest.t b/t/catalyst-request-rest.t index 3fd4c09..4493897 100644 --- a/t/catalyst-request-rest.t +++ b/t/catalyst-request-rest.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 24; use FindBin; use lib ( "$FindBin::Bin/../lib" ); @@ -112,6 +112,31 @@ use HTTP::Headers; $request->headers( HTTP::Headers->new ); $request->parameters( {} ); $request->method('GET'); + $request->content_type('application/json'); + $request->headers->header( + 'Accept' => + # From Firefox 2.0 when it requests an html page + 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', + ); + + is_deeply( $request->accepted_content_types, + [ qw( application/json + text/xml application/xml application/xhtml+xml + image/png + text/html + text/plain + */* + ) ], + 'accept header is parsed properly, and content-type header has precedence over accept' ); + ok( ! $request->accept_only, 'accept_only is false' ); +} + +{ + my $request = Catalyst::Request::REST->new; + $request->{_context} = 'MockContext'; + $request->headers( HTTP::Headers->new ); + $request->parameters( {} ); + $request->method('GET'); $request->content_type('text/x-json'); $request->headers->header( 'Accept' => 'text/plain,text/x-json', @@ -124,6 +149,23 @@ use HTTP::Headers; 'each type appears only once' ); } +{ + my $request = Catalyst::Request::REST->new; + $request->{_context} = 'MockContext'; + $request->headers( HTTP::Headers->new ); + $request->parameters( {} ); + $request->method('GET'); + $request->content_type('application/json'); + $request->headers->header( + 'Accept' => 'text/plain,application/json', + ); + + is_deeply( $request->accepted_content_types, + [ qw( application/json + text/plain + ) ], + 'each type appears only once' ); +} package MockContext;