Adding some additional docs and VERSION, AUTHORITY stuff
[catagits/Web-Session.git] / t / 011_middleware_w_custom_session.t
CommitLineData
ecc6a7ed 1use Plack::Test;
2use Plack::Middleware::Session;
3use Test::More;
4use HTTP::Request::Common;
5use HTTP::Cookies;
6
7{
8 package My::Custom::Session;
9 use strict;
10 use warnings;
11 use parent 'Plack::Session';
12}
13
14my $app = sub {
15 my $env = shift;
16
17 isa_ok($env->{'plack.session'}, 'My::Custom::Session');
18
19 my $counter = $env->{'plack.session'}->get('counter') || 0;
20
21 my $body = "Counter=$counter";
22 $counter++;
23 $env->{'plack.session'}->set(counter => $counter);
24
25 return [ 200, [], [ $body ] ];
26};
27
28$app = Plack::Middleware::Session->wrap(
29 $app,
30 session_class => 'My::Custom::Session'
31);
32
33test_psgi $app, sub {
34 my $cb = shift;
35
36 my $jar = HTTP::Cookies->new;
37
38 my $res = $cb->(GET "http://localhost/");
39 is $res->content, "Counter=0";
40 $jar->extract_cookies($res);
41
42 my $req = GET "http://localhost/";
43 $jar->add_cookie_header($req);
44 $res = $cb->($req);
45 is $res->content, "Counter=1";
46};
47
48done_testing;
49