2efba7a115261790498c6b5cffababc687b51506
[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
14 my $storage         = Plack::Session::Store::Null->new;
15 my $state           = Plack::Session::State->new;
16 my $request_creator = sub {
17     open my $in, '<', \do { my $d };
18     my $env = {
19         'psgi.version'    => [ 1, 0 ],
20         'psgi.input'      => $in,
21         'psgi.errors'     => *STDERR,
22         'psgi.url_scheme' => 'http',
23         SERVER_PORT       => 80,
24         REQUEST_METHOD    => 'GET',
25     };
26     my $r = Plack::Request->new( $env );
27     $r->parameters( @_ );
28     $r;
29 };
30
31 {
32     my $r = $request_creator->();
33
34     my $s = Plack::Session->new(
35         state   => $state,
36         store   => $storage,
37         request => $r,
38     );
39
40     ok($s->id, '... got a session id');
41
42     ok(!$s->get('foo'), '... no value stored in foo for session');
43
44     lives_ok {
45         $s->set( foo => 'bar' );
46     } '... set the value successfully in session';
47
48     ok(!$s->get('foo'), '... still no value stored in foo for session (null store)');
49
50     lives_ok {
51         $s->remove('foo');
52     } '... removed the value successfully in session';
53
54     lives_ok {
55         $s->expire;
56     } '... expire session successfully';
57
58     my $resp = $r->new_response;
59
60     lives_ok {
61         $s->finalize( $resp );
62     } '... finalized session successfully';
63 }
64
65
66 done_testing;