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 | |
ecc6a7ed |
7 | my $app = sub { |
8 | my $env = shift; |
9 | |
85265792 |
10 | isa_ok($env->{'plack.session'}, 't::MyCustomSession'); |
ecc6a7ed |
11 | |
85265792 |
12 | my $counter = $env->{'plack.session'}->get('counter') || 0; |
ecc6a7ed |
13 | |
14 | my $body = "Counter=$counter"; |
15 | $counter++; |
85265792 |
16 | $env->{'plack.session'}->set(counter => $counter); |
ecc6a7ed |
17 | |
18 | return [ 200, [], [ $body ] ]; |
19 | }; |
20 | |
21 | $app = Plack::Middleware::Session->wrap( |
22 | $app, |
85265792 |
23 | session_class => 't::MyCustomSession' |
ecc6a7ed |
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 | |