Reworked Session to make the expiration a store's responsibility and
[catagits/Web-Session.git] / t / 006_basic_w_null_store.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use Plack::Request;
10 use Plack::Session;
11 use Plack::Session::State;
12 use Plack::Session::Store::Null;
13 use Plack::Middleware::Session;
14
15 my $storage         = Plack::Session::Store::Null->new;
16 my $state           = Plack::Session::State->new;
17 my $m               = Plack::Middleware::Session->new(store => $storage, state => $state);
18 my $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
36     my $s = Plack::Session->fetch_or_create($r, $m);
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
46     is($s->get('foo'), 'bar', 'No store, but session works in the session lifetime');
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 {
59         $s->finalize( $m, $resp );
60     } '... finalized session successfully';
61 }
62
63
64 done_testing;