Commit | Line | Data |
ad93b3e9 |
1 | #!perl |
2 | |
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"; |
10 | |
11 | BEGIN { |
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 | |
3581e90f |
24 | eval { require Catalyst::Plugin::Session; |
ad93b3e9 |
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 | |
f26005a7 |
29 | eval { require Catalyst::Plugin::Session::State::Cookie; } |
30 | or plan skip_all => |
31 | "Catalyst::Plugin::Session::State::Cookie is required for this test"; |
32 | |
33 | |
ad93b3e9 |
34 | plan tests => 8; |
35 | |
b4319877 |
36 | use TestApp; |
37 | TestApp->config( { |
ad93b3e9 |
38 | name => 'TestApp', |
39 | authentication => { |
40 | default_realm => "users", |
41 | realms => { |
42 | users => { |
43 | credential => { |
44 | 'class' => "Password", |
45 | 'password_field' => 'password', |
46 | 'password_type' => 'clear' |
47 | }, |
48 | store => { |
49 | 'class' => 'DBIx::Class', |
f55cb81e |
50 | 'user_model' => 'TestApp::User', |
f26005a7 |
51 | 'use_userdata_from_session' => 0, |
ad93b3e9 |
52 | }, |
53 | }, |
54 | }, |
55 | }, |
b4319877 |
56 | } ); |
ad93b3e9 |
57 | |
b4319877 |
58 | TestApp->setup( |
ad93b3e9 |
59 | qw/Authentication |
60 | Session |
61 | Session::Store::Dummy |
62 | Session::State::Cookie |
63 | / |
b4319877 |
64 | ); |
ad93b3e9 |
65 | } |
66 | |
ad93b3e9 |
67 | use Test::WWW::Mechanize::Catalyst 'TestApp'; |
68 | my $m = Test::WWW::Mechanize::Catalyst->new; |
69 | |
70 | # log a user in |
71 | { |
72 | $m->get_ok( 'http://localhost/user_login?username=joeuser&password=hackme', undef, 'request ok' ); |
73 | $m->content_is( 'joeuser logged in', 'user logged in ok' ); |
74 | } |
75 | |
76 | # verify the user is still logged in |
77 | { |
78 | $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' ); |
79 | $m->content_is( 'joeuser', 'user still logged in' ); |
80 | } |
81 | |
82 | # log the user out |
83 | { |
84 | $m->get_ok( 'http://localhost/user_logout', undef, 'request ok' ); |
85 | $m->content_is( 'logged out', 'user logged out ok' ); |
86 | } |
87 | |
88 | # verify there is no session |
89 | { |
90 | $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' ); |
91 | $m->content_is( '', "user's session deleted" ); |
92 | } |