X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_redirect_body.t;fp=t%2Flive_redirect_body.t;h=b6d4c96f7b2f5ca94fc88ece176238bfb138cec4;hb=13e3699abaac396381c0dc9283033223ce2e310f;hp=0000000000000000000000000000000000000000;hpb=23a34adfebeb887fb66214421cb3064f83e796cd;p=catagits%2FCatalyst-Runtime.git diff --git a/t/live_redirect_body.t b/t/live_redirect_body.t new file mode 100644 index 0000000..b6d4c96 --- /dev/null +++ b/t/live_redirect_body.t @@ -0,0 +1,48 @@ +use FindBin; +use lib "$FindBin::Bin/lib"; +use Catalyst::Test 'TestApp', {default_host => 'default.com'}; +use Catalyst::Request; + +use Test::More; + +# test redirect +{ + my $request = + HTTP::Request->new( GET => 'http://localhost:3000/test_redirect' ); + + ok( my $response = request($request), 'Request' ); + is( $response->code, 302, 'Response Code' ); + + # When no body and no content_type has been set, redirecting should set both. + is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' ); + like( $response->content, qr//, 'Content contains HTML body' ); +} + +# test redirect without a body and but with a content_type set explicitly by the developer +{ + my $request = + HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_contenttype' ); + + ok( my $response = request($request), 'Request' ); + is( $response->code, 302, 'Response Code' ); + + # When the developer has not set content body, we set it. The content type must always match the body, so it should be overwritten. + is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' ); + like( $response->content, qr//, 'Content contains HTML body' ); +} + +# test redirect without a body and but with a content_type set explicitly by the developer +{ + my $request = + HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_content' ); + + ok( my $response = request($request), 'Request' ); + is( $response->code, 302, 'Response Code' ); + + # When the developer sets both the content body and content type, the set content body and content_type should get through. + is( $response->header( 'Content-Type' ), 'text/plain', 'Content Type' ); + like( $response->content, qr/kind sir/, 'Content contains content set by the Controller' ); +} + +done_testing; +