-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathposted.t
59 lines (45 loc) · 1.56 KB
/
posted.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
use warnings;
use Test::More;
use HTML::FormHandler::I18N;
$ENV{LANGUAGE_HANDLE} = 'en_en';
{
package Test::SingleBool;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
has_field 'opt_in' => ( type => 'Boolean', required => 1 );
}
{
my $form = Test::SingleBool->new;
ok( $form, 'form built' );
$form->process( params => {} );
ok( !$form->ran_validation, 'form did not run validation' );
my $test = 'POST';
$form->process( posted => ($test eq 'POST'), params => {} );
ok( $form->ran_validation, 'form did run validation' );
ok( $form->has_errors, 'form has errors' );
my @errors = $form->errors;
is( scalar @errors, 1, 'form has an error' );
is( $errors[0], 'Opt in field is required', 'error message is correct' );
}
{
package Test::SingleBoolCompound;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
has_field 'a' => ( type => 'Compound', required => 1 );
has_field 'a.opt_in' => ( type => 'Boolean', required => 1 );
}
{
my $form = Test::SingleBoolCompound->new;
ok( $form, 'form built' );
$form->process( params => {} );
ok( !$form->ran_validation, 'form did not run validation' );
my $test = 'POST';
$form->process( posted => ($test eq 'POST'), params => {} );
ok( $form->ran_validation, 'form did run validation' );
ok( $form->has_errors, 'form has errors' );
my @errors = $form->errors;
is( scalar @errors, 1, 'form has an error' );
is( $errors[0], 'A field is required', 'error message is correct' );
}
done_testing;