0b266e598b4a68ff2dae223da0f21b7bd9d18bdd
[catagits/Web-Session.git] / t / 011_middleware_w_custom_session.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
10     isa_ok($env->{'plack.session'}, 't::MyCustomSession');
11
12     my $counter = $env->{'plack.session'}->get('counter') || 0;
13
14     my $body = "Counter=$counter";
15     $counter++;
16     $env->{'plack.session'}->set(counter => $counter);
17
18     return [ 200, [], [ $body ] ];
19 };
20
21 $app = Plack::Middleware::Session->wrap(
22     $app,
23     session_class => 't::MyCustomSession'
24 );
25
26 test_psgi $app, sub {
27     my $cb = shift;
28
29     my $jar = HTTP::Cookies->new;
30
31     my $res = $cb->(GET "http://localhost/");
32     is $res->content, "Counter=0";
33     $jar->extract_cookies($res);
34
35     my $req = GET "http://localhost/";
36     $jar->add_cookie_header($req);
37     $res = $cb->($req);
38     is $res->content, "Counter=1";
39 };
40
41 done_testing;
42