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