cfab243c5db737088e0e1abf7fe7bcdacb50c7d5
[catagits/Web-Session.git] / t / 002_basic_w_cookie.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use Plack::Request;
9 use Plack::Session;
10 use Plack::Session::State::Cookie;
11 use Plack::Session::Store;
12 use Plack::Util;
13
14 use t::lib::TestSession;
15
16 t::lib::TestSession::run_all_tests(
17     store  => Plack::Session::Store->new,
18     state  => Plack::Session::State::Cookie->new,
19     env_cb => sub {
20         my $cookies = shift;
21         open my $in, '<', \do { my $d };
22         my $env = {
23             'psgi.version'    => [ 1, 0 ],
24             'psgi.input'      => $in,
25             'psgi.errors'     => *STDERR,
26             'psgi.url_scheme' => 'http',
27             SERVER_PORT       => 80,
28             REQUEST_METHOD    => 'GET',
29             HTTP_COOKIE       => join "; " => map { $_ . "=" . $cookies->{ $_ } } keys %$cookies,
30         };
31     },
32     response_test   => sub {
33         my ($res_cb, $session_id, $check_expired) = @_;
34         my $cookie;
35         $res_cb->(sub {
36             my $res = shift;
37             $cookie = Plack::Util::header_get($res->[1], 'Set-Cookie');
38         });
39
40         like $cookie, qr/plack_session=$session_id/;
41         if ($check_expired) {
42             like $cookie, qr/expires=/;
43         }
44     }
45 );
46
47 done_testing;