avoid perl warnings
[catagits/Web-Session.git] / t / 013_cookiestore.t
CommitLineData
d326e755 1use strict;
2use Test::More;
3use Test::Requires qw(Digest::HMAC_SHA1);
4use Plack::Test;
5use Plack::Middleware::Session::Cookie;
6use HTTP::Request::Common;
7use LWP::UserAgent;
8use HTTP::Cookies;
9
10$Plack::Test::Impl = 'Server';
11
12my $app = sub {
13 my $env = shift;
14 my $session = $env->{'psgix.session'};
15
4ff41723 16 my $counter = $session->{counter} || 0;
17 if ($session->{counter}++ >= 2) {
18 $env->{'psgix.session.options'}->{expire} = 1;
d326e755 19 }
20
21 return [ 200, [], [ "counter=$counter" ] ];
22};
23
24$app = Plack::Middleware::Session::Cookie->wrap($app, secret => "foobar");
25
26my $ua = LWP::UserAgent->new;
27$ua->cookie_jar( HTTP::Cookies->new );
28
29test_psgi ua => $ua, app => $app, client => sub {
30 my $cb = shift;
31
32 my $res = $cb->(GET "/");
33 is $res->content, "counter=0";
34
35 $res = $cb->(GET "/");
36 is $res->content, "counter=1";
37
38 $res = $cb->(GET "/");
39 is $res->content, "counter=2";
40
e4976d97 41 $res = $cb->(GET "/");
d326e755 42 is $res->content, "counter=0";
43};
44
45done_testing;