update cookie BEFORE sending to user; change finalize to finalize_headers so that...
[catagits/Catalyst-Plugin-Session.git] / t / 06_finalize.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9     if ( eval { require Catalyst::Plugin::Session::State::Cookie } ) {
10         plan tests => 3;
11     } else {
12         plan skip_all => "Catalyst::Plugin::Session::State::Cookie required";
13     }
14 }
15
16 my $finalized = 0;
17
18 {
19   package TestPlugin;
20   BEGIN { $INC{"TestPlugin.pm"} = 1 } # nasty hack for 5.8.6
21
22   sub finalize_session { $finalized = 1 }
23
24   sub finalize { die "already finalized_session()" if $finalized }
25
26   # Structure inheritance so TestPlugin->finalize() is called *after* 
27   # Catalyst::Plugin::Session->finalize()
28   package TestApp;
29
30   use Catalyst qw/
31     Session Session::Store::Dummy Session::State::Cookie +TestPlugin 
32   /;
33   __PACKAGE__->setup;
34 }
35
36 BEGIN { use_ok('Catalyst::Plugin::Session') }
37
38 my $c = TestApp->new;
39 eval { $c->finalize };
40 ok(!$@, "finalize_session() called after all other finalize() methods");
41 ok($finalized, "finalize_session() called");