Commit | Line | Data |
9bb20750 |
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; |
4a0cb5a0 |
13 | use Plack::Middleware::Session; |
9bb20750 |
14 | |
15 | my $storage = Plack::Session::Store::Null->new; |
16 | my $state = Plack::Session::State->new; |
4a0cb5a0 |
17 | my $m = Plack::Middleware::Session->new(store => $storage, state => $state); |
9bb20750 |
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 | |
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 | |
64 | done_testing; |