use Test::More;
use Test::Exception;
+use Plack::Middleware::Session;
sub run_all_tests {
my %params = @_;
response_test
]};
+ my $m = Plack::Middleware::Session->new(state => $state, store => $storage);
+
$response_test = sub {
my ($response, $session_id, $check_expired) = @_;
};
{
my $r = $request_creator->();
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
push @sids, $s->id;
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[0] ), { foo => 'bar', bar => 'baz' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { foo => 'bar', bar => 'baz' }, '... got the session dump we expected');
$response_test->( $resp, $sids[0] );
}
{
my $r = $request_creator->();
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
push @sids, $s->id;
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { foo => 'baz' }, '... got the session dump we expected');
$response_test->( $resp, $sids[1] );
}
{
my $r = $request_creator->({ plack_session => $sids[0] });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
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';
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[0] ), { bar => 'baz' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { bar => 'baz' }, '... got the session dump we expected');
$response_test->( $resp, $sids[0] );
}
{
my $r = $request_creator->({ plack_session => $sids[1] });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
is($s->id, $sids[1], '... got a basic session id');
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { foo => 'baz' }, '... got the session dump we expected');
$response_test->( $resp, $sids[1] );
}
{
my $r = $request_creator->({ plack_session => $sids[0] });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
is($s->id, $sids[0], '... got a basic session id');
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[0] ), { bar => 'baz', baz => 'gorch' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { bar => 'baz', baz => 'gorch' }, '... got the session dump we expected');
$response_test->( $resp, $sids[0] );
}
{
my $r = $request_creator->({ plack_session => $sids[0] });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
is($s->get('bar'), 'baz', '... got the bar value back successfully from session');
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[0] ), {}, '... got the session dump we expected');
+ is_deeply( $s->dump, {}, '... got the session dump we expected');
$response_test->( $resp, $sids[0], 1 );
}
{
my $r = $request_creator->({ plack_session => $sids[0] });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
push @sids, $s->id;
isnt($s->id, $sids[0], 'expired ... got a new session id');
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[2] ), {}, '... got the session dump we expected');
+ is_deeply( $s->dump, {}, '... got the session dump we expected');
$response_test->( $resp, $sids[2] );
}
{
my $r = $request_creator->({ plack_session => $sids[1] });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
+ my $s = Plack::Session->fetch_or_create($r, $m);
is($s->id, $sids[1], '... got a basic session id');
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { foo => 'baz' }, '... got the session dump we expected');
$response_test->( $resp, $sids[1] );
}
# wrong format session_id
my $r = $request_creator->({ plack_session => '../wrong' });
- my $s = Plack::Session->new(
- state => $state,
- store => $storage,
- request => $r,
- );
-
+ my $s = Plack::Session->fetch_or_create($r, $m);
isnt('../wrong' => $s->id, '... regenerate session id');
$s->finalize( $resp );
} '... finalized session successfully';
- is_deeply( $s->store->dump_session( $s->id ), { foo => 'baz' }, '... got the session dump we expected');
+ is_deeply( $s->dump, { foo => 'baz' }, '... got the session dump we expected');
$response_test->( $resp, $s );
}