Debian Codegraph @

t/field_setup/init_object.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4
5 # this tests that a multiple select with value from an init_object
6 # has the right value with both a hashref and a blessed object
7 {
8 package MyApp::Form::Test;
9 use HTML::FormHandler::Moose;
10 extends 'HTML::FormHandler';
11
12 has_field 'foo' => ( type => 'Select', multiple => 1 );
13 sub options_foo {
14 [
15 1 => 'One',
16 2 => 'Two',
17 3 => 'Three',
18 4 => 'Four',
19 ]
20 }
21 has_field 'bar';
22 }
23
24 {
25 package FooObject;
26 use Moose;
27 has 'foo' => (
28 is => 'ro',
29 isa => 'ArrayRef',
30 traits => ['Array'],
31 handles => {
32 'has_foo' => 'count',
33 }
34 );
35 has 'bar' => ( is => 'ro', isa => 'Str' );
36 }
37
38 my $form = MyApp::Form::Test->new;
39 ok( $form );
40
41 # try with hashref
42 my $init_obj = {
43 foo => [1],
44 bar => 'my_test',
45 };
46 $form->process( init_object => $init_obj );
47 is_deeply( $form->field('foo')->value, [1], 'right value for foo field with hashref init_obj' );
48
49 # try with object
50 my $foo = FooObject->new(
51 foo => [1],
52 bar => 'my_test',
53 );
54 $form->process( init_object => $foo );
55 is_deeply( $form->field('foo')->value, [1], 'right value for foo field with object init_obj' );
56
57 done_testing;