Commit | Line | Data |
ecc6a7ed |
1 | use Plack::Test; |
2 | use Plack::Middleware::Session; |
3 | use Test::More; |
4 | use HTTP::Request::Common; |
5 | use HTTP::Cookies; |
6 | |
7 | { |
8 | package My::Custom::Session; |
9 | use strict; |
10 | use warnings; |
11 | use parent 'Plack::Session'; |
12 | } |
13 | |
14 | my $app = sub { |
15 | my $env = shift; |
16 | |
b84f31d0 |
17 | isa_ok($env->{'psgix.session'}, 'My::Custom::Session'); |
ecc6a7ed |
18 | |
b84f31d0 |
19 | my $counter = $env->{'psgix.session'}->get('counter') || 0; |
ecc6a7ed |
20 | |
21 | my $body = "Counter=$counter"; |
22 | $counter++; |
b84f31d0 |
23 | $env->{'psgix.session'}->set(counter => $counter); |
ecc6a7ed |
24 | |
25 | return [ 200, [], [ $body ] ]; |
26 | }; |
27 | |
28 | $app = Plack::Middleware::Session->wrap( |
29 | $app, |
30 | session_class => 'My::Custom::Session' |
31 | ); |
32 | |
33 | test_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 | |
48 | done_testing; |
49 | |