merged conflicts
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_response_cookies.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use lib "$FindBin::Bin/../lib";
6
7 use Test::More;
8 use Catalyst::Test 'TestApp';
9 use HTTP::Headers::Util 'split_header_words';
10
11 my $expected = {
12     catalyst => [qw|catalyst cool path /bah|],
13     cool     => [qw|cool catalyst path /|]
14 };
15
16 {
17     ok( my $response = request('http://localhost/engine/response/cookies/one'),
18         'Request' );
19     ok( $response->is_success, 'Response Successful 2xx' );
20     is( $response->content_type, 'text/plain', 'Response Content-Type' );
21     is( $response->header('X-Catalyst-Action'),
22         'engine/response/cookies/one', 'Test Action' );
23
24     my $cookies = {};
25
26     for my $string ( $response->header('Set-Cookie') ) {
27         my $cookie = [ split_header_words $string];
28         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
29     }
30
31     is_deeply( $cookies, $expected, 'Response Cookies' );
32 }
33
34 {
35     ok( my $response = request('http://localhost/engine/response/cookies/two'),
36         'Request' );
37     ok( $response->is_redirect, 'Response Redirection 3xx' );
38     is( $response->code, 302, 'Response Code' );
39     is( $response->header('X-Catalyst-Action'),
40         'engine/response/cookies/two', 'Test Action' );
41
42     my $cookies = {};
43
44     for my $string ( $response->header('Set-Cookie') ) {
45         my $cookie = [ split_header_words $string];
46         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
47     }
48
49     is_deeply( $cookies, $expected, 'Response Cookies' );
50 }
51
52 {
53     ok( my $response = request('http://localhost/engine/response/cookies/three'),
54         'Request' );
55     ok( $response->is_success, 'Response Successful 2xx' );
56     is( $response->content_type, 'text/plain', 'Response Content-Type' );
57     is( $response->header('X-Catalyst-Action'),
58         'engine/response/cookies/three', 'Test Action' );
59
60     my $cookies = {};
61
62     for my $string ( $response->header('Set-Cookie') ) {
63         my $cookie = [ split_header_words $string];
64         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
65     }
66
67     is_deeply( $cookies, {
68         hash => [ qw(hash a&b&c path /) ],
69         this_is_the_real_name => [ qw(this_is_the_real_name foo&bar path /) ], # not "object"
70     }, 'Response Cookies' );
71 }
72
73 {
74     my $response;
75     ok( $response = request('http://localhost/engine/response/cookies/four'),
76         'Request' );
77     ok( $response->is_success, 'Response Successful 2xx' ) or diag explain $response;
78     is( $response->content_type, 'text/plain', 'Response Content-Type' );
79     is( $response->header('X-Catalyst-Action'),
80         'engine/response/cookies/four', 'Test Action' );
81
82     my $cookies = {};
83
84     for my $string ( $response->header('Set-Cookie') ) {
85         my $cookie = [ split_header_words $string];
86         $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
87     }
88
89     is_deeply( $cookies, {
90         good => [qw|good good_cookie path /|],
91     }, 'Response Cookies' );
92 }
93
94 done_testing;
95