-\feff#!/usr/bin/perl
+#!/usr/bin/perl
package Catalyst::Plugin::Session::Test::Store;
use strict;
use warnings;
-use Test::More tests => 19;
+use utf8;
+
+use Test::More;
use File::Temp;
use File::Spec;
shift;
my %args = @_;
+ plan tests => 19 + ($args{extra_tests} || 0);
+
my $backend = $args{backend};
my $cfg = $args{config};
isa_ok( bless( {}, $m ), "Catalyst::Plugin::Session::Store" );
- our $restored_session_id;
-
{
+ package # Hide from PAUSE
+ Catalyst::Plugin::SessionStateTest;
+ use base qw/Catalyst::Plugin::Session::State/;
- package SessionStoreTest;
- use Catalyst qw/Session Session::State/;
- push our (@ISA), $m;
+ no strict 'refs';
- our $VERSION = "0.01";
+ sub get_session_id {
+ my $c = shift;
+ ${ ref($c) . "::session_id" };
+ }
- use Test::More;
+ sub set_session_id {
+ my ( $c, $sid ) = @_;
+ ${ ref($c) . "::session_id" } = $sid;
+ }
- sub prepare_cookies {
+ sub delete_session_id {
my $c = shift;
- $c->sessionid($restored_session_id) if defined $restored_session_id;
- $c->NEXT::prepare_cookies(@_);
+ undef ${ ref($c) . "::session_id" };
}
+ }
+
+ {
+
+ package # Hide from PAUSE
+ SessionStoreTest;
+ use Catalyst qw/Session SessionStateTest/;
+ push our (@ISA), $m;
+
+ use strict;
+ use warnings;
+
+ use Test::More;
sub create_session : Global {
my ( $self, $c ) = @_;
- ok( !$c->sessionid, "no session id yet" );
- ok( $c->session, "session created" );
- ok( $c->sessionid, "with a session id" );
-
- $restored_session_id = $c->sessionid;
+ ok( !$c->session_is_valid, "no session id yet" );
+ ok( $c->session, "session created" );
+ ok( $c->session_is_valid, "with a session id" );
$c->session->{magic} = "møøse";
}
sub recover_session : Global {
my ( $self, $c ) = @_;
- ok( $c->sessionid, "session id exists" );
- is( $c->sessionid, $restored_session_id,
+ ok( $c->session_is_valid, "session id exists" );
+ is( $c->sessionid, our $session_id,
"and is the one we saved in the last action" );
ok( $c->session, "a session exists" );
is( $c->session->{magic},
"møøse",
"and it contains what we put in on the last attempt" );
$c->delete_session("user logout");
- $restored_session_id = undef;
}
sub after_session : Global {
my ( $self, $c ) = @_;
- ok( !$c->sessionid, "no session id" );
+ ok( !$c->session_is_valid, "no session id" );
ok( !$c->session->{magic}, "session data not restored" );
ok( !$c->session_delete_reason, "no reason for deletion" );
}
- @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
+ @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
- __PACKAGE__->setup;
+ { __PACKAGE__->setup; }; # Extra block here is an INSANE HACK to get inlined constructor
+ # (i.e. to make B::Hooks::EndOfScope fire)
}
{
- package SessionStoreTest2;
- use Catalyst qw/Session Session::State/;
+ package # Hide from PAUSE
+ SessionStoreTest2;
+ use Catalyst qw/Session SessionStateTest/;
push our (@ISA), $m;
our $VERSION = "123";
use Test::More;
- sub prepare_cookies {
- my $c = shift;
- $c->sessionid($restored_session_id) if defined $restored_session_id;
- $c->NEXT::prepare_cookies(@_);
- }
-
sub create_session : Global {
my ( $self, $c ) = @_;
$c->session->{magic} = "møøse";
-
- $restored_session_id = $c->sessionid;
}
sub recover_session : Global {
my ( $self, $c ) = @_;
- ok( !$c->sessionid, "no session id" );
+ ok( !$c->session_is_valid, "session is gone" );
is(
$c->session_delete_reason,
ok( !$c->session->{magic}, "no saved data" );
}
- __PACKAGE__->config->{session}{expires} = 0;
+ __PACKAGE__->config->{'Plugin::Session'}{expires} = 0;
- @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
+ @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
- __PACKAGE__->setup;
+ { __PACKAGE__->setup; }; # INSANE HACK (the block - as above)
}
use Test::More;
{
- package t1;
+ package # Hide from PAUSE
+ t1;
use Catalyst::Test "SessionStoreTest";
# idiotic void context warning workaround
{
- package t2;
+ package # Hide fram PAUSE
+ t2;
use Catalyst::Test "SessionStoreTest2";
my $x = get("/create_session");