X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=257946f3cbba2a9598afc66d81a585ec8fa69b0e;hb=f331b3e0957efa44b2e86ad76e7c5a1f6914b247;hp=cbb2ad11470a297942d2dc438f6ef999eaf3bce9;hpb=d94ab365abf40507acb251020d7657016ab94933;p=catagits%2FWeb-Session.git diff --git a/t/001_basic.t b/t/001_basic.t index cbb2ad1..257946f 100755 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -4,206 +4,31 @@ use strict; use warnings; use Test::More; -use Test::Exception; use Plack::Request; - use Plack::Session; use Plack::Session::State; use Plack::Session::Store; -sub request { - open my $in, '<', \do { my $d }; - my $env = { - 'psgi.version' => [ 1, 0 ], - 'psgi.input' => $in, - 'psgi.errors' => *STDERR, - 'psgi.url_scheme' => 'http', - SERVER_PORT => 80, - REQUEST_METHOD => 'GET', - }; - my $r = Plack::Request->new( $env ); - $r->parameters( @_ ); - $r; -} - -my $storage = Plack::Session::Store->new; -my $state = Plack::Session::State->new; - -my @sids; -{ - my $r = request(); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - push @sids, $s->id; - - ok(!$s->get('foo'), '... no value stored in foo for session'); - - lives_ok { - $s->set( foo => 'bar' ); - } '... set the value successfully in session'; - - is($s->get('foo'), 'bar', '... got the foo value back successfully from session'); - - my $resp = $r->new_response; - - lives_ok { - $s->finalize( $resp ); - } '... finalized session successfully'; -} - -{ - my $r = request(); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - push @sids, $s->id; - - isnt($sids[0], $sids[1], "no same Session ID"); - ok(!$s->get('foo'), '... no value stored for foo in session'); - - lives_ok { - $s->set( foo => 'baz' ); - } '... set the value successfully'; - - is($s->get('foo'), 'baz', '... got the foo value back successfully from session'); - - my $resp = $r->new_response; - - lives_ok { - $s->finalize( $resp ); - } '... finalized session successfully'; -} - -{ - my $r = request({ plack_session => $sids[0] }); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - is($s->id, $sids[0], '... got a basic session id'); - - is($s->get('foo'), 'bar', '... got the value for foo back successfully from session'); - - lives_ok { - $s->remove( 'foo' ); - } '... removed the foo value successfully from session'; - - ok(!$s->get('foo'), '... no value stored for foo in session'); - - my $resp = $r->new_response; - - lives_ok { - $s->finalize( $resp ); - } '... finalized session successfully'; -} - - -{ - my $r = request({ plack_session => $sids[1] }); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - is($s->id, $sids[1], '... got a basic session id'); - - is($s->get('foo'), 'baz', '... got the foo value back successfully from session'); - - my $resp = $r->new_response; - - lives_ok { - $s->finalize( $resp ); - } '... finalized session successfully'; -} - -{ - my $r = request({ plack_session => $sids[0] }); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - is($s->id, $sids[0], '... got a basic session id'); - - ok(!$s->get('foo'), '... no value stored for foo in session'); - - lives_ok { - $s->set( bar => 'baz' ); - } '... set the bar value successfully in session'; - - my $resp = $r->new_response; - - lives_ok { - $s->finalize( $resp ); - } '... finalized session successfully'; -} - -{ - my $r = request({ plack_session => $sids[0] }); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - is($s->get('bar'), 'baz', '... got the bar value back successfully from session'); - - lives_ok { - $s->expire; - } '... expired session successfully'; -} - -{ - my $r = request({ plack_session => $sids[0] }); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - push @sids, $s->id; - isnt($s->id, $sids[0], 'expired ... got a new session id'); - - ok(!$s->get('bar'), '... no bar value stored'); -} - -{ - my $r = request({ plack_session => $sids[1] }); - - my $s = Plack::Session->new( - state => $state, - store => $storage, - request => $r, - ); - - is($s->id, $sids[1], '... got a basic session id'); - - is($s->get('foo'), 'baz', '... got the foo value back successfully from session'); - - my $resp = $r->new_response; - - lives_ok { - $s->finalize( $resp ); - } '... finalized session successfully'; -} +use t::lib::TestSession; + +t::lib::TestSession::run_all_tests( + store => Plack::Session::Store->new, + state => Plack::Session::State->new, + request_creator => sub { + open my $in, '<', \do { my $d }; + my $env = { + 'psgi.version' => [ 1, 0 ], + 'psgi.input' => $in, + 'psgi.errors' => *STDERR, + 'psgi.url_scheme' => 'http', + SERVER_PORT => 80, + REQUEST_METHOD => 'GET', + }; + my $r = Plack::Request->new( $env ); + $r->parameters( @_ ); + $r; + }, +); done_testing;