3 use Test::More tests => 21;
5 use lib ( "$FindBin::Bin/../lib" );
7 use Catalyst::Request::REST;
11 my $request = Catalyst::Request::REST->new;
12 $request->{_context} = 'MockContext';
13 $request->headers( HTTP::Headers->new );
14 $request->parameters( {} );
15 $request->method('GET');
16 $request->content_type('text/foobar');
18 is_deeply( $request->accepted_content_types, [ 'text/foobar' ],
19 'content-type set in request headers is found' );
20 is( $request->preferred_content_type, 'text/foobar',
21 'preferred content type is text/foobar' );
22 ok( ! $request->accept_only, 'accept_only is false' );
23 ok( $request->accepts('text/foobar'), 'accepts text/foobar' );
24 ok( ! $request->accepts('text/html'), 'does not accept text/html' );
28 my $request = Catalyst::Request::REST->new;
29 $request->{_context} = 'MockContext';
30 $request->headers( HTTP::Headers->new );
31 $request->parameters( { 'content-type' => 'text/fudge' } );
32 $request->method('GET');
33 $request->content_type('text/foobar');
35 is_deeply( $request->accepted_content_types, [ 'text/foobar', 'text/fudge' ],
36 'content-type set in request headers and type in parameters is found' );
37 is( $request->preferred_content_type, 'text/foobar',
38 'preferred content type is text/foobar' );
39 ok( ! $request->accept_only, 'accept_only is false' );
40 ok( $request->accepts('text/foobar'), 'accepts text/foobar' );
41 ok( $request->accepts('text/fudge'), 'accepts text/fudge' );
42 ok( ! $request->accepts('text/html'), 'does not accept text/html' );
46 my $request = Catalyst::Request::REST->new;
47 $request->{_context} = 'MockContext';
48 $request->headers( HTTP::Headers->new );
49 $request->parameters( { 'content-type' => 'text/fudge' } );
50 $request->method('POST');
51 $request->content_type('text/foobar');
53 ok( ! $request->accepts('text/fudge'), 'content type in parameters is ignored for POST' );
57 my $request = Catalyst::Request::REST->new;
58 $request->{_context} = 'MockContext';
59 $request->headers( HTTP::Headers->new );
60 $request->parameters( {} );
61 $request->method('GET');
62 $request->headers->header(
64 # From Firefox 2.0 when it requests an html page
65 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
68 is_deeply( $request->accepted_content_types,
69 [ qw( text/xml application/xml application/xhtml+xml
75 'accept header is parsed properly' );
76 is( $request->preferred_content_type, 'text/xml',
77 'preferred content type is text/xml' );
78 ok( $request->accept_only, 'accept_only is true' );
79 ok( $request->accepts('text/html'), 'accepts text/html' );
80 ok( $request->accepts('image/png'), 'accepts image/png' );
81 ok( ! $request->accepts('image/svg'), 'does not accept image/svg' );
85 my $request = Catalyst::Request::REST->new;
86 $request->{_context} = 'MockContext';
87 $request->headers( HTTP::Headers->new );
88 $request->parameters( {} );
89 $request->method('GET');
90 $request->content_type('text/x-json');
91 $request->headers->header(
93 # From Firefox 2.0 when it requests an html page
94 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
97 is_deeply( $request->accepted_content_types,
99 text/xml application/xml application/xhtml+xml
105 'accept header is parsed properly, and content-type header has precedence over accept' );
106 ok( ! $request->accept_only, 'accept_only is false' );
110 my $request = Catalyst::Request::REST->new;
111 $request->{_context} = 'MockContext';
112 $request->headers( HTTP::Headers->new );
113 $request->parameters( {} );
114 $request->method('GET');
115 $request->content_type('text/x-json');
116 $request->headers->header(
117 'Accept' => 'text/plain,text/x-json',
120 is_deeply( $request->accepted_content_types,
124 'each type appears only once' );