Merge pull request #7 from tokuhirom/master
[catagits/Web-Session.git] / t / 010_middleware.t
CommitLineData
fe1bfe7d 1use Plack::Test;
2use Plack::Middleware::Session;
3use Test::More;
4use HTTP::Request::Common;
5use HTTP::Cookies;
6
7my $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
8e447333 14 return [ 200, [ 'Content-Type', 'text/html' ], [ $body ] ];
fe1bfe7d 15};
16
c6a7260c 17$app = Plack::Middleware::Session->wrap($app);
fe1bfe7d 18
19test_psgi $app, sub {
20 my $cb = shift;
21
22 my $jar = HTTP::Cookies->new;
23
24 my $res = $cb->(GET "http://localhost/");
8e447333 25 is $res->content_type, 'text/html';
fe1bfe7d 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
35done_testing;
36