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