Test the flash feature of C::P::Session
[catagits/Catalyst-Plugin-Session.git] / t / 03_flash.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7 use Test::MockObject::Extends;
8 use Test::Exception;
9
10 my $m;
11 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
12
13 my $c = Test::MockObject::Extends->new( $m );
14
15 $c->set_always( get_session_data => { __expires => time+10000, __updated => time } );
16 $c->set_always( config => { session => { expires => 1000000 } } );
17
18 $c->sessionid("deadbeef");
19
20 $c->_load_session;
21
22 is_deeply( $c->flash, {}, "nothing in flash");
23
24 $c->flash->{foo} = "moose";
25
26 $c->finalize;
27 $c->_load_session;
28
29 is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
30
31 $c->flash->{bar} = "gorch";
32
33 is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash");
34
35 $c->finalize;
36 $c->_load_session;
37
38 is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
39
40 $c->finalize;
41 $c->_load_session;
42
43 is_deeply( $c->flash, {}, "nothing in flash");