Add note about failing tests on remote servers because of LWP bug
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_response_cookies.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../lib";
8
9 use Test::More tests => 15;
10 use Catalyst::Test 'TestApp';
11 use HTTP::Headers::Util 'split_header_words';
12
13 my $expected = {
14     catalyst => [qw|catalyst cool path /bah|],
15     cool     => [qw|cool catalyst path /|]
16 };
17
18 {
19     ok( my $response = request('http://localhost/engine/response/cookies/one'),
20         'Request' );
21     ok( $response->is_success, 'Response Successful 2xx' );
22     is( $response->content_type, 'text/plain', 'Response Content-Type' );
23     is( $response->header('X-Catalyst-Action'),
24         'engine/response/cookies/one', 'Test Action' );
25
26     my $cookies = {};
27
28     for my $string ( $response->header('Set-Cookie') ) {
29         my $cookie = [ split_header_words $string];
30         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
31     }
32
33     is_deeply( $cookies, $expected, 'Response Cookies' );
34 }
35
36 # XXX: these fail on remote servers due to LWP max_redirect 0 bug:
37 # http://rt.cpan.org/Ticket/Display.html?id=40260
38 {
39     ok( my $response = request('http://localhost/engine/response/cookies/two'),
40         'Request' );
41     ok( $response->is_redirect, 'Response Redirection 3xx' );
42     is( $response->code, 302, 'Response Code' );
43     is( $response->header('X-Catalyst-Action'),
44         'engine/response/cookies/two', 'Test Action' );
45
46     my $cookies = {};
47
48     for my $string ( $response->header('Set-Cookie') ) {
49         my $cookie = [ split_header_words $string];
50         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
51     }
52
53     is_deeply( $cookies, $expected, 'Response Cookies' );
54 }
55
56 {
57     ok( my $response = request('http://localhost/engine/response/cookies/three'),
58         'Request' );
59     ok( $response->is_success, 'Response Successful 2xx' );
60     is( $response->content_type, 'text/plain', 'Response Content-Type' );
61     is( $response->header('X-Catalyst-Action'),
62         'engine/response/cookies/three', 'Test Action' );
63
64     my $cookies = {};
65
66     for my $string ( $response->header('Set-Cookie') ) {
67         my $cookie = [ split_header_words $string];
68         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
69     }
70
71     is_deeply( $cookies, {
72         hash => [ qw(hash a&b&c path /) ],
73         this_is_the_real_name => [ qw(this_is_the_real_name foo&bar path /) ], # not "object"
74     }, 'Response Cookies' );
75 }