C::Plugin::Session - branche for verify_user_agent option
[catagits/Catalyst-Plugin-Session.git] / t / 01_setup.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7 use Test::MockObject;
8 use Test::Deep;
9
10 my $m;
11 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
12
13 my %config;
14 my $log      = Test::MockObject->new;
15 my @mock_isa = ();
16
17 $log->set_true("fatal");
18
19 {
20
21     package MockCxt;
22     use MRO::Compat;
23     use base $m;
24     sub new { bless {}, $_[0] }
25     sub config { \%config }
26     sub log    { $log }
27
28     sub isa {
29         my $self  = shift;
30         my $class = shift;
31         grep { $_ eq $class } @mock_isa or $self->SUPER::isa($class);
32     }
33 }
34
35 can_ok( $m, "setup" );
36
37 eval { MockCxt->new->setup };    # throws OK is not working with NEXT
38 like(
39     $@,
40     qr/requires.*((?:State|Store).*){2}/i,
41     "can't setup an object that doesn't use state/store plugins"
42 );
43
44 $log->called_ok( "fatal", "fatal error logged" );
45
46 @mock_isa = qw/Catalyst::Plugin::Session::State/;
47 eval { MockCxt->new->setup };
48 like( $@, qr/requires.*(?:Store)/i,
49     "can't setup an object that doesn't use state/store plugins" );
50
51 @mock_isa = qw/Catalyst::Plugin::Session::Store/;
52 eval { MockCxt->new->setup };
53 like( $@, qr/requires.*(?:State)/i,
54     "can't setup an object that doesn't use state/store plugins" );
55
56 $log->clear;
57
58 @mock_isa =
59   qw/Catalyst::Plugin::Session::State Catalyst::Plugin::Session::Store/;
60 eval { MockCxt->new->setup };
61 ok( !$@, "setup() lives with state/store plugins in use" );
62 ok( !$log->called("fatal"), "no fatal error logged either" );
63
64 cmp_deeply(
65     [ keys %{ $config{session} } ],
66     bag(qw/expires verify_address verify_user_agent/),
67     "default values for config were populated in successful setup",
68 );
69
70 %config = ( session => { expires => 1234 } );
71 MockCxt->new->setup;
72 is( $config{session}{expires},
73     1234, "user values are not overwritten in config" );
74