adding in tests for the raw HASH session
[catagits/Web-Session.git] / t / 014_cookiestore_again.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::Middleware::Session::Cookie;
10
11 use t::lib::TestSessionHash;
12
13 t::lib::TestSessionHash::run_all_tests(
14     middleware_create_cb => sub {
15         Plack::Middleware::Session::Cookie->wrap( $_[0], secret => "foobar" );
16     },
17     env_cb => sub {
18         my $cookies = shift;
19         open my $in, '<', \do { my $d };
20         my $env = {
21             'psgi.version'    => [ 1, 0 ],
22             'psgi.input'      => $in,
23             'psgi.errors'     => *STDERR,
24             'psgi.url_scheme' => 'http',
25             SERVER_PORT       => 80,
26             REQUEST_METHOD    => 'GET',
27             HTTP_COOKIE       => join "; " => map { $_ . "=" . $cookies->{ $_ } } keys %$cookies,
28         };
29     },
30     response_test   => sub {
31         my ($res_cb, $session_id, $check_expired) = @_;
32         my $cookie;
33         $res_cb->(sub {
34             my $res = shift;
35             $cookie = Plack::Util::header_get($res->[1], 'Set-Cookie');
36         });
37
38         like($cookie, qr/plack_session=$session_id/, '... cookie value is as suspected');
39         if ($check_expired) {
40             like($cookie, qr/expires=/, '... cookie is expriring as suspected');
41         }
42     }
43 );
44
45 done_testing;