Perltidy + restore of lost test fixes
[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; BEGIN { use_ok($m = "Catalyst::Plugin::Session") }
11
12 my %config;
13 my $log = Test::MockObject->new;
14 my @mock_isa = ();
15
16 $log->set_true("fatal");
17
18 {
19         package MockCxt;
20         use base $m;
21         sub new { bless {}, $_[0] }
22         sub config { \%config };
23         sub log { $log }
24         sub isa {
25                 my $self = shift;
26                 my $class = shift;
27                 grep { $_ eq $class } @mock_isa or $self->SUPER::isa($class);
28         }
29 }
30
31 can_ok($m, "setup");
32
33 eval { MockCxt->new->setup }; # throws OK is not working with NEXT
34 like($@, qr/requires.*((?:State|Store).*){2}/i, "can't setup an object that doesn't use state/store plugins");
35
36 $log->called_ok("fatal", "fatal error logged");
37
38 @mock_isa = qw/Catalyst::Plugin::Session::State/;
39 eval { MockCxt->new->setup };
40 like($@, qr/requires.*(?:Store)/i, "can't setup an object that doesn't use state/store plugins");
41
42 @mock_isa = qw/Catalyst::Plugin::Session::Store/;
43 eval { MockCxt->new->setup };
44 like($@, qr/requires.*(?:State)/i, "can't setup an object that doesn't use state/store plugins");
45
46 $log->clear;
47
48 @mock_isa = qw/Catalyst::Plugin::Session::State Catalyst::Plugin::Session::Store/;
49 eval { MockCxt->new->setup };
50 ok(!$@, "setup() lives with state/store plugins in use");
51 ok(!$log->called("fatal"), "no fatal error logged either");
52
53 cmp_deeply(
54         [ keys %{ $config{session} } ],
55         bag(qw/expires verify_address/),
56         "default values for config were populated in successful setup",
57 );
58
59 %config = (session => { expires => 1234 });
60 MockCxt->new->setup;
61 is($config{session}{expires}, 1234, "user values are not overwritten in config");
62