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; |
7ea446f1 |
9 | my $counter = $env->{'psgix.session'}->{'counter'} || 0; |
ecc6a7ed |
10 | |
11 | my $body = "Counter=$counter"; |
12 | $counter++; |
7ea446f1 |
13 | $env->{'psgix.session'}->{counter} = $counter; |
ecc6a7ed |
14 | |
15 | return [ 200, [], [ $body ] ]; |
16 | }; |
17 | |
7ea446f1 |
18 | $app = Plack::Middleware::Session->wrap($app); |
ecc6a7ed |
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); |
31 | $res = $cb->($req); |
32 | is $res->content, "Counter=1"; |
33 | }; |
34 | |
35 | done_testing; |
36 | |