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/;
60 our $VERSION = "123"; # Do not remove
67 sub create_session : Global {
68 my ( $self, $c ) = @_;
69 ok( !$c->session_is_valid, "no session id yet" );
70 ok( $c->session, "session created" );
71 ok( $c->session_is_valid, "with a session id" );
73 $c->session->{magic} = "møøse";
76 sub recover_session : Global {
77 my ( $self, $c ) = @_;
78 ok( $c->session_is_valid, "session id exists" );
79 is( $c->sessionid, our $session_id,
80 "and is the one we saved in the last action" );
81 ok( $c->session, "a session exists" );
82 is( $c->session->{magic},
84 "and it contains what we put in on the last attempt" );
85 $c->delete_session("user logout");
88 sub after_session : Global {
89 my ( $self, $c ) = @_;
90 ok( !$c->session_is_valid, "no session id" );
91 ok( !$c->session->{magic}, "session data not restored" );
92 ok( !$c->session_delete_reason, "no reason for deletion" );
95 @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
97 { __PACKAGE__->setup; }; # Extra block here is an INSANE HACK to get inlined constructor
98 # (i.e. to make B::Hooks::EndOfScope fire)
103 package # Hide from PAUSE
105 use Catalyst qw/Session SessionStateTest/;
108 our $VERSION = "123";
112 sub create_session : Global {
113 my ( $self, $c ) = @_;
115 $c->session->{magic} = "møøse";
118 sub recover_session : Global {
119 my ( $self, $c ) = @_;
121 ok( !$c->session_is_valid, "session is gone" );
124 $c->session_delete_reason,
126 "reason is that the session expired"
129 ok( !$c->session->{magic}, "no saved data" );
132 __PACKAGE__->config->{'Plugin::Session'}{expires} = 0;
134 @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
136 { __PACKAGE__->setup; }; # INSANE HACK (the block - as above)
141 can_ok( $m, "get_session_data" );
142 can_ok( $m, "store_session_data" );
143 can_ok( $m, "delete_session_data" );
144 can_ok( $m, "delete_expired_sessions" );
148 package # Hide from PAUSE
150 use Catalyst::Test "SessionStoreTest";
152 # idiotic void context warning workaround
154 my $x = get("/create_session");
155 $x = get("/recover_session");
156 $x = get("/after_session");
161 package # Hide fram PAUSE
163 use Catalyst::Test "SessionStoreTest2";
165 my $x = get("/create_session");
166 sleep 1; # let the session expire
167 $x = get("/recover_session");
179 Catalyst::Plugin::Session::Test::Store - Reusable sanity for session storage
186 use Catalyst::Plugin::Session::Test::Store (
187 backend => "FastMmap",
189 storage => "/tmp/foo",