3 package Catalyst::Plugin::Session::Test::Store;
8 use Test::More tests => 19;
18 my $backend = $args{backend};
19 my $cfg = $args{config};
21 my $p = "Session::Store::$backend";
22 use_ok(my $m = "Catalyst::Plugin::$p");
24 isa_ok(bless({}, $m), "Catalyst::Plugin::Session::Store");
26 our $restored_session_id;
29 package SessionStoreTest;
30 use Catalyst qw/-Engine=Test Session Session::State/;
33 our $VERSION = "0.01";
39 $c->sessionid($restored_session_id) if defined $restored_session_id;
40 $c->NEXT::prepare_cookies(@_);
43 sub create_session : Global {
44 my ( $self, $c ) = @_;
45 ok(!$c->sessionid, "no session id yet");
46 ok($c->session, "session created");
47 ok($c->sessionid, "with a session id");
49 $restored_session_id = $c->sessionid;
51 $c->session->{magic} = "møøse";
54 sub recover_session : Global {
55 my ( $self, $c ) = @_;
56 ok($c->sessionid, "session id exists");
57 is($c->sessionid, $restored_session_id, "and is the one we saved in the last action");
58 ok($c->session, "a session exists");
59 is($c->session->{magic}, "møøse", "and it contains what we put in on the last attempt");
60 $c->delete_session("user logout");
61 $restored_session_id = undef;
64 sub after_session : Global {
65 my ( $self, $c ) = @_;
66 ok(!$c->sessionid, "no session id");
67 ok(!$c->session->{magic}, "session data not restored");
68 ok(!$c->session_delete_reason, "no reason for deletion");
71 @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
77 package SessionStoreTest2;
78 use Catalyst qw/-Engine=Test Session Session::State/;
87 $c->sessionid($restored_session_id) if defined $restored_session_id;
88 $c->NEXT::prepare_cookies(@_);
91 sub create_session : Global {
92 my ( $self, $c ) = @_;
94 $c->session->{magic} = "møøse";
96 $restored_session_id = $c->sessionid;
99 sub recover_session : Global {
100 my ( $self, $c ) = @_;
102 ok(!$c->sessionid, "no session id");
104 is($c->session_delete_reason, "session expired", "reason is that the session expired");
106 ok(!$c->session->{magic}, "no saved data");
109 __PACKAGE__->config->{session}{expires} = 0;
111 @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
118 can_ok($m, "get_session_data");
119 can_ok($m, "store_session_data");
120 can_ok($m, "delete_session_data");
121 can_ok($m, "delete_expired_sessions");
125 use Catalyst::Test "SessionStoreTest";
127 get("/create_session");
128 get("/recover_session");
129 get("/after_session");
134 use Catalyst::Test "SessionStoreTest2";
136 get("/create_session");
137 sleep 1; # let the session expire
138 get("/recover_session");
150 Catalyst::Plugin::Session::Test::Store - Reusable sanity for session storage
157 use Catalyst::Plugin::Session::Test::Store (
158 backend => "FastMmap",
160 storage => "/tmp/foo",