Login - negative tests
[scpubgit/stemmaweb.git] / t / 04login.t
1 use warnings;
2 use strict;
3
4 use stemmaweb;
5 use LWP::Protocol::PSGI;
6 use Test::WWW::Mechanize;
7
8 use Test::More;
9 use HTML::TreeBuilder;
10 use Data::Dumper;
11
12 use FindBin;
13 use lib ("$FindBin::Bin/lib");
14
15 use stemmaweb::Test::DB;
16
17 stemmaweb::Test::DB->new_db;
18
19 LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
20
21 my $ua = Test::WWW::Mechanize->new;
22
23 $ua->get_ok('http://localhost/login');
24 my $response = $ua->submit_form(
25     fields => {
26         username    => 'user@example.org',
27         password    => 'UserPass'
28     });
29
30 $ua->content_contains('Stemmaweb - Logged in', 'Log in successful.');
31
32 my $content  = $ua->get('/');
33 $ua->content_contains('Hello! user@example.org', 'We are logged in.');
34
35 $ua->get('/logout');
36 $ua->get('/login');
37
38 $ua->submit_form;
39
40 $ua->content_contains('Your username is required.', 'Username is required to log in');
41 $ua->content_contains('Your password is required.', 'Password is required to log in.');
42
43 $ua->submit_form(
44     fields => {
45         username    => 'nonexistant',
46         password    => 'nonexistant',
47     });
48
49 $ua->content_contains('Bad username or password.', 'Error is shown on incorrect details.');
50
51
52 done_testing;