Commit | Line | Data |
da9aa7d5 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
eb250519 |
6 | use Test::More tests => 12; |
da9aa7d5 |
7 | use Test::MockObject::Extends; |
8 | use Test::Exception; |
eb250519 |
9 | use Test::Deep; |
da9aa7d5 |
10 | |
11 | my $m; |
12 | BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) } |
13 | |
ab634fee |
14 | my $c = Test::MockObject::Extends->new($m); |
15 | |
16 | my $flash = {}; |
17 | $c->mock( |
18 | get_session_data => sub { |
19 | my ( $c, $key ) = @_; |
20 | return $key =~ /expire/ ? time() + 1000 : $flash; |
d3e0ff80 |
21 | }, |
ab634fee |
22 | ); |
eb250519 |
23 | $c->mock("debug" => sub { 0 }); |
5a1f6ed4 |
24 | $c->mock("store_session_data" => sub { $flash = $_[2] }); |
25 | $c->mock("delete_session_data" => sub { $flash = {} }); |
ab634fee |
26 | $c->set_always( _sessionid => "deadbeef" ); |
27 | $c->set_always( config => { session => { expires => 1000 } } ); |
28 | $c->set_always( stash => {} ); |
da9aa7d5 |
29 | |
eb250519 |
30 | is_deeply( $c->session, {}, "nothing in session" ); |
31 | |
ab634fee |
32 | is_deeply( $c->flash, {}, "nothing in flash" ); |
da9aa7d5 |
33 | |
34 | $c->flash->{foo} = "moose"; |
35 | |
92eaec32 |
36 | $c->finalize_body; |
da9aa7d5 |
37 | |
38 | is_deeply( $c->flash, { foo => "moose" }, "one key in flash" ); |
39 | |
eb250519 |
40 | cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session has __flash with flash data" ); |
41 | |
c9396824 |
42 | $c->flash(bar => "gorch"); |
da9aa7d5 |
43 | |
ab634fee |
44 | is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" ); |
da9aa7d5 |
45 | |
eb250519 |
46 | cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session still has __flash with flash data" ); |
47 | |
92eaec32 |
48 | $c->finalize_body; |
da9aa7d5 |
49 | |
50 | is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" ); |
51 | |
92eaec32 |
52 | $c->finalize_body; |
da9aa7d5 |
53 | |
99ad8ae8 |
54 | $c->flash->{test} = 'clear_flash'; |
55 | |
92eaec32 |
56 | $c->finalize_body; |
99ad8ae8 |
57 | |
58 | $c->clear_flash(); |
59 | |
60 | is_deeply( $c->flash, {}, "nothing in flash after clear_flash" ); |
61 | |
92eaec32 |
62 | $c->finalize_body; |
99ad8ae8 |
63 | |
64 | is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" ); |
19c130c2 |
65 | |
eb250519 |
66 | cmp_deeply( $c->session, { __updated => re('^\d+$'), }, "session has empty __flash after clear_flash + finalize" ); |
67 | |
19c130c2 |
68 | $c->flash->{bar} = "gorch"; |
69 | |
70 | $c->config->{session}{flash_to_stash} = 1; |
71 | |
92eaec32 |
72 | $c->finalize_body; |
19c130c2 |
73 | $c->prepare_action; |
74 | |
75 | is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" ); |