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