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;
30 package SessionStoreTest;
31 use Catalyst qw/Session Session::State/;
34 our $VERSION = "0.01";
40 $c->sessionid($restored_session_id) if defined $restored_session_id;
41 $c->NEXT::prepare_cookies(@_);
44 sub create_session : Global {
45 my ( $self, $c ) = @_;
46 ok( !$c->sessionid, "no session id yet" );
47 ok( $c->session, "session created" );
48 ok( $c->sessionid, "with a session id" );
50 $restored_session_id = $c->sessionid;
52 $c->session->{magic} = "møøse";
55 sub recover_session : Global {
56 my ( $self, $c ) = @_;
57 ok( $c->sessionid, "session id exists" );
58 is( $c->sessionid, $restored_session_id,
59 "and is the one we saved in the last action" );
60 ok( $c->session, "a session exists" );
61 is( $c->session->{magic},
63 "and it contains what we put in on the last attempt" );
64 $c->delete_session("user logout");
65 $restored_session_id = undef;
68 sub after_session : Global {
69 my ( $self, $c ) = @_;
70 ok( !$c->sessionid, "no session id" );
71 ok( !$c->session->{magic}, "session data not restored" );
72 ok( !$c->session_delete_reason, "no reason for deletion" );
75 @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
82 package SessionStoreTest2;
83 use Catalyst qw/Session Session::State/;
92 $c->sessionid($restored_session_id) if defined $restored_session_id;
93 $c->NEXT::prepare_cookies(@_);
96 sub create_session : Global {
97 my ( $self, $c ) = @_;
99 $c->session->{magic} = "møøse";
101 $restored_session_id = $c->sessionid;
104 sub recover_session : Global {
105 my ( $self, $c ) = @_;
107 ok( !$c->sessionid, "no session id" );
110 $c->session_delete_reason,
112 "reason is that the session expired"
115 ok( !$c->session->{magic}, "no saved data" );
118 __PACKAGE__->config->{session}{expires} = 0;
120 @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
127 can_ok( $m, "get_session_data" );
128 can_ok( $m, "store_session_data" );
129 can_ok( $m, "delete_session_data" );
130 can_ok( $m, "delete_expired_sessions" );
135 use Catalyst::Test "SessionStoreTest";
137 # idiotic void context warning workaround
139 my $x = get("/create_session");
140 $x = get("/recover_session");
141 $x = get("/after_session");
147 use Catalyst::Test "SessionStoreTest2";
149 my $x = get("/create_session");
150 sleep 1; # let the session expire
151 $x = get("/recover_session");
163 Catalyst::Plugin::Session::Test::Store - Reusable sanity for session storage
170 use Catalyst::Plugin::Session::Test::Store (
171 backend => "FastMmap",
173 storage => "/tmp/foo",