use strict;
use warnings;
-use Test::More tests => 15;
+use utf8;
+
+use Test::More;
use File::Temp;
use File::Spec;
use Catalyst ();
sub import {
- shift;
- my %args = @_;
+ shift;
+ my %args = @_;
+
+ plan tests => 19 + ($args{extra_tests} || 0);
+
+ my $backend = $args{backend};
+ my $cfg = $args{config};
+
+ my $p = "Session::Store::$backend";
+ use_ok( my $m = "Catalyst::Plugin::$p" );
+
+ isa_ok( bless( {}, $m ), "Catalyst::Plugin::Session::Store" );
+
+ {
+ package # Hide from PAUSE
+ Catalyst::Plugin::SessionStateTest;
+ use base qw/Catalyst::Plugin::Session::State/;
+
+ no strict 'refs';
+
+ sub get_session_id {
+ my $c = shift;
+ ${ ref($c) . "::session_id" };
+ }
+
+ sub set_session_id {
+ my ( $c, $sid ) = @_;
+ ${ ref($c) . "::session_id" } = $sid;
+ }
- my $backend = $args{backend};
- my $cfg = $args{config};
+ sub delete_session_id {
+ my $c = shift;
+ undef ${ ref($c) . "::session_id" };
+ }
+ }
- my $p = "Session::Store::$backend";
- use_ok(my $m = "Catalyst::Plugin::$p");
+ {
- isa_ok(bless({}, $m), "Catalyst::Plugin::Session::Store");
+ package # Hide from PAUSE
+ SessionStoreTest;
+ use Catalyst qw/Session SessionStateTest/;
+ push our (@ISA), $m;
- our $restored_session_id;
+ use strict;
+ use warnings;
- {
- package SessionStoreTest;
- use Catalyst qw/-Engine=Test Session Session::State/;
- push our(@ISA), $m;
+ use Test::More;
- our $VERSION = "0.01";
+ sub create_session : Global {
+ my ( $self, $c ) = @_;
+ ok( !$c->session_is_valid, "no session id yet" );
+ ok( $c->session, "session created" );
+ ok( $c->session_is_valid, "with a session id" );
- use Test::More;
+ $c->session->{magic} = "møøse";
+ }
- sub prepare_cookies {
- my $c = shift;
- $c->sessionid($restored_session_id) if defined $restored_session_id;
- $c->NEXT::prepare_cookies(@_);
- }
+ sub recover_session : Global {
+ my ( $self, $c ) = @_;
+ 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");
+ }
- 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");
+ sub after_session : Global {
+ my ( $self, $c ) = @_;
+ 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" );
+ }
- $restored_session_id = $c->sessionid;
+ @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
- $c->session->{magic} = "møøse";
- }
+ { __PACKAGE__->setup; }; # INSANE HACK
+ }
- sub recover_session : Global {
- my ( $self, $c ) = @_;
- ok($c->sessionid, "session id exists");
- is($c->sessionid, $restored_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->{magic}, "session data not restored");
- ok(!$c->session_delete_reason, "no reason for deletion");
- }
+ package # Hide from PAUSE
+ SessionStoreTest2;
+ use Catalyst qw/Session SessionStateTest/;
+ push our (@ISA), $m;
- @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
-
- __PACKAGE__->setup;
- }
+ our $VERSION = "123";
- {
- package SessionStoreTest2;
- use Catalyst qw/-Engine=Test Session Session::State/;
- push our(@ISA), $m;
+ use Test::More;
- our $VERSION = "123";
+ sub create_session : Global {
+ my ( $self, $c ) = @_;
- use Test::More;
+ $c->session->{magic} = "møøse";
+ }
- sub prepare_cookies {
- my $c = shift;
- $c->sessionid($restored_session_id) if defined $restored_session_id;
- $c->NEXT::prepare_cookies(@_);
- }
+ sub recover_session : Global {
+ my ( $self, $c ) = @_;
- sub create_session : Global {
- my ( $self, $c ) = @_;
+ ok( !$c->session_is_valid, "session is gone" );
- $c->session->{magic} = "møøse";
+ is(
+ $c->session_delete_reason,
+ "session expired",
+ "reason is that the session expired"
+ );
- $restored_session_id = $c->sessionid;
- }
+ ok( !$c->session->{magic}, "no saved data" );
+ }
- sub recover_session : Global {
- my ( $self, $c ) = @_;
+ __PACKAGE__->config->{'Plugin::Session'}{expires} = 0;
- ok(!$c->sessionid, "no session id");
+ @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
- is($c->session_delete_reason, "session expired", "reason is that the session expired");
+ { __PACKAGE__->setup; }; # INSANE HACK
+ }
- ok(!$c->session->{magic}, "no saved data");
- }
+ use Test::More;
- __PACKAGE__->config->{session}{expires} = 0;
+ can_ok( $m, "get_session_data" );
+ can_ok( $m, "store_session_data" );
+ can_ok( $m, "delete_session_data" );
+ can_ok( $m, "delete_expired_sessions" );
- @{ __PACKAGE__->config->{session} }{ keys %$cfg } = values %$cfg;
+ {
- __PACKAGE__->setup;
- }
+ package # Hide from PAUSE
+ t1;
+ use Catalyst::Test "SessionStoreTest";
- {
- package t1;
- use Catalyst::Test "SessionStoreTest";
+ # idiotic void context warning workaround
+
+ my $x = get("/create_session");
+ $x = get("/recover_session");
+ $x = get("/after_session");
+ }
- get("/create_session");
- get("/recover_session");
- get("/after_session");
- }
+ {
- {
- package t2;
- use Catalyst::Test "SessionStoreTest2";
+ package # Hide fram PAUSE
+ t2;
+ use Catalyst::Test "SessionStoreTest2";
- get("/create_session");
- sleep 1; # let the session expire
- get("/recover_session");
- }
+ my $x = get("/create_session");
+ sleep 1; # let the session expire
+ $x = get("/recover_session");
+ }
}
__PACKAGE__;
=head1 SYNOPSIS
- #!/usr/bin/perl
+ #!/usr/bin/perl
- use Catalyst::Plugin::Session::Test::Store (
- backend => "FastMmap",
- config => {
- storage => "/tmp/foo",
- },
- );
+ use Catalyst::Plugin::Session::Test::Store (
+ backend => "FastMmap",
+ config => {
+ storage => "/tmp/foo",
+ },
+ );
=head1 DESCRIPTION