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