| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
# tests that 'by_flag' works for contains |
| 6 |
# Test 'by_type' flag |
| 7 |
{ |
| 8 |
package Test::Form; |
| 9 |
use HTML::FormHandler::Moose; |
| 10 |
extends 'HTML::FormHandler'; |
| 11 |
|
| 12 |
sub build_update_subfields {{ |
| 13 |
by_flag => { contains => { wrapper_class => ['rep_elem'] } }, |
| 14 |
by_type => { 'Select' => { wrapper_class => ['sel_wrapper'] }, |
| 15 |
'BoolSelect' => { element_class => ['sel_elem'] }, |
| 16 |
}, |
| 17 |
}} |
| 18 |
has_field 'records' => ( type => 'Repeatable' ); |
| 19 |
has_field 'records.one'; |
| 20 |
has_field 'records.two'; |
| 21 |
has_field 'foo' => ( type => 'Select', options => [ |
| 22 |
{ value => 1, label => 'One' }, { value => 2, label => 'Two' }] ); |
| 23 |
has_field 'bar' => ( type => 'BoolSelect' ); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
my $form = Test::Form->new; |
| 28 |
$form->process; |
| 29 |
is_deeply( $form->field('records.0')->wrapper_class, ['rep_elem'], 'contains has correct class by flag' ); |
| 30 |
is_deeply( $form->field('foo')->wrapper_class, ['sel_wrapper'], 'correct class by type' ); |
| 31 |
is_deeply( $form->field('bar')->element_class, ['sel_elem'], 'correct class by type' ); |
| 32 |
|
| 33 |
# test using update_subfields with base class |
| 34 |
|
| 35 |
{ |
| 36 |
package Test::Form::Base; |
| 37 |
use Moose; |
| 38 |
extends 'HTML::FormHandler'; |
| 39 |
|
| 40 |
sub build_update_subfields { |
| 41 |
return { all => { tags => { no_errors => 1 } } }; |
| 42 |
} |
| 43 |
} |
| 44 |
{ |
| 45 |
package Test::Form::Special; |
| 46 |
use HTML::FormHandler::Moose; |
| 47 |
extends 'Test::Form::Base'; |
| 48 |
use HTML::FormHandler::Merge ('merge'); |
| 49 |
|
| 50 |
sub build_update_subfields { |
| 51 |
my $self = shift; |
| 52 |
my $new = { all => { tags => { wrapper_tag => 'p' } } }; |
| 53 |
return merge( $new, $self->next::method(@_) ); |
| 54 |
} |
| 55 |
has_field 'foo'; |
| 56 |
has_field 'bar'; |
| 57 |
} |
| 58 |
$form = Test::Form::Special->new; |
| 59 |
ok( $form ); |
| 60 |
my $expected = { no_errors => 1, wrapper_tag => 'p' }; |
| 61 |
is_deeply( $form->field('foo')->tags, $expected, 'got expected tags' ); |
| 62 |
|
| 63 |
done_testing; |