3 package Catalyst::Plugin::Session::Test::Store;
20 plan tests => 19 + ($args{extra_tests} || 0);
22 my $backend = $args{backend};
23 my $cfg = $args{config};
25 my $p = "Session::Store::$backend";
26 use_ok( my $m = "Catalyst::Plugin::$p" );
28 isa_ok( bless( {}, $m ), "Catalyst::Plugin::Session::Store" );
31 package # Hide from PAUSE
32 Catalyst::Plugin::SessionStateTest;
33 use base qw/Catalyst::Plugin::Session::State/;
39 ${ ref($c) . "::session_id" };
44 ${ ref($c) . "::session_id" } = $sid;
47 sub delete_session_id {
49 undef ${ ref($c) . "::session_id" };
55 package # Hide from PAUSE
57 use Catalyst qw/Session SessionStateTest/;
65 sub create_session : Global {
66 my ( $self, $c ) = @_;
67 ok( !$c->session_is_valid, "no session id yet" );
68 ok( $c->session, "session created" );
69 ok( $c->session_is_valid, "with a session id" );
71 $c->session->{magic} = "møøse";
74 sub recover_session : Global {
75 my ( $self, $c ) = @_;
76 ok( $c->session_is_valid, "session id exists" );
77 is( $c->sessionid, our $session_id,
78 "and is the one we saved in the last action" );
79 ok( $c->session, "a session exists" );
80 is( $c->session->{magic},
82 "and it contains what we put in on the last attempt" );
83 $c->delete_session("user logout");
86 sub after_session : Global {
87 my ( $self, $c ) = @_;
88 ok( !$c->session_is_valid, "no session id" );
89 ok( !$c->session->{magic}, "session data not restored" );
90 ok( !$c->session_delete_reason, "no reason for deletion" );
93 @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
100 package # Hide from PAUSE
102 use Catalyst qw/Session SessionStateTest/;
105 our $VERSION = "123";
109 sub create_session : Global {
110 my ( $self, $c ) = @_;
112 $c->session->{magic} = "møøse";
115 sub recover_session : Global {
116 my ( $self, $c ) = @_;
118 ok( !$c->session_is_valid, "session is gone" );
121 $c->session_delete_reason,
123 "reason is that the session expired"
126 ok( !$c->session->{magic}, "no saved data" );
129 __PACKAGE__->config->{session}{expires} = 0;
131 @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
138 can_ok( $m, "get_session_data" );
139 can_ok( $m, "store_session_data" );
140 can_ok( $m, "delete_session_data" );
141 can_ok( $m, "delete_expired_sessions" );
145 package # Hide from PAUSE
147 use Catalyst::Test "SessionStoreTest";
149 # idiotic void context warning workaround
151 my $x = get("/create_session");
152 $x = get("/recover_session");
153 $x = get("/after_session");
158 package # Hide fram PAUSE
160 use Catalyst::Test "SessionStoreTest2";
162 my $x = get("/create_session");
163 sleep 1; # let the session expire
164 $x = get("/recover_session");
176 Catalyst::Plugin::Session::Test::Store - Reusable sanity for session storage
183 use Catalyst::Plugin::Session::Test::Store (
184 backend => "FastMmap",
186 storage => "/tmp/foo",