Show quoted text
> perl t/recaptcha_field.t
1..5
ok 1 - get form
ok 2 - OK recaptcha
ok 3 - recaptcha render OK
ok 4 - recaptcha public_key OK
Can't locate object method "public_key" via package "Test::reCAPTCHA" at /usr/local/lib/perl5/site_perl/5.14/HTML/FormHandlerX/Widget/Field/reCAPTCHA.pm line 14.
# Looks like you planned 5 tests but ran 4.
# Looks like your test exited with 255 just after 4.
The test is in file attachment.
Subject: | recaptcha_field.t |
#/usr/bin/env perl
use strict;
use warnings;
use Test::More tests=>5;
use utf8;
package Test::reCAPTCHA;
use HTML::FormHandler::I18N;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler'; # se non derivasse da DBIC
with 'HTML::FormHandlerX::Widget::Field::reCAPTCHA';
has '+is_html5' => (default=>1);
has_field 'recaptcha' => (
type=>'reCAPTCHA',
recaptcha_message => "Non hai dimostrato di essere un umano!",
required=>1,
);
has ['recaptcha_public_key','recaptcha_private_key'] => (is => 'rw', isa=>'Str', required=>1);
no HTML::FormHandler::Moose;
package ::main;
#use_ok('Test::reCAPTCHA');
my $public_key = 'zio pino';
my $private_key = 'zio can';
my $form = Test::reCAPTCHA->new(recaptcha_public_key=>$public_key,recaptcha_private_key=>$private_key);
ok($form, 'get form');
$form->process(params => {});
ok($form->field('recaptcha')->render, 'OK recaptcha');
my $expected = q(
<div>
<label for="recaptcha">Recaptcha</label>
<script type="text/javascript">
//<![CDATA[
var RecaptchaOptions = {};
//]]>
</script>
<script src="http://www.google.com/recaptcha/api/challenge?k=zio+pino" type="text/javascript"></script>
<noscript><iframe frameborder="0" height="300" src="http://www.google.com/recaptcha/api/noscript?k=zio+pino" width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" rows="3"></textarea><input name="recaptcha_response_field" type="hidden" value="manual_challenge" /></noscript>
</div>);
ok($form->field('recaptcha')->render eq $expected, 'recaptcha render OK') || diag($form->field('recaptcha')->render);
like($form->field('recaptcha')->render,qr/k=zio\+pino/, 'recaptcha public_key OK') || diag($form->field('recaptcha')->render);
ok($form->render, "Fixed!");
exit;
1;