6 use Test::More tests => 12;
11 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
13 my $c_meta = Class::MOP::Class->create_anon_class(
14 superclasses => [ $m, 'Moose::Object', ],
16 my $c = $c_meta->name->new;
20 get_session_data => sub {
22 return $key =~ /expire/ ? time() + 1000 : $flash;
25 $c->meta->add_method("debug" => sub { 0 });
26 $c->meta->add_method("store_session_data" => sub { $flash = $_[2] });
27 $c->meta->add_method("delete_session_data" => sub { $flash = {} });
28 $c->meta->add_method( _sessionid => sub { "deadbeef" });
29 my $config = { expires => 1000 };
30 $c->meta->add_method( config => sub { { session => $config } });
32 $c->meta->add_method( stash => sub { $stash } );
34 is_deeply( $c->session, {}, "nothing in session" );
36 is_deeply( $c->flash, {}, "nothing in flash" );
38 $c->flash->{foo} = "moose";
42 is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
44 cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session has __flash with flash data" );
46 $c->flash(bar => "gorch");
48 is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
50 cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session still has __flash with flash data" );
54 is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
58 $c->flash->{test} = 'clear_flash';
64 is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
68 is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
70 cmp_deeply( $c->session, { __updated => re('^\d+$'), }, "session has empty __flash after clear_flash + finalize" );
72 $c->flash->{bar} = "gorch";
74 $config->{flash_to_stash} = 1;
79 is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );