Session/Test/Store.pm untested

filter: Statementstmt 0.0% 0 / 125 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 27 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 164 CC 1 SCAR 6.9
CC
1
Cov
0%
import
2.0
get_session_id
2.0
set_session_id
2.0
CRAP 2.0
1 package Catalyst::Plugin::Session::Test::Store;
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.44';
7 $VERSION =~ tr/_//d;
8  
9 use utf8;
10  
11 use Test::More;
12 use File::Temp;
13 use File::Spec;
14  
15 use Catalyst ();
16  
17 sub import {
18 shift;
19 my %args = @_;
20  
21 plan tests => 19 + ($args{extra_tests} || 0);
22  
23 my $backend = $args{backend};
24 my $cfg = $args{config};
25  
26 my $p = "Session::Store::$backend";
27 use_ok( my $m = "Catalyst::Plugin::$p" );
28  
29 isa_ok( bless( {}, $m ), "Catalyst::Plugin::Session::Store" );
30  
31 {
32 package # Hide from PAUSE
33 Catalyst::Plugin::SessionStateTest;
34 use base qw/Catalyst::Plugin::Session::State/;
35  
36 no strict 'refs';
37  
38 sub get_session_id {
39 my $c = shift;
40 ${ ref($c) . "::session_id" };
41 }
42  
43 sub set_session_id {
44 my ( $c, $sid ) = @_;
45 ${ ref($c) . "::session_id" } = $sid;
46 }
47  
48 sub delete_session_id {
49 my $c = shift;
50 undef ${ ref($c) . "::session_id" };
51 }
52 }
53  
54 {
55  
56 package # Hide from PAUSE
57 SessionStoreTest;
58 use Catalyst qw/Session SessionStateTest/;
59 push our (@ISA), $m;
60  
61 our $VERSION # make unparseable
62 = "123"; # Do not remove
63  
64 use strict;
65 use warnings;
66  
67 use Test::More;
68  
69 sub create_session : Global {
70 my ( $self, $c ) = @_;
71 ok( !$c->session_is_valid, "no session id yet" );
72 ok( $c->session, "session created" );
73 ok( $c->session_is_valid, "with a session id" );
74  
75 $c->session->{magic} = "møøse";
76 }
77  
78 sub recover_session : Global {
79 my ( $self, $c ) = @_;
80 ok( $c->session_is_valid, "session id exists" );
81 is( $c->sessionid, our $session_id,
82 "and is the one we saved in the last action" );
83 ok( $c->session, "a session exists" );
84 is( $c->session->{magic},
85 "møøse",
86 "and it contains what we put in on the last attempt" );
87 $c->delete_session("user logout");
88 }
89  
90 sub after_session : Global {
91 my ( $self, $c ) = @_;
92 ok( !$c->session_is_valid, "no session id" );
93 ok( !$c->session->{magic}, "session data not restored" );
94 ok( !$c->session_delete_reason, "no reason for deletion" );
95 }
96  
97 @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
98  
99 { __PACKAGE__->setup; }; # Extra block here is an INSANE HACK to get inlined constructor
100 # (i.e. to make B::Hooks::EndOfScope fire)
101 }
102  
103 {
104  
105 package # Hide from PAUSE
106 SessionStoreTest2;
107 use Catalyst qw/Session SessionStateTest/;
108 push our (@ISA), $m;
109  
110 our $VERSION # make unparseable
111 = "123";
112  
113 use Test::More;
114  
115 sub create_session : Global {
116 my ( $self, $c ) = @_;
117  
118 $c->session->{magic} = "møøse";
119 }
120  
121 sub recover_session : Global {
122 my ( $self, $c ) = @_;
123  
124 ok( !$c->session_is_valid, "session is gone" );
125  
126 is(
127 $c->session_delete_reason,
128 "session expired",
129 "reason is that the session expired"
130 );
131  
132 ok( !$c->session->{magic}, "no saved data" );
133 }
134  
135 __PACKAGE__->config->{'Plugin::Session'}{expires} = 0;
136  
137 @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
138  
139 { __PACKAGE__->setup; }; # INSANE HACK (the block - as above)
140 }
141  
142 use Test::More;
143  
144 can_ok( $m, "get_session_data" );
145 can_ok( $m, "store_session_data" );
146 can_ok( $m, "delete_session_data" );
147 can_ok( $m, "delete_expired_sessions" );
148  
149 {
150  
151 package # Hide from PAUSE
152 t1;
153 use Catalyst::Test "SessionStoreTest";
154  
155 # idiotic void context warning workaround
156  
157 my $x = get("/create_session");
158 $x = get("/recover_session");
159 $x = get("/after_session");
160 }
161  
162 {
163  
164 package # Hide fram PAUSE
165 t2;
166 use Catalyst::Test "SessionStoreTest2";
167  
168 my $x = get("/create_session");
169 sleep 1; # let the session expire
170 $x = get("/recover_session");
171 }
172 }
173  
174 __PACKAGE__;
175  
176 __END__