6 use Test::More tests => 12;
7 use Test::MockObject::Extends;
12 BEGIN { use_ok( $m = "Catalyst::Plugin::SessionHP" ) }
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( _session_id => "deadbeef" );
28 config => { session => { max_lifetime => 1000, min_lifetime => 500 } } );
29 $c->set_always( stash => {} );
31 # check that start state is as expected
32 is_deeply( $c->session, {}, "nothing in session" );
33 is_deeply( $c->flash, {}, "nothing in flash" );
35 # set a value in the flash and check it gets to the flash
36 pass "--- add one value to the flash ---";
37 $c->flash->{foo} = "moose";
38 is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
44 { __updated => re('^\d+$'),
45 __created => re('^\d+$'),
46 __flash => { foo => "moose" },
48 "session has __flash with flash data"
51 pass "--- add second value to flash ---";
52 $c->flash->{bar} = "gorch";
55 { foo => "moose", bar => "gorch" },
61 is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
65 $c->flash->{test} = 'clear_flash';
71 is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
75 is_deeply( $c->flash, {},
76 "nothing in flash after finalize after clear_flash" );
80 { __updated => re('^\d+$'), __created => re('^\d+$'), },
81 "session has empty __flash after clear_flash + finalize"
84 $c->flash->{bar} = "gorch";