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