Update for new Catalyst version and upcoming new Session plugin version
[catagits/Catalyst-Plugin-Session-State-Stash.git] / t / 04-basic.t
CommitLineData
642b19cf 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
effd6244 6use Test::More tests => 10;
642b19cf 7use Test::MockObject;
8use Test::MockObject::Extends;
9
10# Get a stash
11my $m;
12BEGIN { use_ok( $m = "Catalyst::Plugin::Session::State::Stash" ) }
13
14# Mock a catalyst controller
15my $cxt =
16 Test::MockObject::Extends->new("Catalyst::Plugin::Session::State::Stash");
17
18$cxt->set_always( config => {} );
19$cxt->set_always( session => {} );
20$cxt->set_always( stash => {} );
21$cxt->set_false("debug");
22
23my $sessionid;
24$cxt->mock( sessionid => sub { shift; $sessionid = shift if @_; $sessionid } );
25
26can_ok( $m, "setup_session" );
27
28$cxt->setup_session;
29
effd6244 30is( $cxt->config->{'session'}{stash_key},
642b19cf 31 '_session', "default cookie name is set" );
32
33can_ok( $m, "get_session_id" );
34
35ok( !$cxt->get_session_id, "no session id yet");
36
effd6244 37$cxt->set_always( stash => { '_session' => {id => 1}, 'session_id' => {id => 2}, 'other_thing' => { id => 3 } } );
642b19cf 38
39is( $cxt->get_session_id, "1", "Pull newfound session id" );
40
effd6244 41$cxt->config->{'session'}{stash_key} = "session_id";
642b19cf 42
43is( $cxt->get_session_id, "2", "Pull session id from second key" );
44
effd6244 45can_ok( $m, "set_session_id" );
46
47# Check forwards config compatibility..
48$cxt->config->{'Plugin::Session'} = {};
49$cxt->setup_session;
50
51is( $cxt->config->{'Plugin::Session'}{stash_key},
52 '_session', "default cookie name is set when new stash key used" );
53
54$cxt->config->{'Plugin::Session'}{stash_key} = "other_thing";
55
56is( $cxt->get_session_id, "3", "Pull session id from key in new config" );