File: when.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More;

{
    package MyApp::Test::Form;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    has_field 'fee';
    has_field 'fie' => ( apply => [
        { when => { fee => 1 }, check => qr/when/, message => 'Wrong fie' },
    ]);
    has_field 'fo';
    has_field 'fum_comp' => ( type => 'Compound' );
    has_field 'fum_comp.one' => ( apply => [
        { when => { '+fee' => sub { $_[0] == 1 } }, check => qr/when/, message => 'Wrong one' },
    ]);
    has_field 'fum_comp.two' => ( apply => [
        { when => { '+fee' => [1,2,3] }, check => qr/when/, message => 'Wrong two' },
    ]);
}

my $form = MyApp::Test::Form->new;
ok( $form );
my $params = {
    fee => '',
    fie => 'where',
    fo => 'my_fo',
    'fum_comp.one' => 2,
    'fum_comp.two' => 'where',
};
$form->process( $params );
ok( $form->validated );
$params->{fee} = 1;
$form->process( $params );
ok( !$form->validated, 'validation failed for fie when fee is 1' );
my @errors = $form->errors;
is( scalar @errors, 3, 'right number of errors' );

done_testing;