remove session_class and psgix.session per discussion on IRC :)
[catagits/Web-Session.git] / t / 010_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'}->{counter} || 0;
10
11     my $body = "Counter=$counter";
12     $env->{'psgix.session'}->{counter} = $counter + 1;
13
14     return [ 200, [], [ $body ] ];
15 };
16
17 $app = Plack::Middleware::Session->wrap($app);
18
19 test_psgi $app, sub {
20     my $cb = shift;
21
22     my $jar = HTTP::Cookies->new;
23
24     my $res = $cb->(GET "http://localhost/");
25     is $res->content, "Counter=0";
26     $jar->extract_cookies($res);
27
28     my $req = GET "http://localhost/";
29     $jar->add_cookie_header($req);
30     $res = $cb->($req);
31     is $res->content, "Counter=1";
32 };
33
34 done_testing;
35