PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/xt/init.t

http://github.com/gshank/html-formhandler
Unknown | 51 lines | 42 code | 9 blank | 0 comment | 0 complexity | 7ed02f3df146dc34e1802f0ef359368f MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4
 5{
 6    package My::Default;
 7    use Moose::Role;
 8
 9    sub build_default_over_obj {
10        return 'From Method';
11    }
12}
13
14{
15   package My::Other::Form;
16   use HTML::FormHandler::Moose;
17   extends 'HTML::FormHandler';
18
19   has '+name' => ( default => 'testform_' );
20   has_field 'optname' => ( temp => 'First' );
21   has_field 'reqname' => ( required => 1, default_over_obj => 'From Attribute' );
22   has_field 'altname' => ( traits => ['My::Default'] );
23   has_field 'somename';
24   has_field 'extraname' => ( default_over_obj => '' );
25
26   sub default_somename {
27      my $self = shift;
28      return 'SN from meth';
29   }
30}
31
32my $init_object = { reqname => 'Starting Perl', optname => 'Over Again', altname => 'test',
33    extraname => 'not_empty',
34};
35my $form = My::Other::Form->new;
36ok( $form, 'get form' );
37my $params = { reqname => 'Sweet', optname => 'Charity', somename => 'Exists' };
38
39$form->process( init_object => $init_object, params => $params );
40ok( $form->validated, 'form with init_obj & params validated' );
41is( $form->field('reqname')->init_value, 'From Attribute', 'correct init_value');
42is(  $form->field('optname')->init_value, 'Over Again', 'correct init_value no meth');
43is( $form->field('altname')->init_value, 'From Method', 'correct init_value from trait');
44is( $form->field('somename')->init_value, 'SN from meth', 'correct for init_obj undef');
45is( $form->field('somename')->value, 'Exists', 'correct value for init_obj undef');
46is( $form->field('extraname')->init_value, '', 'correct value for empty string default');
47
48$form = My::Other::Form->new( init_object => $init_object );
49is( $form->field('somename')->init_value, 'SN from meth', 'correct init_value new w init_obj');
50
51done_testing;