suppress declaration warning
[scpubgit/stemmaweb.git] / t / 05register.t
CommitLineData
32d1fbf8 1use warnings;
2use strict;
3
bf3397df 4use FindBin;
5use lib ("$FindBin::Bin/lib");
6
7use stemmaweb::Test::Common;
8
32d1fbf8 9use stemmaweb;
10use LWP::Protocol::PSGI;
11use Test::WWW::Mechanize;
12
13use Test::More;
14use HTML::TreeBuilder;
15use Data::Dumper;
16
32d1fbf8 17use stemmaweb::Test::DB;
18
19stemmaweb::Test::DB->new_db;
20
21LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
22
32d1fbf8 23my $ua = Test::WWW::Mechanize->new;
24
25$ua->get_ok('http://localhost/register');
26
27my $response = $ua->submit_form(
28 fields => {
29 username => 'user2@example.org',
30 password => 'UserPass',
31 confirm_password => 'UserPass',
32 });
33
bf3397df 34$ua->content_contains('You are now registered.', 'Registration worked');
35
36$ua->get('/');
37$ua->content_contains('Hello! user2@example.org', 'We are logged in.');
38
39$ua->get('/logout');
40
41$ua->get_ok('http://localhost/login');
42$response = $ua->submit_form(
43 fields => {
44 username => 'user2@example.org',
45 password => 'UserPass'
46 });
47
48$ua->content_contains('Stemmaweb - Logged in', 'Log in with new account works');
49
50$ua->get('/');
51$ua->content_contains('Hello! user2@example.org', 'We are logged in with new account');
52
53$ua->get('/logout');
32d1fbf8 54
bf3397df 55$ua->get_ok('http://localhost/register');
32d1fbf8 56
bf3397df 57$response = $ua->submit_form(
58 fields => {
59 username => 'user2@example.org',
60 password => 'UserPass',
61 confirm_password => 'UserPass',
62 });
32d1fbf8 63
bf3397df 64$ua->content_contains('That username already exists.', 'We cannot register an already
65 existing username');
32d1fbf8 66
315022bd 67$ua->get('/logout');
68$ua->get('http://localhost/register');
69
70$ua->submit_form;
71
72$ua->content_contains('Your username is required.', 'We get an error if username is empty');
73$ua->content_contains('Your password is required.', 'We get an error if password is empty');
74$ua->content_contains('You must confirm your password.', 'We get an error if password confirmation is empty');
75
76$ua->submit_form(
77 fields => {
78 username => 'new@example.com',
79 password => 'MyPassword',
80 confirm_password => 'WrongPassword',
81 });
82
83$ua->content_contains('The password confirmation does not match the password', 'confirm password needs to be the same as password.');
84
85$ua->submit_form(
86 fields => {
87 username => 'user',
88 password => 'a',
89 confirm_password => 'a',
90 });
91
92
93$ua->content_contains('Field must be at least 8 characters. You entered 1', 'Error is shown on too short passwd.');
94
32d1fbf8 95
96done_testing;