updating docs to be more clear about behavior when updating
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 04-authsessions.t
CommitLineData
ad93b3e9 1#!perl
2
3use strict;
4use warnings;
5use DBI;
6use File::Path;
7use FindBin;
8use Test::More;
9use lib "$FindBin::Bin/lib";
10
11BEGIN {
12 eval { require Test::WWW::Mechanize::Catalyst }
13 or plan skip_all =>
14 "Test::WWW::Mechanize::Catalyst is required for this test";
15
16 eval { require DBD::SQLite }
17 or plan skip_all =>
18 "DBD::SQLite is required for this test";
19
20 eval { require DBIx::Class }
21 or plan skip_all =>
22 "DBIx::Class is required for this test";
23
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";
28
29 plan tests => 8;
30
31 $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
32
33 $ENV{TESTAPP_CONFIG} = {
34 name => 'TestApp',
35 authentication => {
36 default_realm => "users",
37 realms => {
38 users => {
39 credential => {
40 'class' => "Password",
41 'password_field' => 'password',
42 'password_type' => 'clear'
43 },
44 store => {
45 'class' => 'DBIx::Class',
46 'user_class' => 'TestApp::User',
47 },
48 },
49 },
50 },
51 };
52
53 $ENV{TESTAPP_PLUGINS} = [
54 qw/Authentication
55 Session
56 Session::Store::Dummy
57 Session::State::Cookie
58 /
59 ];
60}
61
62use SetupDB;
63
64use Test::WWW::Mechanize::Catalyst 'TestApp';
65my $m = Test::WWW::Mechanize::Catalyst->new;
66
67# log a user in
68{
69 $m->get_ok( 'http://localhost/user_login?username=joeuser&password=hackme', undef, 'request ok' );
70 $m->content_is( 'joeuser logged in', 'user logged in ok' );
71}
72
73# verify the user is still logged in
74{
75 $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
76 $m->content_is( 'joeuser', 'user still logged in' );
77}
78
79# log the user out
80{
81 $m->get_ok( 'http://localhost/user_logout', undef, 'request ok' );
82 $m->content_is( 'logged out', 'user logged out ok' );
83}
84
85# verify there is no session
86{
87 $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
88 $m->content_is( '', "user's session deleted" );
89}
90
91# clean up
92unlink $ENV{TESTAPP_DB_FILE};