Debian Codegraph @

t/repeatable/constraints/required_not_nested.t

raw symbols SCIP
1 use strict;
2 use warnings;
3
4 use Test::More tests => 11;
5
6 use HTML::FormFu;
7 use lib 't/lib';
8 use HTMLFormFu::TestLib;
9
10 my $form = HTML::FormFu->new(
11 { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } );
12
13 $form->load_config_file('t/repeatable/constraints/required_not_nested.yml');
14
15 $form->get_element( { type => 'Repeatable' } )->repeat(2);
16
17 # Valid
18 {
19 $form->process(
20 { foo_1 => 'a',
21 bar_1 => 'b',
22 foo_2 => 'c',
23 bar_2 => 'd',
24 count => 2,
25 } );
26
27 ok( $form->submitted_and_valid );
28
29 is_deeply(
30 $form->params,
31 { foo_1 => 'a',
32 bar_1 => 'b',
33 foo_2 => 'c',
34 bar_2 => 'd',
35 count => 2,
36 } );
37 }
38
39 # Missing - Invalid
40 {
41 $form->process(
42 { bar_1 => 'b',
43 foo_2 => 'c',
44 count => 2,
45 } );
46
47 ok( !$form->submitted_and_valid );
48
49 ok( $form->has_errors('foo_1') );
50 ok( !$form->has_errors('bar_1') );
51 ok( !$form->has_errors('foo_2') );
52 ok( $form->has_errors('bar_2') );
53
54 like( $form->get_field('foo_1'), qr/This field is required/ );
55 unlike( $form->get_field('bar_1'), qr/This field is required/ );
56 unlike( $form->get_field('foo_2'), qr/This field is required/ );
57 like( $form->get_field('bar_2'), qr/This field is required/ );
58 }
59