Debian Codegraph @

t/repeatable/constraints/required.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.yml');
14
15 $form->get_element( { type => 'Repeatable' } )->repeat(2);
16
17 # Valid
18 {
19 $form->process(
20 { 'rep_1.foo' => 'a',
21 'rep_1.bar' => 'b',
22 'rep_2.foo' => 'c',
23 'rep_2.bar' => 'd',
24 count => 2,
25 } );
26
27 ok( $form->submitted_and_valid );
28
29 is_deeply(
30 $form->params,
31 { rep_1 => {
32 foo => 'a',
33 bar => 'b',
34 },
35 rep_2 => {
36 foo => 'c',
37 bar => 'd',
38 },
39 count => 2,
40 } );
41 }
42
43 # Missing - Invalid
44 {
45 $form->process(
46 { 'rep_1.bar' => 'b',
47 'rep_2.foo' => 'c',
48 count => 2,
49 } );
50
51 ok( !$form->submitted_and_valid );
52
53 ok( $form->has_errors('rep_1.foo') );
54 ok( !$form->has_errors('rep_1.bar') );
55 ok( !$form->has_errors('rep_2.foo') );
56 ok( $form->has_errors('rep_2.bar') );
57
58 like( $form->get_field( { nested_name => 'rep_1.foo' } ),
59 qr/This field is required/ );
60 unlike( $form->get_field( { nested_name => 'rep_1.bar' } ),
61 qr/This field is required/ );
62 unlike( $form->get_field( { nested_name => 'rep_2.foo' } ),
63 qr/This field is required/ );
64 like( $form->get_field( { nested_name => 'rep_2.bar' } ),
65 qr/This field is required/ );
66 }
67