Version 0.02
[blog.pm-common-perl-mods.git] / Catalyst-Authentication-Store-RDBO / t / 04-authsessions.t
blobae28e7f39ee48bac59fde2eb7720f007a41b3222
1 #!perl
3 use strict;
4 use warnings;
5 use DBI;
6 use File::Path;
7 use FindBin;
8 use Test::More;
9 use lib "$FindBin::Bin/lib";
11 BEGIN {
12     eval { require Test::WWW::Mechanize::Catalyst }
13       or plan skip_all =>
14       "Test::WWW::Mechanize::Catalyst is required for this test";
16     eval { require DBD::SQLite }
17         or plan skip_all =>
18         "DBD::SQLite is required for this test";
20     eval { require DBIx::Class }
21         or plan skip_all =>
22         "DBIx::Class is required for this test";
24     eval { require Catalyst::Plugin::Session; 
25            die unless $Catalyst::Plugin::Session::VERSION >= 0.02 }
26         or plan skip_all =>
27         "Catalyst::Plugin::Session >= 0.02 is required for this test";
29     eval { require Catalyst::Plugin::Session::State::Cookie; }
30         or plan skip_all =>
31         "Catalyst::Plugin::Session::State::Cookie is required for this test";
34     plan tests => 8;
36     $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
38     $ENV{TESTAPP_CONFIG} = {
39         name => 'TestApp',
40         authentication => {
41             default_realm => "users",
42             realms => {
43                 users => {
44                     credential => {
45                         'class' => "Password",
46                         'password_field' => 'password',
47                         'password_type' => 'clear'
48                     },
49                     store => {
50                         'class' => 'RDBO',
51                         'user_class' => 'User',
52                         'use_userdata_from_session' => 0,
53                     },
54                 },
55             },
56         },
57     };
59     $ENV{TESTAPP_PLUGINS} = [
60         qw/Authentication
61            Session
62            Session::Store::Dummy
63            Session::State::Cookie
64            /
65     ];
68 use SetupDB;
70 use Test::WWW::Mechanize::Catalyst 'TestApp';
71 my $m = Test::WWW::Mechanize::Catalyst->new;
73 # log a user in
75     $m->get_ok( 'http://localhost/user_login?username=joeuser&password=hackme', undef, 'request ok' );
76     $m->content_is( 'joeuser logged in', 'user logged in ok' );
79 # verify the user is still logged in
81     $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
82     $m->content_is( 'joeuser', 'user still logged in' );
85 # log the user out
87     $m->get_ok( 'http://localhost/user_logout', undef, 'request ok' );
88     $m->content_is( 'logged out', 'user logged out ok' );
91 # verify there is no session
93     $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
94     $m->content_is( '', "user's session deleted" );
97 # clean up
98 unlink $ENV{TESTAPP_DB_FILE};