Rewrote all the tests and now all tests pass!
[catagits/Web-Session.git] / t / 011_middleware_w_custom_session.t
CommitLineData
ecc6a7ed 1use Plack::Test;
2use Plack::Middleware::Session;
3use Test::More;
4use HTTP::Request::Common;
5use HTTP::Cookies;
6
ecc6a7ed 7my $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
26test_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
41done_testing;
42