6 use Test::More tests => 8;
7 use Test::MockObject::Extends;
11 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
13 my $c = Test::MockObject::Extends->new($m);
17 get_session_data => sub {
19 return $key =~ /expire/ ? time() + 1000 : $flash;
22 $c->mock("store_session_data" => sub { $flash = $_[2] });
23 $c->mock("delete_session_data" => sub { $flash = {} });
24 $c->set_always( _sessionid => "deadbeef" );
25 $c->set_always( config => { session => { expires => 1000 } } );
26 $c->set_always( stash => {} );
28 is_deeply( $c->flash, {}, "nothing in flash" );
30 $c->flash->{foo} = "moose";
34 is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
36 $c->flash(bar => "gorch");
38 is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
42 is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
46 $c->flash->{test} = 'clear_flash';
52 is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
56 is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
58 $c->flash->{bar} = "gorch";
60 $c->config->{session}{flash_to_stash} = 1;
65 is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );