File: update_subfields.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
use warnings;
use Test::More;

# tests that 'by_flag' works for contains
# Test 'by_type' flag
{
    package Test::Form;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    sub build_update_subfields {{
        by_flag => { contains => { wrapper_class => ['rep_elem'] } },
        by_type => { 'Select' => { wrapper_class => ['sel_wrapper'] },
                     'BoolSelect' => { element_class => ['sel_elem'] },
        },
    }}
    has_field 'records' => ( type => 'Repeatable' );
    has_field 'records.one';
    has_field 'records.two';
    has_field 'foo' => ( type => 'Select', options => [
        { value => 1, label => 'One' }, { value => 2, label => 'Two' }] );
    has_field 'bar' => ( type => 'BoolSelect' );

}

my $form = Test::Form->new;
$form->process;
is_deeply( $form->field('records.0')->wrapper_class, ['rep_elem'], 'contains has correct class by flag' );
is_deeply( $form->field('foo')->wrapper_class, ['sel_wrapper'], 'correct class by type' );
is_deeply( $form->field('bar')->element_class, ['sel_elem'], 'correct class by type' );

# test using update_subfields with base class

{
    package Test::Form::Base;
    use Moose;
    extends 'HTML::FormHandler';

    sub build_update_subfields {
        return { all => { tags => { no_errors => 1 } } };
    }
}
{
    package Test::Form::Special;
    use HTML::FormHandler::Moose;
    extends 'Test::Form::Base';
    use HTML::FormHandler::Merge ('merge');

    sub build_update_subfields {
        my $self = shift;
        my $new = { all => { tags => { wrapper_tag => 'p' } } };
        return merge( $new, $self->next::method(@_) );
    }
    has_field 'foo';
    has_field 'bar';
}
$form = Test::Form::Special->new;
ok( $form );
my $expected = { no_errors => 1, wrapper_tag => 'p' };
is_deeply( $form->field('foo')->tags, $expected, 'got expected tags' );

done_testing;