Register test
[scpubgit/stemmaweb.git] / t / 05register.t
index 57e5b59..37ea333 100644 (file)
@@ -1,6 +1,11 @@
 use warnings;
 use strict;
 
+use FindBin;
+use lib ("$FindBin::Bin/lib");
+
+use stemmaweb::Test::Common;
+
 use stemmaweb;
 use LWP::Protocol::PSGI;
 use Test::WWW::Mechanize;
@@ -9,17 +14,12 @@ use Test::More;
 use HTML::TreeBuilder;
 use Data::Dumper;
 
-use FindBin;
-use lib ("$FindBin::Bin/lib");
-
 use stemmaweb::Test::DB;
 
 stemmaweb::Test::DB->new_db;
 
 LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
 
-use stemmaweb::Test::Common;
-
 my $ua = Test::WWW::Mechanize->new;
 
 $ua->get_ok('http://localhost/register');
@@ -31,15 +31,38 @@ my $response = $ua->submit_form(
         confirm_password => 'UserPass',
     });
 
-warn $ua->content;
+$ua->content_contains('You are now registered.', 'Registration worked');
+
+$ua->get('/');
+$ua->content_contains('Hello! user2@example.org', 'We are logged in.');
+
+$ua->get('/logout');
+
+$ua->get_ok('http://localhost/login');
+$response = $ua->submit_form(
+    fields => {
+        username    => 'user2@example.org',
+        password    => 'UserPass'
+    });
+
+$ua->content_contains('Stemmaweb - Logged in', 'Log in with new account works');
+
+$ua->get('/');
+$ua->content_contains('Hello! user2@example.org', 'We are logged in with new account');
+
+$ua->get('/logout');
 
-=cut
+$ua->get_ok('http://localhost/register');
 
-$ua->content_contains('Stemmaweb - Logged in', 'Log in successful.');
+$response = $ua->submit_form(
+    fields => {
+        username         => 'user2@example.org',
+        password         => 'UserPass',
+        confirm_password => 'UserPass',
+    });
 
-my $content  = $ua->get('/');
-$ua->content_contains('Hello! user@example.org', 'We are logged in.');
+$ua->content_contains('That username already exists.', 'We cannot register an already
+    existing username');
 
-=cut
 
 done_testing;