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