Allow having no captcha, add registration test
Errietta Kostala [Thu, 22 Jan 2015 15:45:47 +0000 (15:45 +0000)]
lib/stemmaweb/Controller/Users.pm
stemmaweb.conf
stemmaweb_tests.conf [new file with mode: 0644]
t/05register.t [new file with mode: 0644]
t/lib/stemmaweb/Test/Common.pm [new file with mode: 0644]

index 1e87b37..96516a7 100644 (file)
@@ -83,12 +83,16 @@ form with an error message.
 before register => sub {
     my ($self, $c) = @_;
 
+    warn $c->config->{'Registration'}->{'no_recaptcha'};
+
     ## Puts HTML into stash in "recaptcha" key.
-    $c->forward('captcha_get');
+    if (!$c->config->{'Registration'}->{'no_recaptcha'}) {
+        $c->forward('captcha_get');
+    }
 
     ## When submitting, check recaptcha passes, else re-draw form
     if($c->req->method eq 'POST') {
-        if(!$c->forward('captcha_check') || 0 ) {
+        if ( !$c->config->{'Registration'}->{'no_recaptcha'} && !$c->forward('captcha_check') ) {
             ## Need these two lines to detach, so end can draw the correct template again:
             my $form = $self->form_handler->new( active => [ $self->login_id_field, 'password', 'confirm_password' ] );
             $c->stash( template => $self->register_template, form => $form );
index 3bfed71..e01f291 100644 (file)
@@ -14,3 +14,6 @@ name = stemmaweb
     public_cert_url https://www.googleapis.com/oauth2/v1/certs
     client_id 577442226093-pi2ud795g49ibip78bgfoabhl4kdrguc.apps.googleusercontent.com
 </Authentication::Credential::Google>
+<Registration>
+    no_recaptcha 0
+</Registration>
diff --git a/stemmaweb_tests.conf b/stemmaweb_tests.conf
new file mode 100644 (file)
index 0000000..a4e4302
--- /dev/null
@@ -0,0 +1,3 @@
+<Registration>
+    no_recaptcha 1
+</Registration>
diff --git a/t/05register.t b/t/05register.t
new file mode 100644 (file)
index 0000000..57e5b59
--- /dev/null
@@ -0,0 +1,45 @@
+use warnings;
+use strict;
+
+use stemmaweb;
+use LWP::Protocol::PSGI;
+use Test::WWW::Mechanize;
+
+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');
+
+my $response = $ua->submit_form(
+    fields => {
+        username         => 'user2@example.org',
+        password         => 'UserPass',
+        confirm_password => 'UserPass',
+    });
+
+warn $ua->content;
+
+=cut
+
+$ua->content_contains('Stemmaweb - Logged in', 'Log in successful.');
+
+my $content  = $ua->get('/');
+$ua->content_contains('Hello! user@example.org', 'We are logged in.');
+
+=cut
+
+done_testing;
diff --git a/t/lib/stemmaweb/Test/Common.pm b/t/lib/stemmaweb/Test/Common.pm
new file mode 100644 (file)
index 0000000..85a6a79
--- /dev/null
@@ -0,0 +1,11 @@
+package stemmaweb::Test::Common;
+
+use strict;
+use warnings;
+
+BEGIN {
+    $ENV{STEMMAWEB_CONFIG_LOCAL_SUFFIX} = 'tests';
+    $ENV{STEMMAWEB_CONFIG_PATH} = '.';
+}
+
+1;