PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/t/formhandlerx.t

http://github.com/gshank/html-formhandler
text | 52 lines | 40 code | 12 blank | 0 comment | 0 complexity | 2ef82ed9e54c4cbe17c6ea60d30ccdee MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4use Test::Exception;
 5
 6{
 7    package HTML::FormHandlerX::Widget::Field::TesT;
 8    use Moose::Role;
 9    sub render { '<p>field rendered...</p>' }
10
11}
12
13{
14    package HTML::FormHandlerX::Field::TesT;
15    use Moose;
16    extends 'HTML::FormHandler::Field::Text';
17
18    has '+widget' => ( default => 'TesT' );
19}
20
21{
22    package Test::HTML::FormHandler::TextFormHandlerX;
23
24    use HTML::FormHandler::Moose;
25    extends 'HTML::FormHandler';
26
27    has_field 'field_name' => (
28        type => 'TesT',
29        required => 1,
30    );
31}
32
33my $form = Test::HTML::FormHandler::TextFormHandlerX->new;
34ok( $form, 'created Form' );
35my %params = (
36    field_name => 'This is a field',
37);
38$form->process(params=>\%params);
39is( $form->field('field_name')->widget, 'TesT', 'got right widget name' );
40is( $form->field('field_name')->render, '<p>field rendered...</p>', 'field rendered' );
41
42{
43    package Test::Fail;
44    use HTML::FormHandler::Moose;
45    extends 'HTML::FormHandler';
46
47    has_field 'foo' => ( type => 'Fail' );
48}
49
50dies_ok( sub { Test::Fail->new }, 'form dies with invalid field' );
51
52done_testing;