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