Debian Codegraph @

t/repeatable/constraints/required_not_increment_field_names.t

raw symbols SCIP
1 use strict;
2 use warnings;
3
4 use Test::More tests => 13;
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(
14 't/repeatable/constraints/required_not_increment_field_names.yml');
15
16 $form->get_element( { type => 'Repeatable' } )->repeat(2);
17
18 # Valid
19 {
20 $form->process(
21 { foo => [ 'a', 'b' ],
22 bar => [ 'c', 'd' ],
23 count => 2,
24 } );
25
26 ok( $form->submitted_and_valid );
27
28 is_deeply(
29 $form->params,
30 { foo => [ 'a', 'b' ],
31 bar => [ 'c', 'd' ],
32 count => 2,
33 } );
34 }
35
36 # Missing - Invalid
37 {
38 $form->process(
39 { foo => [ '', 'b' ],
40 bar => [ 'c', '' ],
41 count => 2,
42 } );
43
44 ok( !$form->submitted_and_valid );
45
46 # $form->has_errors() doesn't really make sense for multiple fields with the same name
47 # - an error on any of those fields will return true
48
49 ok( $form->has_errors('foo') );
50 ok( $form->has_errors('bar') );
51
52 my $foo1 = $form->get_fields('foo')->[0];
53 my $foo2 = $form->get_fields('foo')->[1];
54 my $bar1 = $form->get_fields('bar')->[0];
55 my $bar2 = $form->get_fields('bar')->[1];
56
57 is( scalar @{ $foo1->get_errors }, 1 );
58 is( scalar @{ $foo2->get_errors }, 0 );
59 is( scalar @{ $bar1->get_errors }, 0 );
60 is( scalar @{ $bar2->get_errors }, 1 );
61
62 like( $foo1, qr/This field is required/ );
63 unlike( $foo2, qr/This field is required/ );
64
65 unlike( $bar1, qr/This field is required/ );
66 like( $bar2, qr/This field is required/ );
67 }