finalize session before sending HTTP headers
[catagits/Catalyst-Plugin-Session.git] / t / 03_flash.t
CommitLineData
da9aa7d5 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
99ad8ae8 6use Test::More tests => 8;
da9aa7d5 7use Test::MockObject::Extends;
8use Test::Exception;
9
10my $m;
11BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
12
ab634fee 13my $c = Test::MockObject::Extends->new($m);
14
15my $flash = {};
16$c->mock(
17 get_session_data => sub {
18 my ( $c, $key ) = @_;
19 return $key =~ /expire/ ? time() + 1000 : $flash;
d3e0ff80 20 },
ab634fee 21);
5a1f6ed4 22$c->mock("store_session_data" => sub { $flash = $_[2] });
23$c->mock("delete_session_data" => sub { $flash = {} });
ab634fee 24$c->set_always( _sessionid => "deadbeef" );
25$c->set_always( config => { session => { expires => 1000 } } );
26$c->set_always( stash => {} );
da9aa7d5 27
ab634fee 28is_deeply( $c->flash, {}, "nothing in flash" );
da9aa7d5 29
30$c->flash->{foo} = "moose";
31
92eaec32 32$c->finalize_body;
da9aa7d5 33
34is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
35
c9396824 36$c->flash(bar => "gorch");
da9aa7d5 37
ab634fee 38is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
da9aa7d5 39
92eaec32 40$c->finalize_body;
da9aa7d5 41
42is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
43
92eaec32 44$c->finalize_body;
da9aa7d5 45
99ad8ae8 46$c->flash->{test} = 'clear_flash';
47
92eaec32 48$c->finalize_body;
99ad8ae8 49
50$c->clear_flash();
51
52is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
53
92eaec32 54$c->finalize_body;
99ad8ae8 55
56is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
19c130c2 57
58$c->flash->{bar} = "gorch";
59
60$c->config->{session}{flash_to_stash} = 1;
61
92eaec32 62$c->finalize_body;
19c130c2 63$c->prepare_action;
64
65is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );