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; |
d3e0ff80 |
20 | }, |
ab634fee |
21 | ); |
22 | $c->set_true("store_session_data"); |
d3e0ff80 |
23 | $c->set_true("delete_session_data"); |
ab634fee |
24 | $c->set_always( _sessionid => "deadbeef" ); |
25 | $c->set_always( config => { session => { expires => 1000 } } ); |
26 | $c->set_always( stash => {} ); |
da9aa7d5 |
27 | |
ab634fee |
28 | is_deeply( $c->flash, {}, "nothing in flash" ); |
da9aa7d5 |
29 | |
30 | $c->flash->{foo} = "moose"; |
31 | |
32 | $c->finalize; |
da9aa7d5 |
33 | |
34 | is_deeply( $c->flash, { foo => "moose" }, "one key in flash" ); |
35 | |
36 | $c->flash->{bar} = "gorch"; |
37 | |
ab634fee |
38 | is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" ); |
da9aa7d5 |
39 | |
40 | $c->finalize; |
da9aa7d5 |
41 | |
42 | is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" ); |
43 | |
44 | $c->finalize; |
da9aa7d5 |
45 | |
ab634fee |
46 | is_deeply( $c->flash, {}, "nothing in flash" ); |
19c130c2 |
47 | |
48 | $c->flash->{bar} = "gorch"; |
49 | |
50 | $c->config->{session}{flash_to_stash} = 1; |
51 | |
52 | $c->finalize; |
53 | $c->prepare_action; |
54 | |
55 | is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" ); |
56 | |