From: Stevan Little Date: Mon, 14 Dec 2009 02:52:51 +0000 (-0500) Subject: adding test for custom session subclass X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Session.git;a=commitdiff_plain;h=ecc6a7ed63a2c3c15593c19fdf685a92e9126903 adding test for custom session subclass --- diff --git a/t/011_middleware_w_custom_session.t b/t/011_middleware_w_custom_session.t new file mode 100644 index 0000000..4482078 --- /dev/null +++ b/t/011_middleware_w_custom_session.t @@ -0,0 +1,49 @@ +use Plack::Test; +use Plack::Middleware::Session; +use Test::More; +use HTTP::Request::Common; +use HTTP::Cookies; + +{ + package My::Custom::Session; + use strict; + use warnings; + use parent 'Plack::Session'; +} + +my $app = sub { + my $env = shift; + + isa_ok($env->{'plack.session'}, 'My::Custom::Session'); + + my $counter = $env->{'plack.session'}->get('counter') || 0; + + my $body = "Counter=$counter"; + $counter++; + $env->{'plack.session'}->set(counter => $counter); + + return [ 200, [], [ $body ] ]; +}; + +$app = Plack::Middleware::Session->wrap( + $app, + session_class => 'My::Custom::Session' +); + +test_psgi $app, sub { + my $cb = shift; + + my $jar = HTTP::Cookies->new; + + my $res = $cb->(GET "http://localhost/"); + is $res->content, "Counter=0"; + $jar->extract_cookies($res); + + my $req = GET "http://localhost/"; + $jar->add_cookie_header($req); + $res = $cb->($req); + is $res->content, "Counter=1"; +}; + +done_testing; +