to make git include the t/tmp dir
[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
13 use t::lib::TestSession;
14
15 t::lib::TestSession::run_all_tests(
16     store           => Plack::Session::Store->new,
17     state           => Plack::Session::State::Cookie->new,
18     request_creator => sub {
19         my $cookies = shift;
20         open my $in, '<', \do { my $d };
21         my $env = {
22             'psgi.version'    => [ 1, 0 ],
23             'psgi.input'      => $in,
24             'psgi.errors'     => *STDERR,
25             'psgi.url_scheme' => 'http',
26             SERVER_PORT       => 80,
27             REQUEST_METHOD    => 'GET',
28             HTTP_COOKIE       => join "; " => map { $_ . "=" . $cookies->{ $_ } } keys %$cookies,
29         };
30         return Plack::Request->new( $env );
31     },
32     response_test   => sub {
33         my ($response, $session_id, $check_expired) = @_;
34         is_deeply(
35             $response->cookies,
36             {
37                 plack_session => {
38                     value => $session_id,
39                     path  => '/',
40                     ($check_expired
41                         ? ( expires => '0' )
42                         : ())
43                 }
44             },
45             '... got the right cookies in the response'
46         );
47     }
48 );
49
50 done_testing;