use Test::More; use Test::Mojo; use Mojo::Base -strict; use Mojolicious::Lite; use lib 'lib'; plugin 'Qaptcha', { inbuild_jquery => 1, inbuild_jquery_ui => 1, inbuild_jquery_ui_touch => 1, txtLock => "gesperrt", txtUnlock => "entsperrt", disabledSubmit => "true", autoRevert => "false", autoSubmit => "true", qaptcha_url => '/entsperren', }; any '/' => sub { my $self = shift; $self->stash( form_processing => sprintf("form data %s processed", $self->qaptcha_is_unlocked ? '' : 'not') ); $self->render('index'); }; app->start(); my $t = Test::Mojo->new; $t->get_ok('/')->status_is(200) ->content_like(qr'gesperrt') ->content_like(qr'entsperrt') ->content_like(qr'disabledSubmit : true') ->content_like(qr'autoRevert : false') ->content_like(qr'autoSubmit : true'); $t->post_ok('/entsperren' => {DNT => 1} => form => {action => 'qaptcha', qaptcha_key => 'ABC'}) ->status_is(200) ->json_is({error => 0}); $t->post_ok('/' => {DNT => 1} => form => {firstname => 'hans', lastname => 'test'}) ->status_is(200) ->text_is('div#q_session' => 'ABC') ->text_is('div#f_processed' => 'form data processed'); $t->post_ok('/' => {DNT => 1} => form => {firstname => 'hans', lastname => 'test'}) ->status_is(200) ->text_is('div#q_session' => '') ->text_is('div#f_processed' => 'form data not processed'); done_testing(); __DATA__ @@ layouts/default.html.ep %= qaptcha_include %= content; @@ index.html.ep %= layout 'default';
%= c.session('qaptcha_key');
%= $form_processing;