6 use Test::More tests => 12;
7 use Test::MockObject::Extends;
12 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
14 my $c = Test::MockObject::Extends->new($m);
18 get_session_data => sub {
20 return $key =~ /expire/ ? time() + 1000 : $flash;
23 $c->mock("debug" => sub { 0 });
24 $c->mock("store_session_data" => sub { $flash = $_[2] });
25 $c->mock("delete_session_data" => sub { $flash = {} });
26 $c->set_always( _sessionid => "deadbeef" );
27 $c->set_always( config => { session => { expires => 1000 } } );
28 $c->set_always( stash => {} );
30 is_deeply( $c->session, {}, "nothing in session" );
32 is_deeply( $c->flash, {}, "nothing in flash" );
34 $c->flash->{foo} = "moose";
38 is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
40 cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session has __flash with flash data" );
42 $c->flash(bar => "gorch");
44 is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
46 cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session still has __flash with flash data" );
50 is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
54 $c->flash->{test} = 'clear_flash';
60 is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
64 is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
66 cmp_deeply( $c->session, { __updated => re('^\d+$'), }, "session has empty __flash after clear_flash + finalize" );
68 $c->flash->{bar} = "gorch";
70 $c->config->{session}{flash_to_stash} = 1;
75 is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );