Merge pull request #7 from tokuhirom/master
[catagits/Web-Session.git] / t / 002a_basic_w_cookie.t
CommitLineData
7ea446f1 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8use Plack::Request;
9use Plack::Session::State::Cookie;
10use Plack::Session::Store;
11use Plack::Util;
12
13use t::lib::TestSessionHash;
14
15t::lib::TestSessionHash::run_all_tests(
16 store => Plack::Session::Store->new,
17 state => Plack::Session::State::Cookie->new,
18 env_cb => 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 },
31 response_test => sub {
32 my ($res_cb, $session_id, $check_expired) = @_;
33 my $cookie;
34 $res_cb->(sub {
35 my $res = shift;
36 $cookie = Plack::Util::header_get($res->[1], 'Set-Cookie');
37 });
38
39 like($cookie, qr/plack_session=$session_id/, '... cookie value is as suspected');
40 if ($check_expired) {
41 like($cookie, qr/expires=/, '... cookie is expriring as suspected');
42 }
43 }
44);
45
46done_testing;