Skip test if we don't have the cookie state module yet
[catagits/Catalyst-Plugin-Session.git] / t / cat_test.t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use HTTP::Request::Common;
7
8 # setup library path
9 use FindBin qw($Bin);
10 use lib "$Bin/lib";
11
12 BEGIN {
13     plan skip_all => "Need Catalyst::Plugin::Session::State::Cookie"
14         unless do { local $@; eval { require Catalyst::Plugin::Session::State::Cookie; } };
15 }
16
17 use Catalyst::Test 'SessionTestApp';
18 my ($res, $c);
19
20 ($res, $c) = ctx_request(POST 'http://localhost/login', [username => 'bob', password => 's00p3r', remember => 1]);
21 is($res->code, 200, 'succeeded');
22 my $cookie = $res->header('Set-Cookie');
23 ok($cookie, 'Have a cookie');
24
25 # this checks that cookie persists across a redirect
26 ($res, $c) = ctx_request(GET 'http://localhost/do_redirect', Cookie => $cookie);
27 is($res->code, 302, 'redirected');
28 is($res->header('Location'), 'http://localhost/page', 'Redirected after do_redirect');
29 ok($res->header('Set-Cookie'), 'Cookie is still there after redirect');
30
31 done_testing;