Merge branch 'master' into gsoc_breadboard
[catagits/Catalyst-Runtime.git] / t / live_redirect_body.t
1 use FindBin;
2 use lib "$FindBin::Bin/lib";
3 use Catalyst::Test 'TestApp', {default_host => 'default.com'};
4 use Catalyst::Request;
5
6 use Test::More;
7
8 # test redirect
9 {
10     my $request  =
11       HTTP::Request->new( GET => 'http://localhost:3000/test_redirect' );
12
13     ok( my $response = request($request), 'Request' );
14     is( $response->code, 302, 'Response Code' );
15
16     # When no body and no content_type has been set, redirecting should set both.
17     is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
18     like( $response->content, qr/<body>/, 'Content contains HTML body' );
19 }
20
21 # test redirect without a body and but with a content_type set explicitly by the developer
22 {
23     my $request  =
24         HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_contenttype' );
25
26     ok( my $response = request($request), 'Request' );
27     is( $response->code, 302, 'Response Code' );
28
29     # When the developer has not set content body, we set it. The content type must always match the body, so it should be overwritten.
30     is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
31     like( $response->content, qr/<body>/, 'Content contains HTML body' );
32 }
33
34 # test redirect without a body and but with a content_type set explicitly by the developer
35 {
36     my $request  =
37         HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_content' );
38
39     ok( my $response = request($request), 'Request' );
40     is( $response->code, 302, 'Response Code' );
41
42     # When the developer sets both the content body and content type, the set content body and content_type should get through.
43     is( $response->header( 'Content-Type' ), 'text/plain', 'Content Type' );
44     like( $response->content, qr/kind sir/, 'Content contains content set by the Controller' );
45 }
46
47 done_testing;
48