Debian Codegraph @

xt/repeatable_clone.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4
5 # tests that we have a valid form reference after
6 # merging attributes for a repeatable instance and a
7 # form package with a 'clone' method
8 {
9 package MyApp::Form::Rep;
10 use HTML::FormHandler::Moose;
11 extends 'HTML::FormHandler';
12
13 use Clone ('clone');
14
15 has '+name' => ( default => 'testform' );
16 has_field 'foo';
17 has_field 'my_array' => ( type => 'Repeatable' );
18 has_field 'my_array.one';
19 has_field 'my_array.two' => ( type => 'Select' );
20 has_field 'my_array.three';
21
22 sub build_update_subfields {
23 { all => { wrap_label_method => \&wrap_label } }
24 }
25
26 sub wrap_label {
27 my $self = shift; # field
28 my $label = $self->label;
29 return qq{<a href="/some/link">$label</a>};
30 }
31
32 sub default_my_array {
33 my $self = shift;
34 return (
35 { one => 'abc1', two => 2, three => 'abc3' },
36 { one => 'def1', two => 3, three => 'def3' },
37 { one => 'ghi1', two => 1, three => 'ghi3' }
38 );
39 }
40 sub options_my_array_two {
41 return (
42 1 => 'one',
43 2 => 'two',
44 3 => 'three',
45 );
46 }
47 # this won't take effect; the 'my_array' default has precedence
48 # would be used for 'num_extra'
49 sub default_my_array_three { 'default_three' }
50 }
51
52 my $form = MyApp::Form::Rep->new;
53 ok( $form );
54 $form->process;
55 is( $form->field('my_array.0')->has_form, 1, 'has_form is true' );
56 ok( $form->field('my_array.0')->form, 'actually has form object' );
57 ok( $form == $form->field('my_array.0')->form, 'correct form object' );
58
59 done_testing;