7fd5962811234513b96c5f86e000d8e7872f12d4
[catagits/Web-Session.git] / t / middleware.t
1 use Plack::Test;
2 use Plack::Middleware::Session;
3 use Test::More;
4 use HTTP::Request::Common;
5 use HTTP::Cookies;
6
7 my $app = sub {
8     my $env = shift;
9     my $counter = $env->{'psgix.session'}->get('counter') || 0;
10
11     my $body = "Counter=$counter";
12     $counter++;
13     $env->{'psgix.session'}->set(counter => $counter);
14
15     return [ 200, [], [ $body ] ];
16 };
17
18 $app = Plack::Middleware::Session->wrap($app);
19
20 test_psgi $app, sub {
21     my $cb = shift;
22
23     my $jar = HTTP::Cookies->new;
24
25     my $res = $cb->(GET "http://localhost/");
26     is $res->content, "Counter=0";
27     $jar->extract_cookies($res);
28
29     my $req = GET "http://localhost/";
30     $jar->add_cookie_header($req);
31     use XXX;
32     $res = $cb->($req);
33     is $res->content, "Counter=1";
34 };
35
36 done_testing;
37