Reworked Session to make the expiration a store's responsibility and
[catagits/Web-Session.git] / t / 006_basic_w_null_store.t
CommitLineData
9bb20750 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
8
9use Plack::Request;
10use Plack::Session;
11use Plack::Session::State;
12use Plack::Session::Store::Null;
4a0cb5a0 13use Plack::Middleware::Session;
9bb20750 14
15my $storage = Plack::Session::Store::Null->new;
16my $state = Plack::Session::State->new;
4a0cb5a0 17my $m = Plack::Middleware::Session->new(store => $storage, state => $state);
9bb20750 18my $request_creator = sub {
19 open my $in, '<', \do { my $d };
20 my $env = {
21 'psgi.version' => [ 1, 0 ],
22 'psgi.input' => $in,
23 'psgi.errors' => *STDERR,
24 'psgi.url_scheme' => 'http',
25 SERVER_PORT => 80,
26 REQUEST_METHOD => 'GET',
27 };
28 my $r = Plack::Request->new( $env );
29 $r->parameters( @_ );
30 $r;
31};
32
33{
34 my $r = $request_creator->();
35
4a0cb5a0 36 my $s = Plack::Session->fetch_or_create($r, $m);
9bb20750 37
38 ok($s->id, '... got a session id');
39
40 ok(!$s->get('foo'), '... no value stored in foo for session');
41
42 lives_ok {
43 $s->set( foo => 'bar' );
44 } '... set the value successfully in session';
45
4a0cb5a0 46 is($s->get('foo'), 'bar', 'No store, but session works in the session lifetime');
9bb20750 47
48 lives_ok {
49 $s->remove('foo');
50 } '... removed the value successfully in session';
51
52 lives_ok {
53 $s->expire;
54 } '... expire session successfully';
55
56 my $resp = $r->new_response;
57
58 lives_ok {
caf3bd90 59 $s->finalize( $m, $resp );
9bb20750 60 } '... finalized session successfully';
61}
62
63
64done_testing;