Commit | Line | Data |
da9aa7d5 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
19c130c2 |
6 | use Test::More tests => 7; |
da9aa7d5 |
7 | use Test::MockObject::Extends; |
8 | use Test::Exception; |
9 | |
10 | my $m; |
11 | BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) } |
12 | |
ab634fee |
13 | my $c = Test::MockObject::Extends->new($m); |
14 | |
15 | my $flash = {}; |
16 | $c->mock( |
17 | get_session_data => sub { |
18 | my ( $c, $key ) = @_; |
19 | return $key =~ /expire/ ? time() + 1000 : $flash; |
20 | } |
21 | ); |
22 | $c->set_true("store_session_data"); |
23 | $c->set_always( _sessionid => "deadbeef" ); |
24 | $c->set_always( config => { session => { expires => 1000 } } ); |
25 | $c->set_always( stash => {} ); |
da9aa7d5 |
26 | |
ab634fee |
27 | is_deeply( $c->flash, {}, "nothing in flash" ); |
da9aa7d5 |
28 | |
29 | $c->flash->{foo} = "moose"; |
30 | |
31 | $c->finalize; |
da9aa7d5 |
32 | |
33 | is_deeply( $c->flash, { foo => "moose" }, "one key in flash" ); |
34 | |
35 | $c->flash->{bar} = "gorch"; |
36 | |
ab634fee |
37 | is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" ); |
da9aa7d5 |
38 | |
39 | $c->finalize; |
da9aa7d5 |
40 | |
41 | is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" ); |
42 | |
43 | $c->finalize; |
da9aa7d5 |
44 | |
ab634fee |
45 | is_deeply( $c->flash, {}, "nothing in flash" ); |
19c130c2 |
46 | |
47 | $c->flash->{bar} = "gorch"; |
48 | |
49 | $c->config->{session}{flash_to_stash} = 1; |
50 | |
51 | $c->finalize; |
52 | $c->prepare_action; |
53 | |
54 | is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" ); |
55 | |