| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
{ |
| 6 |
package MyApp::Test::Form; |
| 7 |
use HTML::FormHandler::Moose; |
| 8 |
extends 'HTML::FormHandler'; |
| 9 |
|
| 10 |
has_field 'fee'; |
| 11 |
has_field 'fie' => ( apply => [ |
| 12 |
{ when => { fee => 1 }, check => qr/when/, message => 'Wrong fie' }, |
| 13 |
]); |
| 14 |
has_field 'fo'; |
| 15 |
has_field 'fum_comp' => ( type => 'Compound' ); |
| 16 |
has_field 'fum_comp.one' => ( apply => [ |
| 17 |
{ when => { '+fee' => sub { $_[0] == 1 } }, check => qr/when/, message => 'Wrong one' }, |
| 18 |
]); |
| 19 |
has_field 'fum_comp.two' => ( apply => [ |
| 20 |
{ when => { '+fee' => [1,2,3] }, check => qr/when/, message => 'Wrong two' }, |
| 21 |
]); |
| 22 |
} |
| 23 |
|
| 24 |
my $form = MyApp::Test::Form->new; |
| 25 |
ok( $form ); |
| 26 |
my $params = { |
| 27 |
fee => '', |
| 28 |
fie => 'where', |
| 29 |
fo => 'my_fo', |
| 30 |
'fum_comp.one' => 2, |
| 31 |
'fum_comp.two' => 'where', |
| 32 |
}; |
| 33 |
$form->process( $params ); |
| 34 |
ok( $form->validated ); |
| 35 |
$params->{fee} = 1; |
| 36 |
$form->process( $params ); |
| 37 |
ok( !$form->validated, 'validation failed for fie when fee is 1' ); |
| 38 |
my @errors = $form->errors; |
| 39 |
is( scalar @errors, 3, 'right number of errors' ); |
| 40 |
|
| 41 |
done_testing; |